Skip to content

Commit 3ff8255

Browse files
qavidjzheaux
authored andcommitted
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
1 parent b83a4c2 commit 3ff8255

File tree

19 files changed

+592
-256
lines changed

19 files changed

+592
-256
lines changed

etc/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<suppress files="OidcParameterNames\.java" checks="InterfaceIsType"/>
2828
<suppress files="BearerTokenErrorCodes\.java" checks="InterfaceIsType"/>
2929
<suppress files="OAuth2IntrospectionClaimNames\.java" checks="InterfaceIsType"/>
30+
<suppress files="OAuth2TokenIntrospectionClaimNames\.java" checks="InterfaceIsType"/>
3031
<suppress files="Saml2ErrorCodes\.java" checks="InterfaceIsType"/>
3132

3233
<!-- Method Visibility that we can't reduce -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright 2002-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.core;
18+
19+
import java.net.URL;
20+
import java.time.Instant;
21+
import java.util.List;
22+
23+
import org.springframework.lang.Nullable;
24+
25+
/**
26+
* A {@link ClaimAccessor} for the &quot;claims&quot; that may be contained in the
27+
* Introspection Response.
28+
*
29+
* @author David Kovac
30+
* @since 5.6
31+
* @see ClaimAccessor
32+
* @see OAuth2TokenIntrospectionClaimNames
33+
* @see <a target="_blank" href=
34+
* "https://tools.ietf.org/html/rfc7662#section-2.2">Introspection Response</a>
35+
*/
36+
public interface OAuth2TokenIntrospectionClaimAccessor extends ClaimAccessor {
37+
38+
/**
39+
* Returns the indicator {@code (active)} whether or not the token is currently active
40+
* @return the indicator whether or not the token is currently active
41+
*/
42+
default boolean isActive() {
43+
return Boolean.TRUE.equals(getClaimAsBoolean(OAuth2TokenIntrospectionClaimNames.ACTIVE));
44+
}
45+
46+
/**
47+
* Returns a human-readable identifier {@code (username)} for the resource owner that
48+
* authorized the token
49+
* @return a human-readable identifier for the resource owner that authorized the
50+
* token
51+
*/
52+
@Nullable
53+
default String getUsername() {
54+
return getClaimAsString(OAuth2TokenIntrospectionClaimNames.USERNAME);
55+
}
56+
57+
/**
58+
* Returns the client identifier {@code (client_id)} for the token
59+
* @return the client identifier for the token
60+
*/
61+
@Nullable
62+
default String getClientId() {
63+
return getClaimAsString(OAuth2TokenIntrospectionClaimNames.CLIENT_ID);
64+
}
65+
66+
/**
67+
* Returns the scopes {@code (scope)} associated with the token
68+
* @return the scopes associated with the token
69+
*/
70+
@Nullable
71+
default List<String> getScopes() {
72+
return getClaimAsStringList(OAuth2TokenIntrospectionClaimNames.SCOPE);
73+
}
74+
75+
/**
76+
* Returns the type of the token {@code (token_type)}, for example {@code bearer}.
77+
* @return the type of the token, for example {@code bearer}.
78+
*/
79+
@Nullable
80+
default String getTokenType() {
81+
return getClaimAsString(OAuth2TokenIntrospectionClaimNames.TOKEN_TYPE);
82+
}
83+
84+
/**
85+
* Returns a timestamp {@code (exp)} indicating when the token expires
86+
* @return a timestamp indicating when the token expires
87+
*/
88+
@Nullable
89+
default Instant getExpiresAt() {
90+
return getClaimAsInstant(OAuth2TokenIntrospectionClaimNames.EXP);
91+
}
92+
93+
/**
94+
* Returns a timestamp {@code (iat)} indicating when the token was issued
95+
* @return a timestamp indicating when the token was issued
96+
*/
97+
@Nullable
98+
default Instant getIssuedAt() {
99+
return getClaimAsInstant(OAuth2TokenIntrospectionClaimNames.IAT);
100+
}
101+
102+
/**
103+
* Returns a timestamp {@code (nbf)} indicating when the token is not to be used
104+
* before
105+
* @return a timestamp indicating when the token is not to be used before
106+
*/
107+
@Nullable
108+
default Instant getNotBefore() {
109+
return getClaimAsInstant(OAuth2TokenIntrospectionClaimNames.NBF);
110+
}
111+
112+
/**
113+
* Returns usually a machine-readable identifier {@code (sub)} of the resource owner
114+
* who authorized the token
115+
* @return usually a machine-readable identifier of the resource owner who authorized
116+
* the token
117+
*/
118+
@Nullable
119+
default String getSubject() {
120+
return getClaimAsString(OAuth2TokenIntrospectionClaimNames.SUB);
121+
}
122+
123+
/**
124+
* Returns the intended audience {@code (aud)} for the token
125+
* @return the intended audience for the token
126+
*/
127+
@Nullable
128+
default List<String> getAudience() {
129+
return getClaimAsStringList(OAuth2TokenIntrospectionClaimNames.AUD);
130+
}
131+
132+
/**
133+
* Returns the issuer {@code (iss)} of the token
134+
* @return the issuer of the token
135+
*/
136+
@Nullable
137+
default URL getIssuer() {
138+
return getClaimAsURL(OAuth2TokenIntrospectionClaimNames.ISS);
139+
}
140+
141+
/**
142+
* Returns the identifier {@code (jti)} for the token
143+
* @return the identifier for the token
144+
*/
145+
@Nullable
146+
default String getId() {
147+
return getClaimAsString(OAuth2TokenIntrospectionClaimNames.JTI);
148+
}
149+
150+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2002-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.core;
18+
19+
/**
20+
* The names of the &quot;Introspection Claims&quot; defined by an
21+
* <a target="_blank" href="https://tools.ietf.org/html/rfc7662#section-2.2">Introspection
22+
* Response</a>.
23+
*
24+
* @author Josh Cummings
25+
* @since 5.6
26+
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc7662#section-2.2">OAuth
27+
* 2.0 Token Introspection (RFC7662)</a>
28+
* @see <a target="_blank" href=
29+
* "https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#token-introspection-response">OAuth
30+
* Parameters (IANA)</a>
31+
*/
32+
public interface OAuth2TokenIntrospectionClaimNames {
33+
34+
/**
35+
* {@code active} - Indicator whether or not the token is currently active
36+
*/
37+
String ACTIVE = "active";
38+
39+
/**
40+
* {@code username} - A human-readable identifier for the resource owner that
41+
* authorized the token
42+
*/
43+
String USERNAME = "username";
44+
45+
/**
46+
* {@code client_id} - The Client identifier for the token
47+
*/
48+
String CLIENT_ID = "client_id";
49+
50+
/**
51+
* {@code scope} - The scopes for the token
52+
*/
53+
String SCOPE = "scope";
54+
55+
/**
56+
* {@code token_type} - The type of the token, for example {@code bearer}.
57+
*/
58+
String TOKEN_TYPE = "token_type";
59+
60+
/**
61+
* {@code exp} - A timestamp indicating when the token expires
62+
*/
63+
String EXP = "exp";
64+
65+
/**
66+
* {@code iat} - A timestamp indicating when the token was issued
67+
*/
68+
String IAT = "iat";
69+
70+
/**
71+
* {@code nbf} - A timestamp indicating when the token is not to be used before
72+
*/
73+
String NBF = "nbf";
74+
75+
/**
76+
* {@code sub} - Usually a machine-readable identifier of the resource owner who
77+
* authorized the token
78+
*/
79+
String SUB = "sub";
80+
81+
/**
82+
* {@code aud} - The intended audience for the token
83+
*/
84+
String AUD = "aud";
85+
86+
/**
87+
* {@code iss} - The issuer of the token
88+
*/
89+
String ISS = "iss";
90+
91+
/**
92+
* {@code jti} - The identifier for the token
93+
*/
94+
String JTI = "jti";
95+
96+
}

0 commit comments

Comments
 (0)