private Account prepareAccountForUpdate ( final Account account , final MultivaluedMap < String , String > data , UserIdentityContext userIdentityContext ) { Account . Builder accBuilder = Account . builder ( ) ; //copy full incoming account, and let override happen //in a separate instance later accBuilder . copy ( account ) ; if ( data . containsKey ( "Status" ) ) { Account . Status newStatus = Account . Status . getValueOf ( data . getFirst ( "Status" ) . toLowerCase ( ) ) ; accBuilder . setStatus ( newStatus ) ; } if ( data . containsKey ( "FriendlyName" ) ) { accBuilder . setFriendlyName ( data . getFirst ( "FriendlyName" ) ) ; } if ( data . containsKey ( "Password" ) ) { // if this is a reset-password operation, we also need to set the account status to active if ( account . getStatus ( ) == Account . Status . UNINITIALIZED ) { accBuilder . setStatus ( Account . Status . ACTIVE ) ; } String password = data . getFirst ( "Password" ) ; PasswordValidator validator = PasswordValidatorFactory . createDefault ( ) ; if ( ! validator . isStrongEnough ( password ) ) { CustomReasonPhraseType stat = new CustomReasonPhraseType ( Response . Status . BAD_REQUEST , "Password too weak" ) ; throw new WebApplicationException ( status ( stat ) . build ( ) ) ; } final String hash = new Md5Hash ( data . getFirst ( "Password" ) ) . toString ( ) ; accBuilder . setAuthToken ( hash ) ; } if ( data . containsKey ( "Role" ) ) { // Only allow role change for administrators. Multitenancy checks will take care of restricting the modification scope to sub-accounts. if ( userIdentityContext . getEffectiveAccountRoles ( ) . contains ( permissionEvaluator . getAdministratorRole ( ) ) ) { accBuilder . setRole ( data . getFirst ( "Role" ) ) ; } else { CustomReasonPhraseType stat = new CustomReasonPhraseType ( Response . Status . FORBIDDEN , "Only Administrator allowed" ) ; throw new WebApplicationException ( status ( stat ) . build ( ) ) ; } } return accBuilder . build ( ) ; }
Fills an account entity object with values supplied from an http request