AuthenticationService { public static TimelyPrincipal authenticate(Authentication authentication, String cacheName) { return authenticate(authentication, SubjectIssuerDNPair.of(cacheName), cacheName); }  static TimelyPrincipal authenticate(Authentication authentication, String cacheName); static TimelyPrincipal authenticate(Authentication authentication, SubjectIssuerDNPair pair, String entity); static TimelyPrincipal authenticate(Authentication authentication, SubjectIssuerDNPair pair, String entity,
            boolean useCache); static void enforceAccess(AuthenticatedRequest request); static X509Certificate getClientCertificate(ChannelHandlerContext ctx); static TimelyPrincipal createPrincipalFromToken(String token); static TimelyPrincipal createPrincipalFromHeaders(Multimap<String, String> httpHeaders); static TimelyAuthenticationToken getAuthenticationToken(Multimap<String, String> headers); static TimelyAuthenticationToken getAuthenticationToken(X509Certificate clientCert,
            Multimap<String, String> headers); static TimelyAuthenticationToken getAuthenticationToken(Object clientCert, String subjectDn,
            String issuerDn); static final String AUTH_HEADER; static final String PRINCIPALS_CLAIM; }
@Test(expected = BadCredentialsException.class) public void testBasicAuthenticationFailure() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("test", "test2"); AuthenticationService.authenticate(token, "test"); }
@Test public void testBasicAuthenticationLogin() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("test", "test1"); TimelyPrincipal principal = AuthenticationService.authenticate(token, "test"); Collection<? extends Collection<String>> authorizations = principal.getAuthorizations(); authorizations.forEach(a -> { Assert.assertTrue(a.contains("A") || a.contains("B") || a.contains("C")); }); }
@Test public void testX509AuthenticationLogin() { PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("CN=example.com", "doesn't matter what I put here"); TimelyPrincipal principal = AuthenticationService.authenticate(token, "test"); Collection<? extends Collection<String>> authorizations = principal.getAuthorizations(); authorizations.forEach(a -> { Assert.assertTrue(a.contains("D") || a.contains("E") || a.contains("F")); }); }
@Test(expected = UsernameNotFoundException.class) public void testX509AuthenticationLoginFailed() { PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("CN=bad.example.com", "doesn't matter what I put here"); TimelyPrincipal principal = AuthenticationService.authenticate(token, "test"); Collection<? extends Collection<String>> authorizations = principal.getAuthorizations(); authorizations.forEach(a -> { Assert.assertTrue(a.contains("D") || a.contains("E") || a.contains("F")); }); }