16
16
17
17
package org .springframework .security .oauth2 .server .resource .introspection ;
18
18
19
- import static org .springframework .security .core .authority .AuthorityUtils .NO_AUTHORITIES ;
20
-
21
19
import java .io .Serializable ;
22
20
import java .util .Collection ;
23
- import java .util .Collections ;
24
21
import java .util .Map ;
25
22
26
23
import org .springframework .security .core .GrantedAuthority ;
24
+ import org .springframework .security .oauth2 .core .DefaultOAuth2AuthenticatedPrincipal ;
27
25
import org .springframework .security .oauth2 .core .OAuth2AuthenticatedPrincipal ;
28
- import org .springframework .util .Assert ;
29
26
30
27
/**
31
28
* A domain object that wraps the attributes of OAuth 2.0 Token Introspection.
36
33
*/
37
34
public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2AuthenticatedPrincipal ,
38
35
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 ;
42
37
43
38
/**
44
39
* Constructs an {@code OAuth2IntrospectionAuthenticatedPrincipal} using the provided parameters.
@@ -49,7 +44,7 @@ public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2Au
49
44
public OAuth2IntrospectionAuthenticatedPrincipal (Map <String , Object > attributes ,
50
45
Collection <GrantedAuthority > authorities ) {
51
46
52
- this ( null , attributes , authorities );
47
+ this . delegate = new DefaultOAuth2AuthenticatedPrincipal ( attributes , authorities );
53
48
}
54
49
55
50
/**
@@ -62,11 +57,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(Map<String, Object> attributes,
62
57
public OAuth2IntrospectionAuthenticatedPrincipal (String name , Map <String , Object > attributes ,
63
58
Collection <GrantedAuthority > authorities ) {
64
59
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 );
70
61
}
71
62
72
63
/**
@@ -76,7 +67,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(String name, Map<String, Object
76
67
*/
77
68
@ Override
78
69
public Map <String , Object > getAttributes () {
79
- return this .attributes ;
70
+ return this .delegate . getAttributes () ;
80
71
}
81
72
82
73
/**
@@ -87,15 +78,15 @@ public Map<String, Object> getAttributes() {
87
78
*/
88
79
@ Override
89
80
public Collection <? extends GrantedAuthority > getAuthorities () {
90
- return this .authorities ;
81
+ return this .delegate . getAuthorities () ;
91
82
}
92
83
93
84
/**
94
85
* {@inheritDoc}
95
86
*/
96
87
@ Override
97
88
public String getName () {
98
- return this .name ;
89
+ return this .delegate . getName () ;
99
90
}
100
91
101
92
/**
0 commit comments