Merge branch 'support/2.6.x' into develop

This commit is contained in:
René Pfeuffer
2020-10-09 12:16:23 +02:00
7 changed files with 103 additions and 8 deletions

View File

@@ -89,7 +89,7 @@ public final class JwtAccessTokenResolver implements AccessTokenResolver {
if (!validator.validate(accessToken)) {
String msg = createValidationFailedMessage(validator, accessToken);
LOG.debug(msg);
throw new AuthenticationException(msg);
throw new TokenValidationFailedException(validator, accessToken);
}
}

View File

@@ -55,16 +55,16 @@ public class ScmAtLeastOneSuccessfulStrategy extends AbstractAuthenticationStrat
}
@Override
public AuthenticationInfo afterAllAttempts(AuthenticationToken token, AuthenticationInfo aggregate) throws AuthenticationException {
public AuthenticationInfo afterAllAttempts(AuthenticationToken token, AuthenticationInfo aggregate) {
final List<Throwable> throwables = threadLocal.get();
threadLocal.remove();
if (isAuthenticationSuccessful(aggregate)) {
return aggregate;
}
Optional<TokenExpiredException> tokenExpiredException = findTokenExpiredException(throwables);
Optional<? extends AuthenticationException> specializedException = findSpecializedException(throwables);
if (tokenExpiredException.isPresent()) {
throw tokenExpiredException.get();
if (specializedException.isPresent()) {
throw specializedException.get();
} else {
throw createAuthenticationException(token);
}
@@ -82,6 +82,18 @@ public class ScmAtLeastOneSuccessfulStrategy extends AbstractAuthenticationStrat
return throwables.stream().filter(t -> t instanceof TokenExpiredException).findFirst().map(t -> (TokenExpiredException) t);
}
private static Optional<AuthenticationException> findTokenValidationFailedException(List<Throwable> throwables) {
return throwables.stream().filter(t -> t instanceof TokenValidationFailedException).findFirst().map(t -> (TokenValidationFailedException) t);
}
private static Optional<? extends AuthenticationException> findSpecializedException(List<Throwable> throwables) {
Optional<TokenExpiredException> tokenExpiredException = findTokenExpiredException(throwables);
if (tokenExpiredException.isPresent()) {
return tokenExpiredException;
}
return findTokenValidationFailedException(throwables);
}
private static AuthenticationException createAuthenticationException(AuthenticationToken token) {
return new AuthenticationException("Authentication token of type [" + token.getClass() + "] " +
"could not be authenticated by any configured realms. Please ensure that at least one realm can " +