@Test public void authenticateSuccess() throws Exception { Authentication auth = provider.authenticate(token); assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal()); assertThat(auth.getCredentials()).isEqualTo(token.getCredentials()); assertThat(auth.isAuthenticated()).isEqualTo(true); assertThat(auth.getAuthorities().isEmpty()).isEqualTo(false); verify(publisher).publishEvent(isA(JaasAuthenticationSuccessEvent.class)); verifyNoMoreInteractions(publisher); }
@Test public void javadocExample() { String resName = "/" + getClass().getName().replace('.', '/') + ".xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( resName); context.registerShutdownHook(); try { provider = context.getBean(DefaultJaasAuthenticationProvider.class); Authentication auth = provider.authenticate(token); assertThat(auth.isAuthenticated()).isEqualTo(true); assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal()); } finally { context.close(); } }
@Test public void authenticateBadPassword() { try { provider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf")); fail("LoginException should have been thrown for the bad password"); } catch (AuthenticationException success) { } verifyFailedLogin(); }
@Test public void authenticateBadUser() { try { provider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password")); fail("LoginException should have been thrown for the bad user"); } catch (AuthenticationException success) { } verifyFailedLogin(); }
@Test public void authenticateUnsupportedAuthentication() { assertThat(provider.authenticate(new TestingAuthenticationToken("user", "password"))).isNull(); }
.authenticate(finalAuthentication);