1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.springframework.security.oauth2.config.xml;
16
17 import org.springframework.beans.factory.FactoryBean;
18 import org.springframework.security.oauth2.client.OAuth2ClientContext;
19 import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
20 import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
21
22
23
24
25
26
27
28
29
30 public class OAuth2ClientContextFactoryBean implements FactoryBean<OAuth2ClientContext> {
31
32 private OAuth2ProtectedResourceDetails resource;
33
34 private OAuth2ClientContext bareContext;
35
36 private OAuth2ClientContext scopedContext;
37
38
39
40
41 public void setResource(OAuth2ProtectedResourceDetails resource) {
42 this.resource = resource;
43 }
44
45
46
47
48 public void setScopedContext(OAuth2ClientContext scopedContext) {
49 this.scopedContext = scopedContext;
50 }
51
52
53
54
55 public void setBareContext(OAuth2ClientContext bareContext) {
56 this.bareContext = bareContext;
57 }
58
59 public OAuth2ClientContext getObject() throws Exception {
60 if (resource instanceof ClientCredentialsResourceDetails) {
61 return bareContext;
62 }
63 return scopedContext;
64 }
65
66 public Class<?> getObjectType() {
67 return OAuth2ClientContext.class;
68 }
69
70 public boolean isSingleton() {
71 return true;
72 }
73
74 }