Move and rename OAuth2IntrospectionClaimAccessor/Names
Introduced OAuth2TokenIntrospectionClaimAccessor and OAuth2TokenIntrospectionClaimNames with copied implementation from OAuth2IntrospectionClaimAccessor/Names. OAuth2IntrospectionClaimAccessor and OAuth2IntrospectionClaimNames are now deprecated. Also method getScopes() returning list of scopes was introduced and getScope() is now deprecated. Closes gh-9647
This commit is contained in:
committed by
Josh Cummings
parent
b83a4c2985
commit
3ff825576b
+4
-4
@@ -56,6 +56,7 @@ import org.springframework.security.oauth2.client.web.server.WebSessionServerOAu
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
||||
import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
@@ -71,7 +72,6 @@ import org.springframework.security.oauth2.server.resource.authentication.Bearer
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
|
||||
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal;
|
||||
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionClaimNames;
|
||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
||||
import org.springframework.security.web.server.csrf.CsrfWebFilter;
|
||||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
||||
@@ -648,14 +648,14 @@ public final class SecurityMockServerConfigurers {
|
||||
|
||||
private Map<String, Object> defaultAttributes() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put(OAuth2IntrospectionClaimNames.SUBJECT, "user");
|
||||
attributes.put(OAuth2IntrospectionClaimNames.SCOPE, "read");
|
||||
attributes.put(OAuth2TokenIntrospectionClaimNames.SUB, "user");
|
||||
attributes.put(OAuth2TokenIntrospectionClaimNames.SCOPE, "read");
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private Collection<GrantedAuthority> defaultAuthorities() {
|
||||
Map<String, Object> attributes = this.attributes.get();
|
||||
Object scope = attributes.get(OAuth2IntrospectionClaimNames.SCOPE);
|
||||
Object scope = attributes.get(OAuth2TokenIntrospectionClaimNames.SCOPE);
|
||||
if (scope == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,6 +70,7 @@ import org.springframework.security.oauth2.client.web.method.annotation.OAuth2Au
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
||||
import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
@@ -85,7 +86,6 @@ import org.springframework.security.oauth2.server.resource.authentication.Bearer
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
|
||||
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal;
|
||||
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionClaimNames;
|
||||
import org.springframework.security.test.context.TestSecurityContextHolder;
|
||||
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
|
||||
import org.springframework.security.test.web.support.WebTestUtils;
|
||||
@@ -1191,14 +1191,14 @@ public final class SecurityMockMvcRequestPostProcessors {
|
||||
|
||||
private Map<String, Object> defaultAttributes() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put(OAuth2IntrospectionClaimNames.SUBJECT, "user");
|
||||
attributes.put(OAuth2IntrospectionClaimNames.SCOPE, "read");
|
||||
attributes.put(OAuth2TokenIntrospectionClaimNames.SUB, "user");
|
||||
attributes.put(OAuth2TokenIntrospectionClaimNames.SCOPE, "read");
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private Collection<GrantedAuthority> defaultAuthorities() {
|
||||
Map<String, Object> attributes = this.attributes.get();
|
||||
Object scope = attributes.get(OAuth2IntrospectionClaimNames.SCOPE);
|
||||
Object scope = attributes.get(OAuth2TokenIntrospectionClaimNames.SCOPE);
|
||||
if (scope == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,9 +29,9 @@ import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
||||
import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames;
|
||||
import org.springframework.security.oauth2.core.TestOAuth2AuthenticatedPrincipals;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
|
||||
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionClaimNames;
|
||||
import org.springframework.security.web.reactive.result.method.annotation.CurrentSecurityContextArgumentResolver;
|
||||
import org.springframework.security.web.server.context.SecurityContextServerWebExchangeWebFilter;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@@ -64,7 +64,7 @@ public class SecurityMockServerConfigurerOpaqueTokenTests extends AbstractMockSe
|
||||
BearerTokenAuthentication token = (BearerTokenAuthentication) context.getAuthentication();
|
||||
assertThat(token.getAuthorities()).isNotEmpty();
|
||||
assertThat(token.getToken()).isNotNull();
|
||||
assertThat(token.getTokenAttributes().get(OAuth2IntrospectionClaimNames.SUBJECT)).isEqualTo("user");
|
||||
assertThat(token.getTokenAttributes().get(OAuth2TokenIntrospectionClaimNames.SUB)).isEqualTo("user");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,12 +83,12 @@ public class SecurityMockServerConfigurerOpaqueTokenTests extends AbstractMockSe
|
||||
String sub = new String("my-subject");
|
||||
this.client
|
||||
.mutateWith(SecurityMockServerConfigurers.mockOpaqueToken()
|
||||
.attributes((attributes) -> attributes.put(OAuth2IntrospectionClaimNames.SUBJECT, sub)))
|
||||
.attributes((attributes) -> attributes.put(OAuth2TokenIntrospectionClaimNames.SUB, sub)))
|
||||
.get().exchange().expectStatus().isOk();
|
||||
SecurityContext context = this.securityContextController.removeSecurityContext();
|
||||
assertThat(context.getAuthentication()).isInstanceOf(BearerTokenAuthentication.class);
|
||||
BearerTokenAuthentication token = (BearerTokenAuthentication) context.getAuthentication();
|
||||
assertThat(token.getTokenAttributes().get(OAuth2IntrospectionClaimNames.SUBJECT)).isSameAs(sub);
|
||||
assertThat(token.getTokenAttributes().get(OAuth2TokenIntrospectionClaimNames.SUB)).isSameAs(sub);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,23 +108,23 @@ public class SecurityMockServerConfigurerOpaqueTokenTests extends AbstractMockSe
|
||||
.active((a) -> a.put("scope", "user"));
|
||||
this.client
|
||||
.mutateWith(SecurityMockServerConfigurers.mockOpaqueToken()
|
||||
.attributes((a) -> a.put(OAuth2IntrospectionClaimNames.SUBJECT, "foo")).principal(principal))
|
||||
.attributes((a) -> a.put(OAuth2TokenIntrospectionClaimNames.SUB, "foo")).principal(principal))
|
||||
.get().exchange().expectStatus().isOk();
|
||||
SecurityContext context = this.securityContextController.removeSecurityContext();
|
||||
assertThat(context.getAuthentication()).isInstanceOf(BearerTokenAuthentication.class);
|
||||
BearerTokenAuthentication token = (BearerTokenAuthentication) context.getAuthentication();
|
||||
assertThat((String) ((OAuth2AuthenticatedPrincipal) token.getPrincipal())
|
||||
.getAttribute(OAuth2IntrospectionClaimNames.SUBJECT))
|
||||
.isEqualTo(principal.getAttribute(OAuth2IntrospectionClaimNames.SUBJECT));
|
||||
.getAttribute(OAuth2TokenIntrospectionClaimNames.SUB))
|
||||
.isEqualTo(principal.getAttribute(OAuth2TokenIntrospectionClaimNames.SUB));
|
||||
this.client
|
||||
.mutateWith(SecurityMockServerConfigurers.mockOpaqueToken().principal(principal)
|
||||
.attributes((a) -> a.put(OAuth2IntrospectionClaimNames.SUBJECT, "bar")))
|
||||
.attributes((a) -> a.put(OAuth2TokenIntrospectionClaimNames.SUB, "bar")))
|
||||
.get().exchange().expectStatus().isOk();
|
||||
context = this.securityContextController.removeSecurityContext();
|
||||
assertThat(context.getAuthentication()).isInstanceOf(BearerTokenAuthentication.class);
|
||||
token = (BearerTokenAuthentication) context.getAuthentication();
|
||||
assertThat((String) ((OAuth2AuthenticatedPrincipal) token.getPrincipal())
|
||||
.getAttribute(OAuth2IntrospectionClaimNames.SUBJECT)).isEqualTo("bar");
|
||||
.getAttribute(OAuth2TokenIntrospectionClaimNames.SUB)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user