View Javadoc
1   /*
2    * Copyright 2008-2009 Web Cohesion
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  
14  package org.springframework.security.oauth2.config.xml;
15  
16  import org.springframework.beans.factory.support.AbstractBeanDefinition;
17  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
18  import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
19  import org.springframework.beans.factory.xml.ParserContext;
20  import org.springframework.security.oauth2.client.OAuth2RestTemplate;
21  import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter;
22  import org.springframework.util.StringUtils;
23  import org.w3c.dom.Element;
24  
25  /**
26   * Parser for the OAuth "client" element supporting client apps using {@link OAuth2RestTemplate}.
27   * 
28   * @author Ryan Heaton
29   * @author Dave Syer
30   */
31  public class ClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
32  
33  	@Override
34  	protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
35  
36  		String redirectStrategyRef = element.getAttribute("redirect-strategy-ref");
37  
38  		BeanDefinitionBuilder clientContextFilterBean = BeanDefinitionBuilder
39  				.rootBeanDefinition(OAuth2ClientContextFilter.class);
40  
41  		if (StringUtils.hasText(redirectStrategyRef)) {
42  			clientContextFilterBean.addPropertyReference("redirectStrategy", redirectStrategyRef);
43  		}
44  
45  		return clientContextFilterBean.getBeanDefinition();
46  
47  	}
48  
49  }