Skip to content
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

Refactor Token Service #39808

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bf30a42
Move all ActionListeners as the last positional parameter
albertzaharovits Mar 5, 2019
d4e5480
Do not throw from methods with listeners
albertzaharovits Mar 5, 2019
6b75095
Reuse and simplify parseTokensFromDocument
albertzaharovits Mar 5, 2019
4a4ab62
findTokenFromRefreshToken return SearchHit
albertzaharovits Mar 5, 2019
291881b
Refactor inner_refresh
albertzaharovits Mar 6, 2019
15b7674
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 7, 2019
f8790ff
Nothing to see here, compilation problems after merge
albertzaharovits Mar 7, 2019
0c870b8
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 8, 2019
d779c6a
Checkstyle
albertzaharovits Mar 8, 2019
530783f
revert change to message
albertzaharovits Mar 8, 2019
981fc99
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 11, 2019
b123c6d
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
jaymode Mar 13, 2019
752e934
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
jaymode Mar 13, 2019
a94a7e6
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
jaymode Mar 13, 2019
a6f2994
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 13, 2019
66acefe
Address Jay's feedback
albertzaharovits Mar 13, 2019
675b1bf
Rename createUserToken + javadoc
albertzaharovits Mar 13, 2019
011033e
Fix mock
albertzaharovits Mar 14, 2019
4d4ec0a
Checkstyle
albertzaharovits Mar 14, 2019
6a8cb69
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 14, 2019
615c5cb
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 14, 2019
2338818
Fix mock in TokenServiceTests
albertzaharovits Mar 15, 2019
1ad9531
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 15, 2019
b942f53
Renames
albertzaharovits Mar 15, 2019
e3769ce
Remove redundant null check
albertzaharovits Mar 15, 2019
e9b1c96
Removed redundant ParametrizedMessage
albertzaharovits Mar 15, 2019
dfe3915
Rework log messages to be explicit about the doc id
albertzaharovits Mar 15, 2019
a7139a8
RefreshTokenStatus
albertzaharovits Mar 16, 2019
a3a97bf
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 16, 2019
45cce17
Fix javadoc
albertzaharovits Mar 16, 2019
e726d04
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 17, 2019
7a672a8
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
bizybot Mar 19, 2019
5fca03d
Remove redundant field
albertzaharovits Mar 19, 2019
00ffa93
checkTokenDocumentForRefresh
albertzaharovits Mar 19, 2019
e8c9e77
Logger
albertzaharovits Mar 19, 2019
aadfade
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 19, 2019
5a17020
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 20, 2019
3326c32
UserToken#fromSourceMap IllegalStateException
albertzaharovits Mar 20, 2019
f2da703
throws IllegalStateException, DateTimeException
albertzaharovits Mar 20, 2019
6367aae
Fix RefreshToken null checks
albertzaharovits Mar 20, 2019
e6cf3fc
getKeyAsync Listener
albertzaharovits Mar 20, 2019
bbc5e7a
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
jaymode Mar 20, 2019
991ab1e
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 20, 2019
0d48726
Merge branch 'master' into refactor_token_service_3
albertzaharovits Mar 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ protected void doExecute(Task task, SamlAuthenticateRequest request, ActionListe
}
assert authentication != null : "authentication should never be null at this point";
final Map<String, Object> tokenMeta = (Map<String, Object>) result.getMetadata().get(SamlRealm.CONTEXT_TOKEN_DATA);
tokenService.createUserToken(authentication, originatingAuthentication,
ActionListener.wrap(tuple -> {
tokenService.createOAuth2Tokens(authentication, originatingAuthentication,
tokenMeta, true, ActionListener.wrap(tuple -> {
final String tokenString = tokenService.getAccessTokenAsString(tuple.v1());
final TimeValue expiresIn = tokenService.getExpirationDelay();
listener.onResponse(
new SamlAuthenticateResponse(authentication.getUser().principal(), tokenString, tuple.v2(), expiresIn));
}, listener::onFailure), tokenMeta, true);
}, listener::onFailure));
}, e -> {
logger.debug(() -> new ParameterizedMessage("SamlToken [{}] could not be authenticated", saml), e);
listener.onFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void findAndInvalidateTokens(SamlRealm realm, SamlLogoutRequestHandler.R
return;
}

tokenService.findActiveTokensForRealm(realm.name(), ActionListener.wrap(tokens -> {
tokenService.findActiveTokensForRealm(realm.name(), containsMetadata(tokenMetadata), ActionListener.wrap(tokens -> {
logger.debug("Found [{}] token pairs to invalidate for SAML metadata [{}]", tokens.size(), tokenMetadata);
if (tokens.isEmpty()) {
listener.onResponse(0);
Expand All @@ -101,7 +101,7 @@ private void findAndInvalidateTokens(SamlRealm realm, SamlLogoutRequestHandler.R
tokens.forEach(tuple -> invalidateTokenPair(tuple, groupedListener));
}
}, listener::onFailure
), containsMetadata(tokenMetadata));
));
}

private void invalidateTokenPair(Tuple<UserToken, String> tokenPair, ActionListener<TokensInvalidationResult> listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.elasticsearch.xpack.security.authc.saml.SamlUtils;
import org.opensaml.saml.saml2.core.LogoutRequest;

import java.io.IOException;
import java.util.Map;

/**
Expand Down Expand Up @@ -73,7 +72,7 @@ protected void doExecute(Task task, SamlLogoutRequest request, ActionListener<Sa
));
}, listener::onFailure
));
} catch (IOException | ElasticsearchException e) {
} catch (ElasticsearchException e) {
logger.debug("Internal exception during SAML logout", e);
listener.onFailure(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.elasticsearch.xpack.security.authc.AuthenticationService;
import org.elasticsearch.xpack.security.authc.TokenService;

import java.io.IOException;
import java.util.Collections;

/**
Expand Down Expand Up @@ -86,19 +85,15 @@ private void authenticateAndCreateToken(CreateTokenRequest request, ActionListen
}

private void createToken(CreateTokenRequest request, Authentication authentication, Authentication originatingAuth,
boolean includeRefreshToken, ActionListener<CreateTokenResponse> listener) {
try {
tokenService.createUserToken(authentication, originatingAuth, ActionListener.wrap(tuple -> {
final String tokenStr = tokenService.getAccessTokenAsString(tuple.v1());
final String scope = getResponseScopeValue(request.getScope());

final CreateTokenResponse response =
new CreateTokenResponse(tokenStr, tokenService.getExpirationDelay(), scope, tuple.v2());
listener.onResponse(response);
}, listener::onFailure), Collections.emptyMap(), includeRefreshToken);
} catch (IOException e) {
listener.onFailure(e);
}
boolean includeRefreshToken, ActionListener<CreateTokenResponse> listener) {
tokenService.createOAuth2Tokens(authentication, originatingAuth, Collections.emptyMap(), includeRefreshToken,
ActionListener.wrap(tuple -> {
final String tokenStr = tokenService.getAccessTokenAsString(tuple.v1());
final String scope = getResponseScopeValue(request.getScope());
final CreateTokenResponse response = new CreateTokenResponse(tokenStr, tokenService.getExpirationDelay(), scope,
tuple.v2());
listener.onResponse(response);
}, listener::onFailure));
}

static String getResponseScopeValue(String requestScope) {
Expand Down
Loading