Skip to content

Commit b54a95e

Browse files
committed
Revert "Support concurrent refresh of refresh tokens (#38382)"
This reverts commit 21703fe.
1 parent b199968 commit b54a95e

12 files changed

Lines changed: 299 additions & 704 deletions

File tree

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.core.security.authc.support;
88

99
import org.elasticsearch.ElasticsearchException;
10-
import org.elasticsearch.Version;
1110
import org.elasticsearch.common.Nullable;
1211
import org.elasticsearch.common.io.stream.StreamInput;
1312
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -33,9 +32,10 @@ public class TokensInvalidationResult implements ToXContentObject, Writeable {
3332
private final List<String> invalidatedTokens;
3433
private final List<String> previouslyInvalidatedTokens;
3534
private final List<ElasticsearchException> errors;
35+
private final int attemptCount;
3636

3737
public TokensInvalidationResult(List<String> invalidatedTokens, List<String> previouslyInvalidatedTokens,
38-
@Nullable List<ElasticsearchException> errors) {
38+
@Nullable List<ElasticsearchException> errors, int attemptCount) {
3939
Objects.requireNonNull(invalidatedTokens, "invalidated_tokens must be provided");
4040
this.invalidatedTokens = invalidatedTokens;
4141
Objects.requireNonNull(previouslyInvalidatedTokens, "previously_invalidated_tokens must be provided");
@@ -45,19 +45,18 @@ public TokensInvalidationResult(List<String> invalidatedTokens, List<String> pre
4545
} else {
4646
this.errors = Collections.emptyList();
4747
}
48+
this.attemptCount = attemptCount;
4849
}
4950

5051
public TokensInvalidationResult(StreamInput in) throws IOException {
5152
this.invalidatedTokens = in.readStringList();
5253
this.previouslyInvalidatedTokens = in.readStringList();
5354
this.errors = in.readList(StreamInput::readException);
54-
if (in.getVersion().before(Version.V_8_0_0)) {
55-
in.readVInt();
56-
}
55+
this.attemptCount = in.readVInt();
5756
}
5857

5958
public static TokensInvalidationResult emptyResult() {
60-
return new TokensInvalidationResult(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
59+
return new TokensInvalidationResult(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), 0);
6160
}
6261

6362

@@ -73,6 +72,10 @@ public List<ElasticsearchException> getErrors() {
7372
return errors;
7473
}
7574

75+
public int getAttemptCount() {
76+
return attemptCount;
77+
}
78+
7679
@Override
7780
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
7881
builder.startObject()
@@ -97,8 +100,6 @@ public void writeTo(StreamOutput out) throws IOException {
97100
out.writeStringCollection(invalidatedTokens);
98101
out.writeStringCollection(previouslyInvalidatedTokens);
99102
out.writeCollection(errors, StreamOutput::writeException);
100-
if (out.getVersion().before(Version.V_8_0_0)) {
101-
out.writeVInt(5);
102-
}
103+
out.writeVInt(attemptCount);
103104
}
104105
}

x-pack/plugin/core/src/main/resources/security-index-template.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,6 @@
199199
"refreshed" : {
200200
"type" : "boolean"
201201
},
202-
"refresh_time": {
203-
"type": "date",
204-
"format": "epoch_millis"
205-
},
206-
"superseded_by": {
207-
"type": "keyword"
208-
},
209202
"invalidated" : {
210203
"type" : "boolean"
211204
},

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenResponseTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public void testSerialization() throws IOException {
2929
TokensInvalidationResult result = new TokensInvalidationResult(Arrays.asList(generateRandomStringArray(20, 15, false)),
3030
Arrays.asList(generateRandomStringArray(20, 15, false)),
3131
Arrays.asList(new ElasticsearchException("foo", new IllegalArgumentException("this is an error message")),
32-
new ElasticsearchException("bar", new IllegalArgumentException("this is an error message2"))));
32+
new ElasticsearchException("bar", new IllegalArgumentException("this is an error message2"))),
33+
randomIntBetween(0, 5));
3334
InvalidateTokenResponse response = new InvalidateTokenResponse(result);
3435
try (BytesStreamOutput output = new BytesStreamOutput()) {
3536
response.writeTo(output);
@@ -46,7 +47,8 @@ public void testSerialization() throws IOException {
4647
}
4748

4849
result = new TokensInvalidationResult(Arrays.asList(generateRandomStringArray(20, 15, false)),
49-
Arrays.asList(generateRandomStringArray(20, 15, false)), Collections.emptyList());
50+
Arrays.asList(generateRandomStringArray(20, 15, false)),
51+
Collections.emptyList(), randomIntBetween(0, 5));
5052
response = new InvalidateTokenResponse(result);
5153
try (BytesStreamOutput output = new BytesStreamOutput()) {
5254
response.writeTo(output);
@@ -66,7 +68,8 @@ public void testToXContent() throws IOException {
6668
List previouslyInvalidatedTokens = Arrays.asList(generateRandomStringArray(20, 15, false));
6769
TokensInvalidationResult result = new TokensInvalidationResult(invalidatedTokens, previouslyInvalidatedTokens,
6870
Arrays.asList(new ElasticsearchException("foo", new IllegalArgumentException("this is an error message")),
69-
new ElasticsearchException("bar", new IllegalArgumentException("this is an error message2"))));
71+
new ElasticsearchException("bar", new IllegalArgumentException("this is an error message2"))),
72+
randomIntBetween(0, 5));
7073
InvalidateTokenResponse response = new InvalidateTokenResponse(result);
7174
XContentBuilder builder = XContentFactory.jsonBuilder();
7275
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/saml/TransportSamlAuthenticateAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected void doExecute(Task task, SamlAuthenticateRequest request, ActionListe
6363
final Map<String, Object> tokenMeta = (Map<String, Object>) result.getMetadata().get(SamlRealm.CONTEXT_TOKEN_DATA);
6464
tokenService.createUserToken(authentication, originatingAuthentication,
6565
ActionListener.wrap(tuple -> {
66-
final String tokenString = tokenService.getAccessTokenAsString(tuple.v1());
66+
final String tokenString = tokenService.getUserTokenString(tuple.v1());
6767
final TimeValue expiresIn = tokenService.getExpirationDelay();
6868
listener.onResponse(
6969
new SamlAuthenticateResponse(authentication.getUser().principal(), tokenString, tuple.v2(), expiresIn));

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/token/TransportCreateTokenAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void createToken(CreateTokenRequest request, Authentication authenticati
8989
boolean includeRefreshToken, ActionListener<CreateTokenResponse> listener) {
9090
try {
9191
tokenService.createUserToken(authentication, originatingAuth, ActionListener.wrap(tuple -> {
92-
final String tokenStr = tokenService.getAccessTokenAsString(tuple.v1());
92+
final String tokenStr = tokenService.getUserTokenString(tuple.v1());
9393
final String scope = getResponseScopeValue(request.getScope());
9494

9595
final CreateTokenResponse response =

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/token/TransportRefreshTokenAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public TransportRefreshTokenAction(TransportService transportService, ActionFilt
3131
@Override
3232
protected void doExecute(Task task, CreateTokenRequest request, ActionListener<CreateTokenResponse> listener) {
3333
tokenService.refreshToken(request.getRefreshToken(), ActionListener.wrap(tuple -> {
34-
final String tokenStr = tokenService.getAccessTokenAsString(tuple.v1());
34+
final String tokenStr = tokenService.getUserTokenString(tuple.v1());
3535
final String scope = getResponseScopeValue(request.getScope());
3636

3737
final CreateTokenResponse response =

0 commit comments

Comments
 (0)