/** * Creates a new cached authenticator. * * @param metricRegistry the application's registry of metrics * @param authenticator the underlying authenticator * @param builder a {@link Caffeine} */ public CachingAuthenticator(final MetricRegistry metricRegistry, final Authenticator<C, P> authenticator, final Caffeine<Object, Object> builder) { this.cacheMisses = metricRegistry.meter(name(authenticator.getClass(), "cache-misses")); this.gets = metricRegistry.timer(name(authenticator.getClass(), "gets")); this.cache = builder.recordStats().build(key -> { cacheMisses.mark(); final Optional<P> optPrincipal = authenticator.authenticate(key); if (!optPrincipal.isPresent()) { // Prevent caching of unknown credentials throw new InvalidCredentialsException(); } return optPrincipal; }); }
final Optional<P> principal = authenticator.authenticate(credentials); if (!principal.isPresent()) { return false;
private P tryAuthenticateUsingJwtToken(String jwtToken) throws WebApplicationException { try { Optional<P> possiblePrincipal = this.authenticator.authenticate(jwtToken); if (possiblePrincipal.isPresent()) return possiblePrincipal.get(); else throw new WebApplicationException("Authentication failed for the supplied json web token.", 401); } catch (AuthenticationException ex) { throw new WebApplicationException("Authentication failed for the supplied json web token.", 401); } }
@Override public Optional<P> load(C key) throws Exception { cacheMisses.mark(); final Optional<P> optPrincipal = authenticator.authenticate(key); if (!optPrincipal.isPresent()) { // Prevent caching of unknown credentials throw new InvalidCredentialsException(); } return optPrincipal; } });
@Override public Optional<P> authenticate(JwtContext context) throws AuthenticationException { final Timer.Context timer = gets.time(); try { final SimpleEntry<JwtContext, Optional<P>> cacheEntry = cache.getIfPresent(context.getJwt()); if (cacheEntry != null) { return cacheEntry.getValue(); } cacheMisses.mark(); final Optional<P> principal = authenticator.authenticate(context); if (principal.isPresent()) { cache.put(context.getJwt(), new SimpleEntry<>(context, principal)); } return principal; } finally { timer.stop(); } }
@Override public Optional<P> authenticate(JwtContext context) throws AuthenticationException { final Timer.Context timer = gets.time(); try { final SimpleEntry<JwtContext, Optional<P>> cacheEntry = cache.getIfPresent(context.getJwt()); if (cacheEntry != null) { return cacheEntry.getValue(); } cacheMisses.mark(); final Optional<P> principal = authenticator.authenticate(context); if (principal.isPresent()) { cache.put(context.getJwt(), new SimpleEntry<>(context, principal)); } return principal; } finally { timer.stop(); } }
@Override public Result check() throws AuthenticationException { if (ldapAuthenticator.authenticate(new BasicCredentials("", "")).isPresent()) { return Result.healthy(); } else { return Result.unhealthy("Cannot contact authentication service"); } } }
@Override public void filter(final ContainerRequestContext requestContext) throws IOException { try { final Optional<P> principal = authenticator.authenticate(null); if (principal.isPresent()) { requestContext.setSecurityContext(new SecurityContext() {
try { GitLabCredentials gitLabCredentials = new GitLabCredentials(username, password); final Optional<Principal> principal = authenticator.authenticate(gitLabCredentials); if (principal.isPresent()) { requestContext.setSecurityContext(new SecurityContext() {
try { final JwtContext jwtContext = verifyToken(optionalToken.get()); final Optional<P> principal = authenticator.authenticate(jwtContext);
try { final JwtContext jwtContext = verifyToken(optionalToken.get()); final Optional<P> principal = authenticator.authenticate(jwtContext);
final Optional<P> principal; try { principal = authenticator.authenticate(request); if (principal.isPresent()) { requestContext.setSecurityContext(new SecurityContext() {
final Optional<P> principal = authenticator.authenticate(credentials); if (!principal.isPresent()) { return false;
throw new WebApplicationException(Response.Status.UNAUTHORIZED); Optional<Token> result = authenticator.authenticate(tokenCookie.getValue()); } else { try { Optional<Token> result = authenticator.authenticate(tokenCookie.getValue()); if (result.isPresent()) { return result.get();
throw unauthorized(); Optional<BasicToken> result = authenticator.authenticate(tokenCookie.getValue()); } else { try { Optional<BasicToken> result = authenticator.authenticate(tokenCookie.getValue()); if (result.isPresent()) { return result.get();
Optional<?> principal = authentication.getAuthenticator().authenticate( new BasicCredentials(credentials.getUsername(), credentials.getPassword()));