Skip to content

Commit 46cfc16

Browse files
committed
Polish OAuth2IntrospectionAuthenticatedPrincipal
Removed some duplication by delegating to DefaultOAuth2AuthenticatedPrincipal. Issue gh-6489
1 parent a58278c commit 46cfc16

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

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

+7-16
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616

1717
package org.springframework.security.oauth2.server.resource.introspection;
1818

19-
import static org.springframework.security.core.authority.AuthorityUtils.NO_AUTHORITIES;
20-
2119
import java.io.Serializable;
2220
import java.util.Collection;
23-
import java.util.Collections;
2421
import java.util.Map;
2522

2623
import org.springframework.security.core.GrantedAuthority;
24+
import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
2725
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
28-
import org.springframework.util.Assert;
2926

3027
/**
3128
* A domain object that wraps the attributes of OAuth 2.0 Token Introspection.
@@ -36,9 +33,7 @@
3633
*/
3734
public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2AuthenticatedPrincipal,
3835
OAuth2IntrospectionClaimAccessor, Serializable {
39-
private final Map<String, Object> attributes;
40-
private final Collection<GrantedAuthority> authorities;
41-
private final String name;
36+
private final OAuth2AuthenticatedPrincipal delegate;
4237

4338
/**
4439
* Constructs an {@code OAuth2IntrospectionAuthenticatedPrincipal} using the provided parameters.
@@ -49,7 +44,7 @@ public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2Au
4944
public OAuth2IntrospectionAuthenticatedPrincipal(Map<String, Object> attributes,
5045
Collection<GrantedAuthority> authorities) {
5146

52-
this(null, attributes, authorities);
47+
this.delegate = new DefaultOAuth2AuthenticatedPrincipal(attributes, authorities);
5348
}
5449

5550
/**
@@ -62,11 +57,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(Map<String, Object> attributes,
6257
public OAuth2IntrospectionAuthenticatedPrincipal(String name, Map<String, Object> attributes,
6358
Collection<GrantedAuthority> authorities) {
6459

65-
Assert.notEmpty(attributes, "attributes cannot be empty");
66-
this.attributes = Collections.unmodifiableMap(attributes);
67-
this.authorities = authorities == null ?
68-
NO_AUTHORITIES : Collections.unmodifiableCollection(authorities);
69-
this.name = name == null ? getSubject() : name;
60+
this.delegate = new DefaultOAuth2AuthenticatedPrincipal(name, attributes, authorities);
7061
}
7162

7263
/**
@@ -76,7 +67,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(String name, Map<String, Object
7667
*/
7768
@Override
7869
public Map<String, Object> getAttributes() {
79-
return this.attributes;
70+
return this.delegate.getAttributes();
8071
}
8172

8273
/**
@@ -87,15 +78,15 @@ public Map<String, Object> getAttributes() {
8778
*/
8879
@Override
8980
public Collection<? extends GrantedAuthority> getAuthorities() {
90-
return this.authorities;
81+
return this.delegate.getAuthorities();
9182
}
9283

9384
/**
9485
* {@inheritDoc}
9586
*/
9687
@Override
9788
public String getName() {
98-
return this.name;
89+
return this.delegate.getName();
9990
}
10091

10192
/**

0 commit comments

Comments
 (0)