private void updateUserAuthenticationSources(Set<UserAuthenticationSourceRequest> requests) throws AuthorizationException, AmbariException {

    Integer authenticatedUserId = AuthorizationHelper.getAuthenticatedId();


    for (UserAuthenticationSourceRequest request : requests) {
      String requestedUsername = request.getUsername();

      UserEntity userEntity = users.getUserEntity(requestedUsername);
      if (null == userEntity) {
        continue;
      }

      boolean isSelf = authenticatedUserId.equals(userEntity.getUserId());
      /* **************************************************
       * Ensure that the authenticated user can change the password for the subject user. At least one
       * of the following must be true
       *  * The authenticate user is requesting to change his/her own password for a local authentication source
       *  * The authenticated user has permissions to manage users
       *  ************************************************** */
      if (!isSelf && !AuthorizationHelper.isAuthorized(ResourceType.AMBARI, null, RoleAuthorization.AMBARI_MANAGE_USERS)) {
        throw new AuthorizationException("You are not authorized perform this operation");
      }

      UserAuthenticationEntity userAuthenticationEntity = null;
      Long sourceId = request.getSourceId();

      if (sourceId != null) {
        List<UserAuthenticationEntity> authenticationEntities = userEntity.getAuthenticationEntities();
        // Find the relevant authentication entity...
        for (UserAuthenticationEntity authenticationEntity : authenticationEntities) {
          if (sourceId.equals(authenticationEntity.getUserAuthenticationId())) {
            userAuthenticationEntity = authenticationEntity;
            break;
          }
        }
      }

      if (userAuthenticationEntity == null) {
        // The requested authentication record was not found....
        throw new ResourceNotFoundException("The requested authentication source was not found.");
      }

      // If the authentication_type is set, use it to verify that the found authentication source matches it...
      if ((request.getAuthenticationType() != null) && (request.getAuthenticationType() != userAuthenticationEntity.getAuthenticationType())) {
        throw new ResourceNotFoundException("The requested authentication source was not found - mismatch on authentication type");
      }

      users.modifyAuthentication(userAuthenticationEntity, request.getOldKey(), request.getKey(), isSelf);
    }
  }
Delete the users authentication sources identified by the given request objects.
<p>
It ia assumed that the user has previously been authorized to perform this operation.

@param requests the request objects
@throws AmbariException if the user authentication sources could not be read
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UserAuthenticationSourceResourceProvider.java