private void addAuthentication(UserEntity userEntity, UserAuthenticationType type, String key,
                                 Validator validator, boolean persist)
      throws AmbariException {

    if (userEntity == null) {
      throw new AmbariException("Missing user");
    }

    validator.validate(userEntity, key);

    List<UserAuthenticationEntity> authenticationEntities = userAuthenticationDAO.findByUser(userEntity);

    UserAuthenticationEntity authenticationEntity = new UserAuthenticationEntity();
    authenticationEntity.setUser(userEntity);
    authenticationEntity.setAuthenticationType(type);
    authenticationEntity.setAuthenticationKey(key);
    authenticationEntities.add(authenticationEntity);

    userEntity.setAuthenticationEntities(authenticationEntities);

    if (persist) {
      userDAO.merge(userEntity);
    }
  }
Worker to add a user authentication methods for a user.

@param userEntity the user
@param type       the authentication type
@param key        the authentication type specific metadata
@param validator  the authentication type specific validator
@param persist    true, to persist the created entity; false, to not persist the created entity
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java