List of usage examples for javax.security.auth.login LoginException LoginException
public LoginException(String msg)
From source file:com.ideabase.repository.core.auth.RepositoryLoginModule.java
/** * clean out the states, request for retrieving user password and user name<br> * verify user name and password. if both match return successful * authentication.<br>/* ww w. j ava 2 s. c om*/ * otherwise throw {@see LoginException} or return false. * @return true if login is successful, * @throws LoginException if authentication failed. */ public boolean login() throws LoginException { LOG.debug("Login action in process."); mSucceeded = false; mCommitSucceeded = false; try { // find user name; final String[] userAndPassword = getUserAndPassword(); final String userName = userAndPassword[0]; final String userPassword = userAndPassword[1]; // Try to authenticate LOG.debug("Trying to perform loging action."); authenticateUser(userName, userPassword); mSucceeded = true; LOG.debug("Login successful."); } catch (Exception e) { LOG.warn("Exception raised during authentication.", e); throw new LoginException("Login action failed."); } return mSucceeded; }
From source file:com.cubusmail.server.mail.security.MailboxLoginModule.java
/** * Map a MessagingException to a LoginException. * /*from w w w . j a v a 2s . c om*/ * @param e * @throws LoginException */ private void mapMessagingException(MessagingException e) throws LoginException { if (e instanceof AuthenticationFailedException) { throw new LoginException(IErrorCodes.EXCEPTION_AUTHENTICATION_FAILED); } else if (e.getCause() != null && e.getCause() instanceof java.net.ConnectException) { throw new LoginException(IErrorCodes.EXCEPTION_CONNECT); } else { throw new LoginException(IErrorCodes.EXCEPTION_GENERAL); } }
From source file:org.acegisecurity.providers.jaas.SecurityContextLoginModule.java
/** * Authenticate the <code>Subject</code> (phase one) by extracting the Acegi Security * <code>Authentication</code> from the current <code>SecurityContext</code>. * * @return true if the authentication succeeded, or false if this <code>LoginModule</code> should be ignored. * * @throws LoginException if the authentication fails *//* w w w .j a va 2 s .c o m*/ public boolean login() throws LoginException { authen = SecurityContextHolder.getContext().getAuthentication(); if (authen == null) { String msg = "Login cannot complete, authentication not found in security context"; if (ignoreMissingAuthentication) { log.warn(msg); return false; } else { throw new LoginException(msg); } } return true; }
From source file:org.opengroupware.logic.auth.OGoLoginModule.java
@Override public boolean login() throws LoginException { if (this.database == null) throw new LoginException("missing valid JAAS OGo database config!"); if (this.handler == null) throw new LoginException("missing JAAS callback handler!"); // TBD: check whether there is some known principal, eg from an LDAP // login, if so, perform principal=>OGo UID mapping and add // a specific OGo principal if (this.tokenManager != null) { if (this.loginWithTokens()) return true; }/*from ww w. j av a2 s.c om*/ if (this.loginWithUsernameAndPassword()) return true; return false; }
From source file:org.rhq.enterprise.gui.legacy.portlet.resourcehealth.RSSAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { RSSFeed feed = getNewRSSFeed(request); ResourceManagerLocal manager = LookupUtil.getResourceManager(); // Set title//from w w w. ja v a 2 s . c o m MessageResources res = getResources(request); feed.setTitle(res.getMessage("dash.home.ResourceHealth")); // Get the resources health WebUser user = getWebUser(request); if (user != null) { WebUserPreferences preferences = user.getWebPreferences(); FavoriteResourcePortletPreferences favoriteResourcePreferences = preferences .getFavoriteResourcePortletPreferences(); PageList<ResourceHealthComposite> results = manager.findResourceHealth(user.getSubject(), favoriteResourcePreferences.asArray(), PageControl.getUnlimitedInstance()); if ((results != null) && (results.size() > 0)) { PageList<DisambiguationReport<ResourceHealthComposite>> list = DisambiguatedResourceListUtil .disambiguate(manager, results, ViewAction.RESOURCE_ID_EXTRACTOR); for (DisambiguationReport<ResourceHealthComposite> summary : list) { String link = feed.getBaseUrl() + FunctionTagLibrary.getDefaultResourceTabURL() + "?id=" + summary.getOriginal().getId(); String availText = res.getMessage("dash.home.ResourceHealth.rss.item.availability", summary.getOriginal().getAvailabilityType().toString()); String alertsText = res.getMessage("dash.home.ResourceHealth.rss.item.alerts", Long.valueOf(summary.getOriginal().getAlerts())); String typeText = res.getMessage("dash.home.ResourceHealth.rss.item.resourceType", summary.getOriginal().getTypeName()); String parentsText = res.getMessage("dash.home.ResourceHealth.rss.item.resourceParents", getLineage(summary)); long now = System.currentTimeMillis(); StringBuffer desc = new StringBuffer(); desc.append("<table><tr><td align=\"left\">").append(typeText).append("</td></tr>"); desc.append("<tr><td align=\"left\">").append(parentsText).append("</td></tr>"); if (favoriteResourcePreferences.showAvailability) { desc.append("<tr><td align=\"left\">").append(availText).append("</td></tr>"); } if (favoriteResourcePreferences.showAlerts) { desc.append("<tr><td align=\"left\">").append(alertsText).append("</td></tr>"); } desc.append("</table>"); feed.addItem(summary.getOriginal().getName(), link, desc.toString(), now); } } request.setAttribute("rssFeed", feed); return mapping.findForward(Constants.RSS_URL); } else { throw new LoginException("RSS access requires authentication"); } }
From source file:org.efaps.jaas.xml.XMLUserLoginModule.java
/** * Method to authenticate a <code>Subject</code> (phase 1). * * <p> The implementation of this method authenticates * a <code>Subject</code>. For example, it may prompt for * <code>Subject</code> information such * as a username and password and then attempt to verify the password. * This method saves the result of the authentication attempt * as private state within the LoginModule. * * <p>/*www . j a va 2 s . c om*/ * * @exception LoginException if the authentication fails * * @return true if the authentication succeeded, or false if this * <code>LoginModule</code> should be ignored. */ public final boolean login() throws LoginException { boolean ret = false; final Callback[] callbacks = new Callback[3]; callbacks[0] = new ActionCallback(); callbacks[1] = new NameCallback("Username: "); callbacks[2] = new PasswordCallback("Password: ", false); // Interact with the user to retrieve the username and password String userName = null; String password = null; try { this.callbackHandler.handle(callbacks); this.mode = ((ActionCallback) callbacks[0]).getMode(); userName = ((NameCallback) callbacks[1]).getName(); if (((PasswordCallback) callbacks[2]).getPassword() != null) { password = new String(((PasswordCallback) callbacks[2]).getPassword()); } } catch (final IOException e) { throw new LoginException(e.toString()); } catch (final UnsupportedCallbackException e) { throw new LoginException(e.toString()); } if (this.mode == ActionCallback.Mode.ALL_PERSONS) { ret = true; } else if (this.mode == ActionCallback.Mode.PERSON_INFORMATION) { this.person = this.allPersons.get(userName); if (this.person != null) { if (XMLUserLoginModule.LOG.isDebugEnabled()) { XMLUserLoginModule.LOG.debug("found '" + this.person + "'"); } ret = true; } } else { this.person = this.allPersons.get(userName); if (this.person != null) { if ((password == null) || ((password != null) && !password.equals(this.person.getPassword()))) { XMLUserLoginModule.LOG .error("person '" + this.person + "' tried to log in with wrong password"); this.person = null; throw new FailedLoginException("Username or password is incorrect"); } if (XMLUserLoginModule.LOG.isDebugEnabled()) { XMLUserLoginModule.LOG.debug("log in of '" + this.person + "'"); } this.mode = ActionCallback.Mode.LOGIN; ret = true; } } return ret; }
From source file:org.collectionspace.authentication.realm.db.CSpaceDbRealm.java
@Override public String getUsersPassword(String username) throws LoginException { String password = null;/* ww w. j a va 2s . c o m*/ Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getConnection(); // Get the password if (logger.isDebugEnabled()) { logger.debug("Executing query: " + principalsQuery + ", with username: " + username); } ps = conn.prepareStatement(principalsQuery); ps.setString(1, username); rs = ps.executeQuery(); if (rs.next() == false) { if (logger.isDebugEnabled()) { logger.debug(principalsQuery + " returned no matches from db"); } throw new FailedLoginException("No matching username found"); } password = rs.getString(1); } catch (SQLException ex) { LoginException le = new LoginException("Query failed"); le.initCause(ex); throw le; } catch (Exception ex) { LoginException le = new LoginException("Unknown Exception"); le.initCause(ex); throw le; } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { } } if (ps != null) { try { ps.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { } } } return password; }
From source file:com.ibm.tivoli.tuna.jaas.sample.SampleLoginModule.java
/** * Authenticate the user by prompting for a user name and password. * // w ww .ja v a2 s . co m * <p> * * @return true in all cases since this <code>LoginModule</code> should not be * ignored. * * @exception FailedLoginException * if the authentication fails. * <p> * * @exception LoginException * if this <code>LoginModule</code> is unable to perform the * authentication. */ public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((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 ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } // print debugging information if (debug) { log.info("\t\t[SampleLoginModule] " + "user entered user name: " + username); log.info("\t\t[SampleLoginModule] " + "user entered password: "); } // verify the username/password boolean usernameCorrect = false; boolean passwordCorrect = false; if (username.equals("testUser")) usernameCorrect = true; if (usernameCorrect && password.length == 12 && password[0] == 't' && password[1] == 'e' && password[2] == 's' && password[3] == 't' && password[4] == 'P' && password[5] == 'a' && password[6] == 's' && password[7] == 's' && password[8] == 'w' && password[9] == 'o' && password[10] == 'r' && password[11] == 'd') { // authentication succeeded!!! passwordCorrect = true; if (debug) log.info("\t\t[SampleLoginModule] " + "authentication succeeded"); succeeded = true; return true; } else { // authentication failed -- clean out state if (debug) log.info("\t\t[SampleLoginModule] " + "authentication failed"); succeeded = false; username = null; for (int i = 0; i < password.length; i++) password[i] = ' '; password = null; if (!usernameCorrect) { throw new FailedLoginException("User Name Incorrect"); } else { throw new FailedLoginException("Password Incorrect"); } } }
From source file:client.SampleLoginModule.java
/** * Authenticate the user by prompting for a user name and password. * /*from ww w. j a v a2 s .c o m*/ * <p> * * @return true in all cases since this <code>LoginModule</code> should * not be ignored. * * @exception FailedLoginException * if the authentication fails. * <p> * * @exception LoginException * if this <code>LoginModule</code> is unable to perform * the authentication. */ public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); String tmpPassword = String.copyValueOf(((PasswordCallback) callbacks[1]).getPassword()); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = ""; } password = tmpPassword; //System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length()); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } // print debugging information if (debug) { System.out.println("\t\t[SampleLoginModule] " + "user entered user name: " + username); System.out.print("\t\t[SampleLoginModule] " + "user entered password: "); for (int i = 0; i < password.length(); i++) System.out.print(password.toCharArray()[i]); System.out.println(); } cmdAuthent.setUsern(username); cmdAuthent.setPassw(password); cmdAuthent.execute(); return cmdAuthent.getRes(); }
From source file:net.sf.jpam.jaas.JpamLoginModule.java
/** * Method to authenticate a <code>Subject</code> (phase 1). * <p/>/* ww w .jav a 2s .c o m*/ * <p> The implementation of this method authenticates * a <code>Subject</code>. For example, it may prompt for * <code>Subject</code> information such * as a username and password and then attempt to verify the password. * This method saves the result of the authentication attempt * as private state within the LoginModule. * <p/> * <p/> * * @return true if the authentication succeeded, or false if this * <code>LoginModule</code> should be ignored. * @throws javax.security.auth.login.LoginException * if the authentication fails */ public boolean login() throws LoginException { pam = createPam(); Callback[] callbacks = new Callback[2]; String username = null; NameCallback nameCallback = new NameCallback("Enter Username: "); callbacks[0] = nameCallback; String credentials = null; PasswordCallback passwordCallback = new PasswordCallback("Enter Credentials: ", false); callbacks[1] = passwordCallback; try { callbackHandler.handle(callbacks); } catch (IOException e) { LOG.error("IOException handling login: " + e.getMessage(), e); throw new LoginException(e.getMessage()); } catch (UnsupportedCallbackException e) { LOG.error("UnsupportedCallbackException handling login: " + e.getMessage(), e); throw new LoginException(e.getMessage()); } username = nameCallback.getName(); credentials = String.copyValueOf(passwordCallback.getPassword()); boolean authenticated = false; PamReturnValue pamReturnValue = pam.authenticate(username, credentials); if (pamReturnValue.equals(PamReturnValue.PAM_SUCCESS)) { authenticated = true; } else if (pamReturnValue.equals(PamReturnValue.PAM_ACCT_EXPIRED)) { throw new AccountExpiredException(PamReturnValue.PAM_ACCT_EXPIRED.toString()); } else if (pamReturnValue.equals(PamReturnValue.PAM_CRED_EXPIRED)) { throw new CredentialExpiredException(PamReturnValue.PAM_CRED_EXPIRED.toString()); } else { throw new FailedLoginException(pamReturnValue.toString()); } return authenticated; }