List of usage examples for javax.security.auth.login LoginException getCause
public synchronized Throwable getCause()
From source file:com.qut.middleware.esoe.authn.plugins.spnego.authenticator.KerberosV5Authenticator.java
@SuppressWarnings("unchecked") private String loginAndAction(String loginContextName, KerberosAuthenticationAction actionToPerform) { LoginContext context = null;//from w ww .jav a 2 s . c om try { // Create a LoginContext context = new LoginContext(loginContextName, null, null, this.config); this.logger.trace(Messages.getString("KerberosV5Authenticator.7") + loginContextName); //$NON-NLS-1$ // Perform server authentication context.login(); Subject subject = context.getSubject(); this.logger.trace(subject.toString()); this.logger.trace(Messages.getString("KerberosV5Authenticator.8") + subject.getPrincipals()); //$NON-NLS-1$ // perform kerberos validation return (String) (Subject.doAs(subject, actionToPerform)); } catch (LoginException e) { this.logger.warn(Messages.getString("KerberosV5Authenticator.9")); //$NON-NLS-1$ this.logger.trace(e.getLocalizedMessage(), e); return null; } catch (PrivilegedActionException e) { this.logger.trace(e.getLocalizedMessage(), e); this.logger.trace(Messages.getString("KerberosV5Authenticator.10") + e.getCause().getMessage()); //$NON-NLS-1$ return null; } catch (Exception e) { this.logger.debug(Messages.getString("KerberosV5Authenticator.11") + e.getCause().getMessage()); //$NON-NLS-1$ this.logger.trace(e.getLocalizedMessage(), e); return null; } }
From source file:com.adito.activedirectory.ActiveDirectoryUserDatabaseConfiguration.java
private LoginContext getServiceAccountLoginContext() throws Exception { /*//from ww w . ja v a 2 s .co m * Only attempt to load the service account context if it has not been * loaded, if the username has changed or if the password has changed */ try { return createLoginContext(getServiceAccountName(), getServiceAccountPassword()); } catch (LoginException e) { Throwable cause = e.getCause(); // Check the class by name to allow non Sun Javas to compile if (cause != null && cause.getClass().getName().equals("sun.security.krb5.KrbException")) { throw new Exception("Failed to logon. Please check your Active Directory configuration.", e); } throw e; } }
From source file:ome.client.Interceptor.java
public Object invoke(MethodInvocation arg0) throws Throwable { Object toReturn = null;//from w w w . j a v a2s .c o m Throwable toThrow = null; try { SecurityAssociation.setPrincipal(principal); toReturn = arg0.proceed(); } catch (final Throwable t) { toThrow = t; if (t instanceof RootException) { // This is what we're expecting. } else if (t instanceof javax.ejb.EJBAccessException) { javax.ejb.EJBAccessException ejb = (javax.ejb.EJBAccessException) t; if (ejb.getCause() instanceof LoginException) { LoginException login = (LoginException) ejb.getCause(); if (login.getCause() instanceof org.jboss.util.NestedSQLException) { toThrow = new OutOfService( "Database appears to be down, " + "improperly configured, or corrupted.", t); } } else { // These are allowed to be thrown. } } else if (t instanceof ClassNotFoundException) { if (t.getMessage().contains("org.postgresql.util.PSQLException")) { toThrow = new OutOfService("Database appears to be down, but no exception is " + "available since org.postgresql.util.PSQLException " + "is not on your classpath", t); } else { toThrow = new OutOfService("Client appears improperly configured.", t); } } else if (t instanceof JndiLookupFailureException) { toThrow = new OutOfService("Cannot find service. Is the server running?"); } else { toThrow = new OutOfService("Error during invocation. " + "Most likely server version does " + "not match client version", t); } } finally { SecurityAssociation.setPrincipal(unknown); } if (toThrow != null) { throw toThrow; } else { return toReturn; } }
From source file:org.marketcetera.modules.remote.receiver.ClientLoginModuleTest.java
/** * test unsupported callbacks//from w ww. j a v a 2 s . c o m * @throws Exception if there was failure */ @Test public void unsupportedCallback() throws Exception { doNotHandleCallbacks = true; UnsupportedCallbackException uce = new UnsupportedCallbackException( new NameCallback(Messages.PROMPT_USERNAME.getText())); LoginException ex = attemptLogin(getTestUsername(), getTestPassword(), LoginException.class, uce.getMessage()); assertNotNull(ex.getCause()); assertTrue(ex.getCause() instanceof UnsupportedCallbackException); Callback callback = ((UnsupportedCallbackException) ex.getCause()).getCallback(); assertNotNull(callback); assertTrue(callback.getClass().toString(), callback instanceof NameCallback); org.junit.Assert.assertEquals(Messages.PROMPT_USERNAME.getText(), ((NameCallback) callback).getPrompt()); }
From source file:org.marketcetera.modules.remote.receiver.ClientLoginModuleTest.java
/** * test callback io failure/*from w w w.j a va 2s.c o m*/ * @throws Exception if there was a failure */ @Test public void callbackIOFailure() throws Exception { callbackException = new IOException("ioeoeoe"); //$NON-NLS-1$ LoginException ex = attemptLogin(getTestUsername(), getTestPassword(), LoginException.class, callbackException.getMessage()); assertNotNull(ex.getCause()); assertTrue(ex.getCause() instanceof IOException); assertSame(callbackException, ex.getCause()); }
From source file:org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.java
protected Principal doAuthenticate(CachableUserIdentificationInfo cachableUserIdent, HttpServletRequest httpRequest) { LoginContext loginContext;// w ww .ja v a2 s .c o m try { CallbackHandler handler = service.getCallbackHandler(cachableUserIdent.getUserInfo()); loginContext = new LoginContext(securityDomain, handler); if (isLoginSynchronized()) { synchronized (NuxeoAuthenticationFilter.class) { loginContext.login(); } } else { loginContext.login(); } Principal principal = (Principal) loginContext.getSubject().getPrincipals().toArray()[0]; cachableUserIdent.setPrincipal(principal); cachableUserIdent.setAlreadyAuthenticated(true); // re-set the userName since for some SSO based on token, // the userName is not known before login is completed cachableUserIdent.getUserInfo().setUserName(principal.getName()); logAuthenticationAttempt(cachableUserIdent.getUserInfo(), true); } catch (LoginException e) { log.info("Login failed for " + cachableUserIdent.getUserInfo().getUserName()); logAuthenticationAttempt(cachableUserIdent.getUserInfo(), false); Throwable cause = e.getCause(); if (cause instanceof DirectoryException) { Throwable rootCause = ExceptionUtils.getRootCause(cause); if (rootCause instanceof NamingException && rootCause.getMessage().contains("LDAP response read timed out") || rootCause instanceof SocketException) { httpRequest.setAttribute(LOGIN_STATUS_CODE, HttpServletResponse.SC_GATEWAY_TIMEOUT); } return DIRECTORY_ERROR_PRINCIPAL; } return null; } // store login context for the time of the request // TODO logincontext is also stored in cachableUserIdent - it is really // needed to store it?? httpRequest.setAttribute(LOGINCONTEXT_KEY, loginContext); // store user ident cachableUserIdent.setLoginContext(loginContext); boolean createSession = needSessionSaving(cachableUserIdent.getUserInfo()); HttpSession session = httpRequest.getSession(createSession); if (session != null) { session.setAttribute(USERIDENT_KEY, cachableUserIdent); } service.onAuthenticatedSessionCreated(httpRequest, session, cachableUserIdent); return cachableUserIdent.getPrincipal(); }