List of usage examples for javax.security.auth.login LoginException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:info.magnolia.cms.security.SecuritySupportBase.java
/** * Logs plain LoginException in error level, but subclasses in debug, since they * are specifically thrown when a known error occurs (wrong password, blocked account, * etc.).// www . j a v a2 s .c o m */ private void logLoginException(LoginException e) { if (e.getClass().equals(LoginException.class)) { log.error("Can't login due to: ", e); } else { // specific subclasses were added in Java5 to identify what the login failure was log.debug("Can't login due to: ", e); } }
From source file:org.marketcetera.modules.remote.receiver.ClientLoginModuleTest.java
/** * Attempt login and test for failure / success conditions * * @param name the user name/*from w ww. jav a2s .c om*/ * @param password the password * @param failure expected failure * @param failureMsg expected failure message * * @return the failure exception if any * * @throws Exception if there was unexpected failure */ private LoginException attemptLogin(String name, char[] password, Class<? extends LoginException> failure, String failureMsg) throws Exception { MockCallbackHandler ch = null; loginContext = null; try { ch = new MockCallbackHandler(name, password); loginContext = new LoginContext(JaasConfiguration.REMOTING_LOGIN_DOMAIN, ch); loginContext.login(); assertNull("Expected failure:" + failure + failureMsg, failure); //verify that the appropriate principals are set in the subject assertTrue(loginContext.getSubject().getPrincipals().toString(), loginContext.getSubject().getPrincipals().contains(new UserPrincipal(getTestUsername()))); } catch (LoginException e) { assertNotNull("Unexpected failure:" + e, failure); assertTrue("Expected:" + failure + ":Actual:" + e.getClass().getName() + e.toString(), failure.isInstance(e)); if (failureMsg != null) { assertEquals(failureMsg, e.getMessage()); } assertNotNull(loginContext); //verify that the appropriate principals are not set in the subject if (loginContext.getSubject() != null && loginContext.getSubject().getPrincipals() != null) { assertFalse(loginContext.getSubject().getPrincipals().toString(), loginContext.getSubject().getPrincipals().contains(new UserPrincipal(getTestUsername()))); } assertEquals(2, ch.getNumCallbacks()); //These values are only set if call back handler doesn't throw //exceptions if (callbackException == null && !doNotHandleCallbacks) { assertEquals(Messages.PROMPT_USERNAME.getText(), ch.getNamePrompt()); assertEquals(Messages.PROMPT_PASSWORD.getText(), ch.getPasswordPrompt()); assertNull(ch.getDefaultName()); } return e; } return null; }