1 /* 2 * Copyright 2006-2011 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 * the License. You may obtain a copy of the License at 6 * 7 * https://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 * specific language governing permissions and limitations under the License. 12 */ 13 package org.springframework.security.oauth2.provider.token; 14 15 import java.util.Collections; 16 import java.util.List; 17 18 import org.springframework.security.oauth2.common.OAuth2AccessToken; 19 import org.springframework.security.oauth2.provider.OAuth2Authentication; 20 21 /** 22 * A composite token enhancer that loops over its delegate enhancers. 23 * 24 * @author Dave Syer 25 * 26 */ 27 public class TokenEnhancerChain implements TokenEnhancer { 28 29 private List<TokenEnhancer> delegates = Collections.emptyList(); 30 31 /** 32 * @param delegates the delegates to set 33 */ 34 public void setTokenEnhancers(List<TokenEnhancer> delegates) { 35 this.delegates = delegates; 36 } 37 38 /** 39 * Loop over the {@link #setTokenEnhancers(List) delegates} passing the result into the next member of the chain. 40 * 41 * @see org.springframework.security.oauth2.provider.token.TokenEnhancer#enhance(org.springframework.security.oauth2.common.OAuth2AccessToken, 42 * org.springframework.security.oauth2.provider.OAuth2Authentication) 43 */ 44 public OAuth2AccessToken../../../org/springframework/security/oauth2/common/OAuth2AccessToken.html#OAuth2AccessToken">OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { 45 OAuth2AccessToken result = accessToken; 46 for (TokenEnhancer enhancer : delegates) { 47 result = enhancer.enhance(result, authentication); 48 } 49 return result; 50 } 51 52 }