agave-systems/systems-api/src/main/java/org/iplantc/service/systems/resources/SystemCredentialResource.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.SystemRemoveCredential.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 = systemDao.findActiveAndInactiveSystemBySystemId(systemId);
			if (system == null)
			{
				throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
						"No system found matching " + systemId);
			}
			else if (!system.isAvailable()) 
			{
				throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
						"System has been disabled by the administrator. "
						+ "No credential changes may be applied to a disabled system.",
						new SystemUnavailableException());
			}
			else if (!system.getUserRole(username).canAdmin()) {
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
						"Individual user credentials may only be managed by system administrators.",
						new PermissionException());
			} 
			SystemManager systemManager = new SystemManager();
			if (systemManager.isManageableByUser(system, username))
			{
				if (!StringUtils.isEmpty(internalUsername)) 
				{
					if (new InternalUserDao().getInternalUserByAPIUserAndUsername(username, internalUsername) == null) {
						throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
								"No internal user found matching username '" + internalUsername + "'",
								new FileNotFoundException());
					}
					if (StringUtils.isEmpty(systemId)) {
						if (StringUtils.isEmpty(type)) {
							manager.removeAllInternalUserAuthConfig(username, internalUsername);
						} else {
							manager.removeAllInternalUserAuthConfigOfType(username, internalUsername, type);
						}
					} 
					else 
					{
						if (StringUtils.isEmpty(type)) {
							manager.removeAllInternalUserAuthConfigOnSystem(system, username, internalUsername);
						} else {
							manager.removeInternalUserAuthConfigOnSystemOfType(system, type, username, internalUsername);
						}
					}
				} 
				else 
				{
					if (StringUtils.isEmpty(systemId)) {
						if (StringUtils.isEmpty(type)) {
							manager.clearAllInternalUserAuthConfig(username);
						} else {
							manager.clearAllInternalUserAuthConfigOfType(username, type);
						}
					} 
					else 
					{
						if (StringUtils.isEmpty(type)) {
							manager.clearAllInternalUserAuthConfigOnSystem(system, username);
						} else {
							manager.clearAllInternalUserAuthConfigOnSystemOfType(system, username, type);
						}
					}
				}	
				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)
		{
			getResponse().setEntity(
					new IplantErrorRepresentation("Failed to remove system credentials: " + 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 . SystemRemoveCredential . 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 = systemDao . findActiveAndInactiveSystemBySystemId ( systemId ) ; if ( system == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No system found matching " + systemId ) ; } else if ( ! system . isAvailable ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "System has been disabled by the administrator. " + "No credential changes may be applied to a disabled system." , new SystemUnavailableException ( ) ) ; } else if ( ! system . getUserRole ( username ) . canAdmin ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "Individual user credentials may only be managed by system administrators." , new PermissionException ( ) ) ; } SystemManager systemManager = new SystemManager ( ) ; if ( systemManager . isManageableByUser ( system , username ) ) { if ( ! StringUtils . isEmpty ( internalUsername ) ) { if ( new InternalUserDao ( ) . getInternalUserByAPIUserAndUsername ( username , internalUsername ) == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No internal user found matching username '" + internalUsername + "'" , new FileNotFoundException ( ) ) ; } if ( StringUtils . isEmpty ( systemId ) ) { if ( StringUtils . isEmpty ( type ) ) { manager . removeAllInternalUserAuthConfig ( username , internalUsername ) ; } else { manager . removeAllInternalUserAuthConfigOfType ( username , internalUsername , type ) ; } } else { if ( StringUtils . isEmpty ( type ) ) { manager . removeAllInternalUserAuthConfigOnSystem ( system , username , internalUsername ) ; } else { manager . removeInternalUserAuthConfigOnSystemOfType ( system , type , username , internalUsername ) ; } } } else { if ( StringUtils . isEmpty ( systemId ) ) { if ( StringUtils . isEmpty ( type ) ) { manager . clearAllInternalUserAuthConfig ( username ) ; } else { manager . clearAllInternalUserAuthConfigOfType ( username , type ) ; } } else { if ( StringUtils . isEmpty ( type ) ) { manager . clearAllInternalUserAuthConfigOnSystem ( system , username ) ; } else { manager . clearAllInternalUserAuthConfigOnSystemOfType ( system , username , type ) ; } } } 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 ) { getResponse ( ) . setEntity ( new IplantErrorRepresentation ( "Failed to remove system credentials: " + e . getMessage ( ) ) ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; } }
Deletes roles for a system.
Deletes roles for a system .
// delete all roles for this system 