New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LoadingCache in CachingAuthenticator. #1615

Merged
merged 1 commit into from Jul 27, 2016

Conversation

Projects
None yet
5 participants
@pkwarren
Contributor

pkwarren commented Jun 29, 2016

Update CachingAuthenticator to use a LoadingCache instead of a Cache,
which will allow multiple concurrent requests to the cache for an
uncached value to only result in one call to the authenticator. The
current behavior to not cache invalid credentials is preserved.

@pkwarren

This comment has been minimized.

Contributor

pkwarren commented Jun 29, 2016

Implements the feature requested in #1614.

@jplock jplock added the improvement label Jun 29, 2016

@jplock jplock added this to the 1.1.0 milestone Jun 29, 2016

@coveralls

This comment has been minimized.

coveralls commented Jun 29, 2016

Coverage Status

Coverage increased (+0.001%) to 82.158% when pulling 0ac9d71 on pkwarren:loading_cache_authenticator into 6532a8e on dropwizard:master.

@evnm

This comment has been minimized.

Member

evnm commented Jun 29, 2016

Very neat. LGTM.

@@ -38,5 +38,10 @@
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<scope>test</scope>
</dependency>
<dependency>

This comment has been minimized.

@arteam

arteam Jun 30, 2016

Member

You can remove this dependency, because Hamcrest is already imported to the module via JUnit.

cache.put(credentials, optionalPrincipal);
}
return cache.get(credentials);
} catch (UncheckedExecutionException|ExecutionException e) {

This comment has been minimized.

@arteam

arteam Jun 30, 2016

Member

I think it's better to handle checked and unchecked exceptions separately to indicate that we know what to do with checked exceptions and we can't do anything with unchecked. Something like that:

} catch (ExecutionException e) {
    final Throwable cause = e.getCause();
    if (cause instanceof InvalidCredentialsException) {
        return Optional.empty();
    }
    Throwables.propagateIfInstanceOf(cause, AuthenticationException.class);
    throw new AuthenticationException(cause);
} catch (UncheckedExecutionException e) {
    throw Throwables.propagate(e.getCause());
}
Throwables.propagateIfPossible(cause, AuthenticationException.class);

// Rethrow other checked exceptions wrapped in an AuthenticationException (this shouldn't happen)
throw new AuthenticationException(Optional.ofNullable(cause).orElse(e));

This comment has been minimized.

@arteam

arteam Jun 30, 2016

Member

Despite it's possible to have a null value for a cause for an exception, I think we can't get an ExecutionException without a cause from a LoadingCache, so it's safe to avoid this check.

@arteam

This comment has been minimized.

Member

arteam commented Jun 30, 2016

LGTM as well, a couple of suggestions in comments.

@pkwarren pkwarren force-pushed the pkwarren:loading_cache_authenticator branch from 0ac9d71 to e773609 Jun 30, 2016

@pkwarren

This comment has been minimized.

Contributor

pkwarren commented Jun 30, 2016

@arteam - Thanks for the review. Updated based on your comments.

@coveralls

This comment has been minimized.

coveralls commented Jun 30, 2016

Coverage Status

Coverage increased (+0.006%) to 82.164% when pulling e773609 on pkwarren:loading_cache_authenticator into 6532a8e on dropwizard:master.

@evnm

This comment has been minimized.

Member

evnm commented Jul 17, 2016

Any reason this hasn't been merged yet? All committer feedback seems to have been addressed.

@jplock

This comment has been minimized.

Member

jplock commented Jul 17, 2016

@evnm waiting until 1.0.0 final has been released first

Philip K. Warren
Use LoadingCache in CachingAuthenticator.
Update CachingAuthenticator to use a LoadingCache instead of a Cache,
which will allow multiple concurrent requests to the cache for an
uncached value to only result in one call to the authenticator. The
current behavior to not cache invalid credentials is preserved.

@pkwarren pkwarren force-pushed the pkwarren:loading_cache_authenticator branch from e773609 to d004ffb Jul 26, 2016

@coveralls

This comment has been minimized.

coveralls commented Jul 26, 2016

Coverage Status

Coverage increased (+0.006%) to 82.207% when pulling d004ffb on pkwarren:loading_cache_authenticator into 0880fcd on dropwizard:master.

@jplock jplock merged commit 8b90d67 into dropwizard:master Jul 27, 2016

@pkwarren pkwarren deleted the pkwarren:loading_cache_authenticator branch Oct 31, 2016

FredDeschenes added a commit to FredDeschenes/dropwizard that referenced this pull request Jul 5, 2017

Use LoadingCache in CachingAuthorizer
As done in dropwizard#1615 for CachingAuthenticator

FredDeschenes added a commit to FredDeschenes/dropwizard that referenced this pull request Jul 5, 2017

Use LoadingCache in CachingAuthorizer
As done in dropwizard#1615 for CachingAuthenticator

arteam added a commit that referenced this pull request Jul 5, 2017

Use LoadingCache in CachingAuthorizer (#2096)
As done in #1615 for CachingAuthenticator

sankate pushed a commit to sankate/dropwizard that referenced this pull request Nov 21, 2017

aaanders added a commit to aaanders/dropwizard that referenced this pull request Sep 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment