|
| 1 | +/* |
| 2 | + * Copyright 2020-2024 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.authorization.authentication; |
| 18 | + |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.Map; |
| 21 | +import java.util.Objects; |
| 22 | + |
| 23 | +import org.springframework.security.oauth2.core.ClaimAccessor; |
| 24 | +import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenClaimNames; |
| 25 | +import org.springframework.util.Assert; |
| 26 | + |
| 27 | +/** |
| 28 | + * A {@link ClaimAccessor} used for the OAuth 2.0 Token Exchange Grant to represent an actor in a |
| 29 | + * {@link OAuth2TokenExchangeCompositeAuthenticationToken} (e.g. the "delegation" use case). |
| 30 | + * |
| 31 | + * @author Steve Riesenberg |
| 32 | + * @since 1.3 |
| 33 | + * @see OAuth2TokenExchangeCompositeAuthenticationToken |
| 34 | + */ |
| 35 | +public final class OAuth2TokenExchangeActor implements ClaimAccessor { |
| 36 | + |
| 37 | + private final Map<String, Object> claims; |
| 38 | + |
| 39 | + public OAuth2TokenExchangeActor(Map<String, Object> claims) { |
| 40 | + Assert.notNull(claims, "claims cannot be null"); |
| 41 | + this.claims = Collections.unmodifiableMap(claims); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public Map<String, Object> getClaims() { |
| 46 | + return this.claims; |
| 47 | + } |
| 48 | + |
| 49 | + public String getIssuer() { |
| 50 | + return getClaimAsString(OAuth2TokenClaimNames.ISS); |
| 51 | + } |
| 52 | + |
| 53 | + public String getSubject() { |
| 54 | + return getClaimAsString(OAuth2TokenClaimNames.SUB); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public boolean equals(Object obj) { |
| 59 | + if (!(obj instanceof OAuth2TokenExchangeActor other)) { |
| 60 | + return false; |
| 61 | + } |
| 62 | + return Objects.equals(this.claims, other.claims); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public int hashCode() { |
| 67 | + return Objects.hash(this.claims); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments