|
| 1 | +/* |
| 2 | + * Copyright 2002-2020 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.server.resource.introspection; |
| 18 | + |
| 19 | +import java.net.URL; |
| 20 | +import java.time.Instant; |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | +import org.springframework.security.oauth2.core.ClaimAccessor; |
| 24 | + |
| 25 | +/** |
| 26 | + * A {@link ClaimAccessor} for the "claims" that may be contained |
| 27 | + * in the Introspection Response. |
| 28 | + * |
| 29 | + * @author David Kovac |
| 30 | + * @since 5.4 |
| 31 | + * @see ClaimAccessor |
| 32 | + * @see OAuth2IntrospectionClaimNames |
| 33 | + * @see OAuth2IntrospectionAuthenticatedPrincipal |
| 34 | + * @see <a target="_blank" href="https://tools.ietf.org/html/rfc7662#section-2.2">Introspection Response</a> |
| 35 | + */ |
| 36 | +public interface OAuth2IntrospectionClaimAccessor extends ClaimAccessor { |
| 37 | + /** |
| 38 | + * Returns the indicator {@code (active)} whether or not the token is currently active |
| 39 | + * |
| 40 | + * @return the indicator whether or not the token is currently active |
| 41 | + */ |
| 42 | + default boolean isActive() { |
| 43 | + return Boolean.TRUE.equals(this.getClaimAsBoolean(OAuth2IntrospectionClaimNames.ACTIVE)); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Returns the scopes {@code (scope)} associated with the token |
| 48 | + * |
| 49 | + * @return the scopes associated with the token |
| 50 | + */ |
| 51 | + default String getScope() { |
| 52 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.SCOPE); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the client identifier {@code (client_id)} for the token |
| 57 | + * |
| 58 | + * @return the client identifier for the token |
| 59 | + */ |
| 60 | + default String getClientId() { |
| 61 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.CLIENT_ID); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Returns a human-readable identifier {@code (username)} for the resource owner that authorized the token |
| 66 | + * |
| 67 | + * @return a human-readable identifier for the resource owner that authorized the token |
| 68 | + */ |
| 69 | + default String getUsername() { |
| 70 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.USERNAME); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the type of the token {@code (token_type)}, for example {@code bearer}. |
| 75 | + * |
| 76 | + * @return the type of the token, for example {@code bearer}. |
| 77 | + */ |
| 78 | + default String getTokenType() { |
| 79 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.TOKEN_TYPE); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns a timestamp {@code (exp)} indicating when the token expires |
| 84 | + * |
| 85 | + * @return a timestamp indicating when the token expires |
| 86 | + */ |
| 87 | + default Instant getExpiresAt() { |
| 88 | + return this.getClaimAsInstant(OAuth2IntrospectionClaimNames.EXPIRES_AT); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Returns a timestamp {@code (iat)} indicating when the token was issued |
| 93 | + * |
| 94 | + * @return a timestamp indicating when the token was issued |
| 95 | + */ |
| 96 | + default Instant getIssuedAt() { |
| 97 | + return this.getClaimAsInstant(OAuth2IntrospectionClaimNames.ISSUED_AT); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Returns a timestamp {@code (nbf)} indicating when the token is not to be used before |
| 102 | + * |
| 103 | + * @return a timestamp indicating when the token is not to be used before |
| 104 | + */ |
| 105 | + default Instant getNotBefore() { |
| 106 | + return this.getClaimAsInstant(OAuth2IntrospectionClaimNames.NOT_BEFORE); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Returns usually a machine-readable identifier {@code (sub)} of the resource owner who authorized the token |
| 111 | + * |
| 112 | + * @return usually a machine-readable identifier of the resource owner who authorized the token |
| 113 | + */ |
| 114 | + default String getSubject() { |
| 115 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.SUBJECT); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Returns the intended audience {@code (aud)} for the token |
| 120 | + * |
| 121 | + * @return the intended audience for the token |
| 122 | + */ |
| 123 | + default List<String> getAudience() { |
| 124 | + return this.getClaimAsStringList(OAuth2IntrospectionClaimNames.AUDIENCE); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Returns the issuer {@code (iss)} of the token |
| 129 | + * |
| 130 | + * @return the issuer of the token |
| 131 | + */ |
| 132 | + default URL getIssuer() { |
| 133 | + return this.getClaimAsURL(OAuth2IntrospectionClaimNames.ISSUER); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Returns the identifier {@code (jti)} for the token |
| 138 | + * |
| 139 | + * @return the identifier for the token |
| 140 | + */ |
| 141 | + default String getId() { |
| 142 | + return this.getClaimAsString(OAuth2IntrospectionClaimNames.JTI); |
| 143 | + } |
| 144 | +} |
0 commit comments