Throwable cause = e.getCause(); if (cause instanceof DirectoryException) { Throwable rootCause = ExceptionUtils.getRootCause(cause);
@Test public void testUnauthenticated() throws Exception { LoginContext context = new LoginContext("UnAuthenticatedLDAPLogin", new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { ((NameCallback) callbacks[i]).setName("first"); } else if (callbacks[i] instanceof PasswordCallback) { ((PasswordCallback) callbacks[i]).setPassword("secret".toCharArray()); } else { throw new UnsupportedCallbackException(callbacks[i]); } } } }); try { context.login(); } catch (LoginException le) { assertEquals(le.getCause().getMessage(), "Empty password is not allowed"); return; } fail("Should have failed authenticating"); assertTrue("sessions still active after logout", waitFor(() -> ldapServer.getLdapSessionManager().getSessions().length == 0)); }
Assert.fail("Login should have failed."); } catch (LoginException e) { assertEquals(TicketValidationException.class, e.getCause().getClass());
fail("Should have thrown FailedLoginException."); } catch (LoginException e) { assertEquals(TicketValidationException.class, e.getCause().getClass());
/** * Test JAAS login failure. * @throws Exception On errors. */ @Test public void testLoginFailure() throws Exception { final String SERVICE = "https://example.com/service"; final String TICKET = "ST-200000-aA5Yuvrxzpv8Tau1cYQ7-srv1"; final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationFailure code=\"INVALID_TICKET\">Ticket ST-200000-aA5Yuvrxzpv8Tau1cYQ7-srv1 not recognized</cas:authenticationFailure></cas:serviceResponse>"; server.content = RESPONSE.getBytes(server.encoding); module.initialize( subject, new ServiceAndTicketCallbackHandler(SERVICE, TICKET), new HashMap<String, Object>(), options); try { module.login(); fail("Login did not throw FailedLoginException as expected."); } catch (LoginException e) { assertEquals(TicketValidationException.class, e.getCause().getClass()); } module.commit(); assertNull(module.ticket); assertNull(module.assertion); }