agave-systems/systems-api/src/main/java/org/iplantc/service/systems/resources/SystemRoleResource.java
/* 
	 * Deletes roles for a system. If no user is specified, it deletes all roles.
	 * Otherwise only the user roles are deleted.
	 */
Deletes roles for a system. If no user is specified, it deletes all roles.
Otherwise only the user roles are deleted.
Deletes roles for a system . If no user is specified it deletes all roles . Otherwise only the user roles are deleted .
@Override
	public void removeRepresentations() throws ResourceException
	{
		this.username = getAuthenticatedUsername();
		AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.SYSTEMS02.name(), 
				AgaveLogServiceClient.ActivityKeys.SystemRemoveRoles.name(), 
				username, "", getRequest().getClientInfo().getUpstreamAddress());
		if (!ServiceUtils.isValid(systemId))
		{
			getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
			getResponse().setEntity(new IplantErrorRepresentation("Invalid system id. " +
							"Please specify an system using its system id. "));
		}
		try
		{
			RemoteSystem system = dao.findBySystemId(systemId);
			if (system == null)
			{
				throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
						"No shared system found matching " + systemId);
			} 
			else if (!system.isAvailable()) 
			{
				throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
						"System has been already been disabled.");
			}
			else if (system.isPubliclyAvailable()) 
			{
				throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED,
						"Share roles are not suported on public systems.");
			}
			SystemManager systemManager = new SystemManager();
			if (systemManager.isManageableByUser(system, username))
			{
				if (!StringUtils.isEmpty(sharedUsername)) 
				{
					AgaveProfileServiceClient authClient = new AgaveProfileServiceClient(
							Settings.IPLANT_PROFILE_SERVICE, Settings.IRODS_USERNAME, Settings.IRODS_PASSWORD);
					if (authClient.getUser(sharedUsername) == null) 
					{
						throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
							"No roles found for user " + sharedUsername);
					} else {
						SystemRoleManager systemRoleManager = new SystemRoleManager(system);
						systemRoleManager.setRole(sharedUsername, RoleType.NONE, username);
					}
				} 
				else 
				{
					SystemRoleManager systemRoleManager = new SystemRoleManager(system);
					systemRoleManager.clearRoles(username);
				}	
				getResponse().setEntity(new IplantSuccessRepresentation());
			} 
			else 
			{
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
						"User does not have the necessary role to update this system", 
						new PermissionException());
			}
		}
		catch (ResourceException e) {
			getResponse().setEntity(
					new IplantErrorRepresentation(e.getMessage()));
			getResponse().setStatus(e.getStatus());
		}
		catch (Exception e)
		{
			if (StringUtils.isEmpty(sharedUsername)) {
				log.error("Failed to clear system roles", e);
			}
			else {
				log.error("Failed to remove system roles for " + sharedUsername, e);
			}
			getResponse().setEntity(
					new IplantErrorRepresentation("Failed to remove system roles: " + e.getMessage()));
			getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
		}
	}
@ Override public void removeRepresentations ( ) throws ResourceException { this . username = getAuthenticatedUsername ( ) ; AgaveLogServiceClient . log ( AgaveLogServiceClient . ServiceKeys . SYSTEMS02 . name ( ) , AgaveLogServiceClient . ActivityKeys . SystemRemoveRoles . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; if ( ! ServiceUtils . isValid ( systemId ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; getResponse ( ) . setEntity ( new IplantErrorRepresentation ( "Invalid system id. " + "Please specify an system using its system id. " ) ) ; } try { RemoteSystem system = dao . findBySystemId ( systemId ) ; if ( system == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No shared system found matching " + systemId ) ; } else if ( ! system . isAvailable ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "System has been already been disabled." ) ; } else if ( system . isPubliclyAvailable ( ) ) { throw new ResourceException ( Status . SERVER_ERROR_NOT_IMPLEMENTED , "Share roles are not suported on public systems." ) ; } SystemManager systemManager = new SystemManager ( ) ; if ( systemManager . isManageableByUser ( system , username ) ) { if ( ! StringUtils . isEmpty ( sharedUsername ) ) { AgaveProfileServiceClient authClient = new AgaveProfileServiceClient ( Settings . IPLANT_PROFILE_SERVICE , Settings . IRODS_USERNAME , Settings . IRODS_PASSWORD ) ; if ( authClient . getUser ( sharedUsername ) == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No roles found for user " + sharedUsername ) ; } else { SystemRoleManager systemRoleManager = new SystemRoleManager ( system ) ; systemRoleManager . setRole ( sharedUsername , RoleType . NONE , username ) ; } } else { SystemRoleManager systemRoleManager = new SystemRoleManager ( system ) ; systemRoleManager . clearRoles ( username ) ; } getResponse ( ) . setEntity ( new IplantSuccessRepresentation ( ) ) ; } else { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have the necessary role to update this system" , new PermissionException ( ) ) ; } } catch ( ResourceException e ) { getResponse ( ) . setEntity ( new IplantErrorRepresentation ( e . getMessage ( ) ) ) ; getResponse ( ) . setStatus ( e . getStatus ( ) ) ; } catch ( Exception e ) { if ( StringUtils . isEmpty ( sharedUsername ) ) { log . error ( "Failed to clear system roles" , e ) ; } else { log . error ( "Failed to remove system roles for " + sharedUsername , e ) ; } getResponse ( ) . setEntity ( new IplantErrorRepresentation ( "Failed to remove system roles: " + e . getMessage ( ) ) ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; } }
Deletes roles for a system.
Deletes roles for a system .
// validate the user they are giving roles to exists // delete all roles for this system 