1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.surf;
20
21 import javax.servlet.http.HttpSession;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.springframework.extensions.surf.exception.ConnectorProviderException;
26 import org.springframework.extensions.surf.exception.ConnectorServiceException;
27 import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
28 import org.springframework.extensions.webscripts.connector.Connector;
29 import org.springframework.extensions.webscripts.connector.ConnectorProvider;
30 import org.springframework.extensions.webscripts.connector.ConnectorService;
31 import org.springframework.extensions.webscripts.connector.User;
32
33
34
35
36
37
38
39
40 public class WebFrameworkConnectorProvider implements ConnectorProvider
41 {
42 private static final Log logger = LogFactory.getLog(WebFrameworkConnectorProvider.class);
43
44 private ConnectorService connectorService;
45
46
47
48
49
50
51 public void setConnectorService(ConnectorService connectorService)
52 {
53 this.connectorService = connectorService;
54 }
55
56
57
58
59
60
61
62 public Connector provide(String endpoint) throws ConnectorProviderException
63 {
64 Connector conn = null;
65 RequestContext rc = ThreadLocalRequestContext.getRequestContext();
66
67 if (rc != null)
68 {
69 try
70 {
71
72 User user = rc.getUser();
73 if (user == null || rc.getCredentialVault() == null)
74 {
75 if (logger.isDebugEnabled())
76 logger.debug("No user was found, creating unauthenticated connector");
77
78
79 conn = connectorService.getConnector(endpoint);
80 }
81 else
82 {
83 if (logger.isDebugEnabled())
84 logger.debug("User '" + user.getId() + "' was found, creating authenticated connector");
85
86
87 HttpSession httpSession = rc.getRequest().getSession(true);
88 conn = connectorService.getConnector(endpoint, rc.getUserId(), httpSession);
89 }
90 }
91 catch (ConnectorServiceException cse)
92 {
93 throw new ConnectorProviderException("Unable to provision connector for endpoint: " + endpoint, cse);
94 }
95 }
96 else
97 {
98
99 try
100 {
101 conn = connectorService.getConnector(endpoint);
102 }
103 catch (ConnectorServiceException cse)
104 {
105 throw new ConnectorProviderException("Unable to provision non-credential'd connector for endpoint: " + endpoint, cse);
106 }
107 }
108
109 return conn;
110 }
111 }