List of usage examples for javax.security.auth.login FailedLoginException getMessage
public String getMessage()
From source file:gov.nih.nci.security.authentication.loginmodules.CSMLoginModule.java
public boolean changePassword(String newPassword) throws LoginException, CSInternalLoginException, CSInternalConfigurationException, CSConfigurationException { if (callbackHandler == null) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in obtaining the CallBack Handler |"); throw new LoginException("Error in obtaining Callback Handler"); }//from w w w. j a v a2s . co m Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("userid: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); userID = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = new char[0]; } password = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException e) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in creating the CallBack Handler |" + e.getMessage()); throw new LoginException("Error in Creating the CallBack Handler"); } catch (UnsupportedCallbackException e) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in creating the CallBack Handler |" + e.getMessage()); throw new LoginException("Error in Creating the CallBack Handler"); } try { //now validate user if (validate(options, userID, password, subject)) { DataConfiguration config = ConfigurationHelper.getConfiguration(); String encryptedPassword = new String(password); encryptedPassword = StringUtilities.initTrimmedString(encryptPassword(encryptedPassword, "YES")); if (encryptedPassword.equals(encryptPassword(newPassword, "YES"))) { throw new LoginException("The password should be different from the previous passwords"); } if (passwordMatchs(options, userID, newPassword, Integer.parseInt(config.getString("PASSWORD_MATCH_NUM")))) { throw new LoginException("The password should be different from the previous passwords"); } else { changePassword(options, userID, newPassword); if (isFirstTimeLogin(options, userID)) resetFirstTimeLogin(options, userID); insertIntoPasswordHistory(options, userID, password); updatePasswordExpiryDate(options, userID, DateUtils.addDays(Calendar.getInstance().getTime(), Integer.parseInt(config.getString("PASSWORD_EXPIRY_DAYS")))); } } else { // clear the values loginSuccessful = false; userID = null; password = null; throw new FailedLoginException("Invalid Login Credentials"); } } catch (FailedLoginException fle) { if (log.isDebugEnabled()) if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Invalid Login Credentials |" + fle.getMessage()); throw new LoginException("Invalid Login Credentials"); } if (log.isDebugEnabled()) log.debug("Authentication|||login|Success| Authentication is " + loginSuccessful + "|"); return loginSuccessful; }
From source file:gov.nih.nci.security.authentication.loginmodules.CSMLoginModule.java
/** * Retrieves the user credentials from the CallBacks and tries to validate * them against the database. It retrieves userID and password from the * CallbackHandler. It uses helper class to perform the actual authentication * operations and access the user record. This method returns a true if * the user authentication was sucessful else it throws a Login Exception. * @throws LoginException //from w w w . j av a 2s. com * @see javax.security.auth.spi.LoginModule#login() */ public boolean login() throws LoginException, CSInternalLoginException, CSInternalConfigurationException { if (callbackHandler == null) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in obtaining the CallBack Handler |"); throw new LoginException("Error in obtaining Callback Handler"); } Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("userid: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); userID = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = new char[0]; } password = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException e) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in creating the CallBack Handler |" + e.getMessage()); throw new LoginException("Error in Creating the CallBack Handler"); } catch (UnsupportedCallbackException e) { if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Error in creating the CallBack Handler |" + e.getMessage()); throw new LoginException("Error in Creating the CallBack Handler"); } if (isFirstTimeLogin(options, userID)) { loginSuccessful = false; password = null; throw new FailedLoginException("User logging in first time, Password should be changed "); } DataConfiguration config; try { config = ConfigurationHelper.getConfiguration(); } catch (CSConfigurationException e) { // TODO Auto-generated catch block throw new CSInternalConfigurationException("Exception while reading config data!!"); } if (isPasswordExpired(options, userID)) { loginSuccessful = false; userID = null; password = null; throw new CredentialExpiredException("User password expired, Ceate new password"); } try { //now validate user if (validate(options, userID, password, subject)) { if (isActive(options, userID)) loginSuccessful = true; else { loginSuccessful = false; password = null; throw new AccountExpiredException("User is not active, Contact the system administrator"); } } else { // clear the values loginSuccessful = false; userID = null; password = null; throw new LoginException("Invalid Login Credentials"); } } catch (FailedLoginException fle) { if (log.isDebugEnabled()) if (log.isDebugEnabled()) log.debug("Authentication|||login|Failure| Invalid Login Credentials |" + fle.getMessage()); throw new LoginException("Invalid Login Credentials"); } if (log.isDebugEnabled()) log.debug("Authentication|||login|Success| Authentication is " + loginSuccessful + "|"); return loginSuccessful; }