AuthenticationService { public static AuthenticationManager getAuthenticationManager() { return authManager; }  static AuthenticationManager getAuthenticationManager(); static String extractDN(X509Certificate clientCert);  }
@Test(expected = BadCredentialsException.class) public void testBasicAuthenticationFailure() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("test", "test2"); AuthenticationService.getAuthenticationManager().authenticate(token); }
@Test public void testBasicAuthenticationLogin() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("test", "test1"); Authentication auth = AuthenticationService.getAuthenticationManager().authenticate(token); Collection<? extends GrantedAuthority> authorizations = auth.getAuthorities(); authorizations.forEach(a -> { Assert.assertTrue( a.getAuthority().equals("A") || a.getAuthority().equals("B") || a.getAuthority().equals("C")); }); }
@Test public void testX509AuthenticationLogin() { PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("example.com", "doesn't matter what I put here"); Authentication auth = AuthenticationService.getAuthenticationManager().authenticate(token); Collection<? extends GrantedAuthority> authorizations = auth.getAuthorities(); authorizations.forEach(a -> { Assert.assertTrue( a.getAuthority().equals("D") || a.getAuthority().equals("E") || a.getAuthority().equals("F")); }); }
@Test(expected = UsernameNotFoundException.class) public void testX509AuthenticationLoginFailed() { PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("bad.example.com", "doesn't matter what I put here"); Authentication auth = AuthenticationService.getAuthenticationManager().authenticate(token); Collection<? extends GrantedAuthority> authorizations = auth.getAuthorities(); authorizations.forEach(a -> { Assert.assertTrue( a.getAuthority().equals("D") || a.getAuthority().equals("E") || a.getAuthority().equals("F")); }); }