1
2
3
4
5
6
7
8
9
10
11
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.provider.token.DefaultTokenServices;
21 import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
22 import org.springframework.util.StringUtils;
23 import org.w3c.dom.Element;
24
25
26
27
28
29
30
31 public abstract class ProviderBeanDefinitionParser extends AbstractBeanDefinitionParser {
32
33 @Override
34 protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
35
36 String tokenServicesRef = element.getAttribute("token-services-ref");
37 String serializerRef = element.getAttribute("serialization-service-ref");
38
39 if (!StringUtils.hasText(tokenServicesRef)) {
40 tokenServicesRef = "oauth2TokenServices";
41 BeanDefinitionBuilder tokenServices = BeanDefinitionBuilder.rootBeanDefinition(DefaultTokenServices.class);
42 AbstractBeanDefinition tokenStore = BeanDefinitionBuilder.rootBeanDefinition(InMemoryTokenStore.class).getBeanDefinition();
43 tokenServices.addPropertyValue("tokenStore", tokenStore);
44 parserContext.getRegistry().registerBeanDefinition(tokenServicesRef, tokenServices.getBeanDefinition());
45 }
46
47 return parseEndpointAndReturnFilter(element, parserContext, tokenServicesRef, serializerRef);
48 }
49
50 protected abstract AbstractBeanDefinition parseEndpointAndReturnFilter(Element element, ParserContext parserContext,
51 String tokenServicesRef, String serializerRef);
52
53 }