|
| 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.io.Serializable; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Collections; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +import org.springframework.security.authentication.AbstractAuthenticationToken; |
| 25 | +import org.springframework.security.core.Authentication; |
| 26 | +import org.springframework.util.Assert; |
| 27 | + |
| 28 | +/** |
| 29 | + * @author Steve Riesenberg |
| 30 | + */ |
| 31 | +public class OAuth2CompositeAuthenticationToken extends AbstractAuthenticationToken implements Serializable { |
| 32 | + |
| 33 | + private final Authentication subject; |
| 34 | + |
| 35 | + private final List<Authentication> actors; |
| 36 | + |
| 37 | + public OAuth2CompositeAuthenticationToken(Authentication subject, List<Authentication> actors) { |
| 38 | + super(subject.getAuthorities()); |
| 39 | + Assert.notNull(subject, "subject cannot be null"); |
| 40 | + Assert.notNull(actors, "actors cannot be null"); |
| 41 | + this.subject = subject; |
| 42 | + this.actors = Collections.unmodifiableList(new ArrayList<>(actors)); |
| 43 | + setDetails(subject.getDetails()); |
| 44 | + setAuthenticated(subject.isAuthenticated()); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Object getPrincipal() { |
| 49 | + return this.subject.getPrincipal(); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Object getCredentials() { |
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + public Authentication getSubject() { |
| 58 | + return this.subject; |
| 59 | + } |
| 60 | + |
| 61 | + public List<Authentication> getActors() { |
| 62 | + return this.actors; |
| 63 | + } |
| 64 | +} |
0 commit comments