public ModeledAuthenticatedUser retrieveAuthenticatedUser(AuthenticationProvider authenticationProvider,Credentials credentials) throws GuacamoleException {
  String username=credentials.getUsername();
  String password=credentials.getPassword();
  UserModel userModel=userMapper.selectOne(username);
  if (userModel == null)   return null;
  if (userModel.isDisabled())   return null;
  byte[] hash=encryptionService.createPasswordHash(password,userModel.getPasswordSalt());
  if (!Arrays.equals(hash,userModel.getPasswordHash()))   return null;
  ModeledUser user=getObjectInstance(null,userModel);
  user.setCurrentUser(new ModeledAuthenticatedUser(authenticationProvider,user,credentials));
  if (!user.isAccountValid())   throw new GuacamoleClientException("LOGIN.ERROR_NOT_VALID");
  if (!user.isAccountAccessible())   throw new GuacamoleClientException("LOGIN.ERROR_NOT_ACCESSIBLE");
  if (userModel.isExpired()) {
    HttpServletRequest request=credentials.getRequest();
    String newPassword=request.getParameter(NEW_PASSWORD_PARAMETER);
    String confirmNewPassword=request.getParameter(CONFIRM_NEW_PASSWORD_PARAMETER);
    if (newPassword == null || confirmNewPassword == null) {
      logger.info("The password of user \"{}\" has expired and must be reset.",username);
      throw new GuacamoleInsufficientCredentialsException("LOGIN.INFO_PASSWORD_EXPIRED",EXPIRED_PASSWORD);
    }
    if (newPassword.equals(credentials.getPassword()))     throw new GuacamoleClientException("LOGIN.ERROR_PASSWORD_SAME");
    if (newPassword.isEmpty())     throw new GuacamoleClientException("LOGIN.ERROR_PASSWORD_BLANK");
    if (!newPassword.equals(confirmNewPassword))     throw new GuacamoleClientException("LOGIN.ERROR_PASSWORD_MISMATCH");
    userModel.setExpired(false);
    user.setPassword(newPassword);
    userMapper.update(userModel);
    logger.info("Expired password of user \"{}\" has been reset.",username);
  }
  return user.getCurrentUser();
}

public ModeledAuthenticatedUser retrieveAuthenticatedUser ( AuthenticationProvider authenticationProvider , Credentials credentials ) throws GuacamoleException { String username = credentials . getUsername ( ) ; String password = credentials . getPassword ( ) ; UserModel userModel = userMapper . selectOne ( username ) ; if ( userModel == null ) return null ; if ( userModel . isDisabled ( ) ) return null ; byte [ ] hash = encryptionService . createPasswordHash ( password , userModel . getPasswordSalt ( ) ) ; if ( ! Arrays . equals ( hash , userModel . getPasswordHash ( ) ) ) return null ; ModeledUser user = getObjectInstance ( null , userModel ) ; user . setCurrentUser ( new ModeledAuthenticatedUser ( authenticationProvider , user , credentials ) ) ; if ( ! user . isAccountValid ( ) ) throw new GuacamoleClientException ( "LOGIN.ERROR_NOT_VALID" ) ; if ( ! user . isAccountAccessible ( ) ) throw new GuacamoleClientException ( "LOGIN.ERROR_NOT_ACCESSIBLE" ) ; if ( userModel . isExpired ( ) ) { HttpServletRequest request = credentials . getRequest ( ) ; String newPassword = request . getParameter ( NEW_PASSWORD_PARAMETER ) ; String confirmNewPassword = request . getParameter ( CONFIRM_NEW_PASSWORD_PARAMETER ) ; if ( newPassword == null || confirmNewPassword == null ) { logger . info ( "The password of user \"{}\" has expired and must be reset." , username ) ; throw new GuacamoleInsufficientCredentialsException ( "LOGIN.INFO_PASSWORD_EXPIRED" , EXPIRED_PASSWORD ) ; } if ( newPassword . equals ( credentials . getPassword ( ) ) ) throw new GuacamoleClientException ( "LOGIN.ERROR_PASSWORD_SAME" ) ; if ( newPassword . isEmpty ( ) ) throw new GuacamoleClientException ( "LOGIN.ERROR_PASSWORD_BLANK" ) ; if ( ! newPassword . equals ( confirmNewPassword ) ) throw new GuacamoleClientException ( "LOGIN.ERROR_PASSWORD_MISMATCH" ) ; userModel . setExpired ( false ) ; user . setPassword ( newPassword ) ; userMapper . update ( userModel ) ; logger . info ( "Expired password of user \"{}\" has been reset." , username ) ; } return user . getCurrentUser ( ) ; }
retrieves the user corresponding to the given credentials from the database . if the user account is expired , and the credentials contain the necessary additional parameters to reset the user ' s password , the password is reset .
