Skip to content

Commit 3bc1b7a

Browse files
committed
Simplify opaqueToken support
Remove scopes convenience method to alleviate potential confusion with the "scope" attribute. Issue gh-7827 Issue gh-7712
1 parent 689fc9d commit 3bc1b7a

File tree

5 files changed

+3
-48
lines changed

5 files changed

+3
-48
lines changed

samples/boot/oauth2resourceserver-opaque/src/test/java/sample/OAuth2ResourceServerControllerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void indexGreetsAuthenticatedUser() throws Exception {
5151

5252
@Test
5353
public void messageCanBeReadWithScopeMessageReadAuthority() throws Exception {
54-
this.mvc.perform(get("/message").with(opaqueToken().scopes("message:read")))
54+
this.mvc.perform(get("/message").with(opaqueToken().attributes(a -> a.put("scope", "message:read"))))
5555
.andExpect(content().string(is("secret message")));
5656

5757
this.mvc.perform(get("/message")
@@ -77,15 +77,15 @@ public void messageCanNotBeCreatedWithoutAnyScope() throws Exception {
7777
public void messageCanNotBeCreatedWithScopeMessageReadAuthority() throws Exception {
7878
this.mvc.perform(post("/message")
7979
.content("Hello message")
80-
.with(opaqueToken().scopes("message:read")))
80+
.with(opaqueToken().authorities(new SimpleGrantedAuthority("SCOPE_message:read"))))
8181
.andExpect(status().isForbidden());
8282
}
8383

8484
@Test
8585
public void messageCanBeCreatedWithScopeMessageWriteAuthority() throws Exception {
8686
this.mvc.perform(post("/message")
8787
.content("Hello message")
88-
.with(opaqueToken().scopes("message:write")))
88+
.with(opaqueToken().authorities(new SimpleGrantedAuthority("SCOPE_message:write"))))
8989
.andExpect(status().isOk())
9090
.andExpect(content().string(is("Message was created. Content: Hello message")));
9191
}

test/src/main/java/org/springframework/security/test/web/reactive/server/SecurityMockServerConfigurers.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,18 +590,6 @@ public OpaqueTokenMutator authorities(GrantedAuthority... authorities) {
590590
return this;
591591
}
592592

593-
/**
594-
* Use the provided scopes as the authorities in the resulting principal
595-
* @param scopes the scopes to use
596-
* @return the {@link OpaqueTokenMutator} for further configuration
597-
*/
598-
public OpaqueTokenMutator scopes(String... scopes) {
599-
Assert.notNull(scopes, "scopes cannot be null");
600-
this.authorities = () -> getAuthorities(Arrays.asList(scopes));
601-
this.principal = this::defaultPrincipal;
602-
return this;
603-
}
604-
605593
/**
606594
* Use the provided principal
607595
* @param principal the principal to use

test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,18 +1228,6 @@ public OpaqueTokenRequestPostProcessor authorities(GrantedAuthority... authoriti
12281228
return this;
12291229
}
12301230

1231-
/**
1232-
* Use the provided scopes as the authorities in the resulting principal
1233-
* @param scopes the scopes to use
1234-
* @return the {@link OpaqueTokenRequestPostProcessor} for further configuration
1235-
*/
1236-
public OpaqueTokenRequestPostProcessor scopes(String... scopes) {
1237-
Assert.notNull(scopes, "scopes cannot be null");
1238-
this.authorities = () -> getAuthorities(Arrays.asList(scopes));
1239-
this.principal = this::defaultPrincipal;
1240-
return this;
1241-
}
1242-
12431231
/**
12441232
* Use the provided principal
12451233
* @param principal the principal to use

test/src/test/java/org/springframework/security/test/web/reactive/server/SecurityMockServerConfigurerOpaqueTokenTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ public void mockOpaqueTokenWhenAuthoritiesThenBearerTokenAuthentication() {
9090
.containsOnly(this.authority1, this.authority2);
9191
}
9292

93-
@Test
94-
public void mockOpaqueTokenWhenScopesThenBearerTokenAuthentication() {
95-
this.client
96-
.mutateWith(mockOpaqueToken().scopes("scoped", "authorities"))
97-
.get()
98-
.exchange()
99-
.expectStatus().isOk();
100-
101-
SecurityContext context = securityContextController.removeSecurityContext();
102-
assertThat((List<GrantedAuthority>) context.getAuthentication().getAuthorities())
103-
.containsOnly(new SimpleGrantedAuthority("SCOPE_scoped"),
104-
new SimpleGrantedAuthority("SCOPE_authorities"));
105-
}
106-
10793
@Test
10894
public void mockOpaqueTokenWhenAttributesThenBearerTokenAuthentication() {
10995
String sub = new String("my-subject");

test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsOpaqueTokenTests.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ public void opaqueTokenWhenUsingDefaultsThenProducesDefaultAuthentication()
8989
.andExpect(status().isForbidden());
9090
}
9191

92-
@Test
93-
public void opaqueTokenWhenAuthoritiesSpecifiedThenGrantsAccess() throws Exception {
94-
this.mvc.perform(get("/admin/scopes")
95-
.with(opaqueToken().scopes("admin", "read")))
96-
.andExpect(content().string("[\"SCOPE_admin\",\"SCOPE_read\"]"));
97-
}
98-
9992
@Test
10093
public void opaqueTokenWhenAttributeSpecifiedThenUserHasAttribute() throws Exception {
10194
this.mvc.perform(get("/opaque-token/iss")

0 commit comments

Comments
 (0)