Skip to content

Commit 14e71ef

Browse files
Update javadoc
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
1 parent dd8cf97 commit 14e71ef

File tree

4 files changed

+36
-87
lines changed

4 files changed

+36
-87
lines changed

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospector.java

+12-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.net.URI;
2121
import java.net.URLEncoder;
2222
import java.nio.charset.Charset;
23+
import java.nio.charset.StandardCharsets;
2324
import java.time.Instant;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -79,8 +80,8 @@ public class SpringOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
7980
/**
8081
* Creates a {@code OpaqueTokenAuthenticationProvider} with the provided parameters
8182
* @param introspectionUri The introspection endpoint uri
82-
* @param clientId The client id authorized to introspect
83-
* @param clientSecret The client's secret
83+
* @param clientId The URL-encoded client id authorized to introspect
84+
* @param clientSecret The URL-encoded client secret authorized to introspect
8485
* @deprecated Please use {@link SpringOpaqueTokenIntrospector.Builder}
8586
*/
8687
@Deprecated(since = "6.5", forRemoval = true)
@@ -330,54 +331,28 @@ private Builder(String introspectionUri) {
330331
}
331332

332333
/**
333-
* Uses the given parameters to build {@code SpringOpaqueTokenIntrospector}
334-
* @param clientId The client id authorized that should be encoded
335-
* @param charset The charset to use
336-
* @return the {@link SpringOpaqueTokenIntrospector.Builder}
337-
* @since 6.5
338-
*/
339-
public Builder clientId(String clientId, Charset charset) {
340-
Assert.notNull(clientId, "clientId cannot be null");
341-
Assert.notNull(charset, "charset cannot be null");
342-
this.clientId = URLEncoder.encode(clientId, charset);
343-
return this;
344-
}
345-
346-
/**
347-
* Uses the given parameter to build {@code SpringOpaqueTokenIntrospector}
348-
* @param clientId The client id authorized
334+
* The builder will {@link URLEncoder encode} the client id that you provide, so
335+
* please give the unencoded value.
336+
* @param clientId The unencoded client id
349337
* @return the {@link SpringOpaqueTokenIntrospector.Builder}
350338
* @since 6.5
351339
*/
352340
public Builder clientId(String clientId) {
353341
Assert.notNull(clientId, "clientId cannot be null");
354-
this.clientId = clientId;
355-
return this;
356-
}
357-
358-
/**
359-
* Uses the given parameters to build {@code SpringOpaqueTokenIntrospector}
360-
* @param clientSecret The client's secret that should be encoded
361-
* @param charset The charset to use
362-
* @return the {@link SpringOpaqueTokenIntrospector.Builder}
363-
* @since 6.5
364-
*/
365-
public Builder clientSecret(String clientSecret, Charset charset) {
366-
Assert.notNull(clientSecret, "clientSecret cannot be null");
367-
Assert.notNull(charset, "charset cannot be null");
368-
this.clientSecret = URLEncoder.encode(clientSecret, charset);
342+
this.clientId = URLEncoder.encode(clientId, StandardCharsets.UTF_8);
369343
return this;
370344
}
371345

372346
/**
373-
* Uses the given parameter to build {@code SpringOpaqueTokenIntrospector}
374-
* @param clientSecret The client's secret
347+
* The builder will {@link URLEncoder encode} the client secret that you provide,
348+
* so please give the unencoded value.
349+
* @param clientSecret The unencoded client secret
375350
* @return the {@link SpringOpaqueTokenIntrospector.Builder}
376351
* @since 6.5
377352
*/
378353
public Builder clientSecret(String clientSecret) {
379354
Assert.notNull(clientSecret, "clientSecret cannot be null");
380-
this.clientSecret = clientSecret;
355+
this.clientSecret = URLEncoder.encode(clientSecret, StandardCharsets.UTF_8);
381356
return this;
382357
}
383358

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospector.java

+12-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import java.io.Serial;
2020
import java.net.URI;
2121
import java.net.URLEncoder;
22-
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2323
import java.time.Instant;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
@@ -74,8 +74,8 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
7474
* Creates a {@code OpaqueTokenReactiveAuthenticationManager} with the provided
7575
* parameters
7676
* @param introspectionUri The introspection endpoint uri
77-
* @param clientId The client id authorized to introspect
78-
* @param clientSecret The client secret for the authorized client
77+
* @param clientId The URL-encoded client id authorized to introspect
78+
* @param clientSecret The URL-encoded client secret authorized to introspect
7979
* @deprecated Please use {@link SpringReactiveOpaqueTokenIntrospector.Builder}
8080
*/
8181
@Deprecated(since = "6.5", forRemoval = true)
@@ -284,54 +284,28 @@ private Builder(String introspectionUri) {
284284
}
285285

286286
/**
287-
* Uses the given parameters to build {@code SpringOpaqueTokenIntrospector}
288-
* @param clientId The client id authorized that should be encoded
289-
* @param charset The charset to use
290-
* @return the {@link SpringReactiveOpaqueTokenIntrospector.Builder}
291-
* @since 6.5
292-
*/
293-
public Builder clientId(String clientId, Charset charset) {
294-
Assert.notNull(clientId, "clientId cannot be null");
295-
Assert.notNull(charset, "charset cannot be null");
296-
this.clientId = URLEncoder.encode(clientId, charset);
297-
return this;
298-
}
299-
300-
/**
301-
* Uses the given parameter to build {@code SpringOpaqueTokenIntrospector}
302-
* @param clientId The client id authorized
287+
* The builder will {@link URLEncoder encode} the client id that you provide, so
288+
* please give the unencoded value.
289+
* @param clientId The unencoded client id
303290
* @return the {@link SpringReactiveOpaqueTokenIntrospector.Builder}
304291
* @since 6.5
305292
*/
306293
public Builder clientId(String clientId) {
307294
Assert.notNull(clientId, "clientId cannot be null");
308-
this.clientId = clientId;
309-
return this;
310-
}
311-
312-
/**
313-
* Uses the given parameters to build {@code SpringOpaqueTokenIntrospector}
314-
* @param clientSecret The client's secret that should be encoded
315-
* @param charset The charset to use
316-
* @return the {@link SpringReactiveOpaqueTokenIntrospector.Builder}
317-
* @since 6.5
318-
*/
319-
public Builder clientSecret(String clientSecret, Charset charset) {
320-
Assert.notNull(clientSecret, "clientSecret cannot be null");
321-
Assert.notNull(charset, "charset cannot be null");
322-
this.clientSecret = URLEncoder.encode(clientSecret, charset);
295+
this.clientId = URLEncoder.encode(clientId, StandardCharsets.UTF_8);
323296
return this;
324297
}
325298

326299
/**
327-
* Uses the given parameter to build {@code SpringOpaqueTokenIntrospector}
328-
* @param clientSecret The client's secret
300+
* The builder will {@link URLEncoder encode} the client secret that you provide,
301+
* so please give the unencoded value.
302+
* @param clientSecret The unencoded client secret
329303
* @return the {@link SpringReactiveOpaqueTokenIntrospector.Builder}
330304
* @since 6.5
331305
*/
332306
public Builder clientSecret(String clientSecret) {
333307
Assert.notNull(clientSecret, "clientSecret cannot be null");
334-
this.clientSecret = clientSecret;
308+
this.clientSecret = URLEncoder.encode(clientSecret, StandardCharsets.UTF_8);
335309
return this;
336310
}
337311

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospectorTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -364,22 +364,22 @@ public void introspectWithEncodeClientCredentialsThenOk() throws Exception {
364364
String response = """
365365
{
366366
"active": true,
367-
"username": "client%&1"
367+
"username": "client&1"
368368
}
369369
""";
370-
server.setDispatcher(requiresAuth("client%25%261", "secret%40%242", response));
370+
server.setDispatcher(requiresAuth("client%261", "secret%40%242", response));
371371
String introspectUri = server.url("/introspect").toString();
372372
OpaqueTokenIntrospector introspectionClient = SpringOpaqueTokenIntrospector
373373
.withIntrospectionUri(introspectUri)
374-
.clientId("client%&1", StandardCharsets.UTF_8)
375-
.clientSecret("secret@$2", StandardCharsets.UTF_8)
374+
.clientId("client&1")
375+
.clientSecret("secret@$2")
376376
.build();
377377
OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token");
378378
// @formatter:off
379379
assertThat(authority.getAttributes())
380380
.isNotNull()
381381
.containsEntry(OAuth2TokenIntrospectionClaimNames.ACTIVE, true)
382-
.containsEntry(OAuth2TokenIntrospectionClaimNames.USERNAME, "client%&1");
382+
.containsEntry(OAuth2TokenIntrospectionClaimNames.USERNAME, "client&1");
383383
// @formatter:on
384384
}
385385
}

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospectorTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -288,22 +288,22 @@ public void introspectWithEncodeClientCredentialsThenOk() throws Exception {
288288
String response = """
289289
{
290290
"active": true,
291-
"username": "client%&1"
291+
"username": "client&1"
292292
}
293293
""";
294-
server.setDispatcher(requiresAuth("client%25%261", "secret%40%242", response));
294+
server.setDispatcher(requiresAuth("client%261", "secret%40%242", response));
295295
String introspectUri = server.url("/introspect").toString();
296296
ReactiveOpaqueTokenIntrospector introspectionClient = SpringReactiveOpaqueTokenIntrospector
297297
.withIntrospectionUri(introspectUri)
298-
.clientId("client%&1", StandardCharsets.UTF_8)
299-
.clientSecret("secret@$2", StandardCharsets.UTF_8)
298+
.clientId("client&1")
299+
.clientSecret("secret@$2")
300300
.build();
301301
OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token").block();
302302
// @formatter:off
303303
assertThat(authority.getAttributes())
304304
.isNotNull()
305305
.containsEntry(OAuth2TokenIntrospectionClaimNames.ACTIVE, true)
306-
.containsEntry(OAuth2TokenIntrospectionClaimNames.USERNAME, "client%&1");
306+
.containsEntry(OAuth2TokenIntrospectionClaimNames.USERNAME, "client&1");
307307
// @formatter:on
308308
}
309309
}

0 commit comments

Comments
 (0)