1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.astrogrid.community.resolver.security.service ;
29
30 import org.apache.commons.logging.Log ;
31 import org.apache.commons.logging.LogFactory ;
32
33 import java.net.URL ;
34
35 import org.astrogrid.store.Ivorn ;
36
37 import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
38
39 import org.astrogrid.community.common.security.service.SecurityService ;
40
41 import org.astrogrid.community.client.security.service.SecurityServiceDelegate ;
42 import org.astrogrid.community.client.security.service.SecurityServiceMockDelegate ;
43 import org.astrogrid.community.client.security.service.SecurityServiceSoapDelegate ;
44
45 import org.astrogrid.community.resolver.CommunityEndpointResolver ;
46
47 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
48 import org.astrogrid.community.resolver.exception.CommunityResolverException ;
49
50 import org.astrogrid.registry.RegistryException;
51
52 /***
53 * A toolkit to resolve an Ivorn identifier into a SecurityServiceResolver delegate.
54 *
55 */
56 public class SecurityServiceResolver
57 {
58 /***
59 * Our debug logger.
60 *
61 */
62 private static Log log = LogFactory.getLog(SecurityServiceResolver.class);
63
64 /***
65 * Public constructor, using the default Registry service.
66 *
67 */
68 public SecurityServiceResolver()
69 {
70
71
72 resolver = new CommunityEndpointResolver() ;
73 }
74
75 /***
76 * Public constructor, for a specific Registry service.
77 * @param registry The endpoint address for our RegistryDelegate.
78 *
79 */
80 public SecurityServiceResolver(URL registry)
81 {
82
83
84 resolver = new CommunityEndpointResolver(registry) ;
85 }
86
87 /***
88 * Our endpoint resolver.
89 *
90 */
91 private CommunityEndpointResolver resolver ;
92
93 /***
94 * Resolve an Ivorn identifier into a SecurityServiceDelegate.
95 * If the Ivorn matches the MOCK_IVORN, this will return a SecurityServiceMockDelegate.
96 * If the Ivorn is a valid identifier, then this will lookup the identifier in the registry.
97 * @param ident The service identifier.
98 * @return A new SecurityServiceDelegate.
99 * @throws CommunityIdentifierException If the identifier is not valid.
100 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
101 * @throws RegistryException If the Registry is unable to resolve the identifier.
102 *
103 */
104 public SecurityServiceDelegate resolve(Ivorn ivorn)
105 throws RegistryException, CommunityIdentifierException, CommunityResolverException
106 {
107 log.debug("") ;
108 log.debug("----\"----") ;
109 log.debug("SecurityServiceResolver.resolve()") ;
110 log.debug(" Ivorn : " + ((null != ivorn) ? ivorn : null)) ;
111
112
113 if (null == ivorn)
114 {
115 throw new CommunityIdentifierException(
116 "Null identifier"
117 ) ;
118 }
119
120
121 return this.resolve(
122 new CommunityIvornParser(ivorn)
123 ) ;
124 }
125
126 /***
127 * Resolve data from a CommunityIvornParser into a SecurityServiceDelegate.
128 * If the Ivorn matches the MOCK_IVORN, this will return a SecurityServiceMockDelegate.
129 * If the Ivorn is a valid identifier, then this will lookup the identifier in the registry.
130 * @param parser The service identifier.
131 * @return A new SecurityServiceDelegate.
132 * @throws CommunityIdentifierException If the identifier is not valid.
133 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
134 * @throws RegistryException If the Registry is unable to resolve the identifier.
135 *
136 */
137 public SecurityServiceDelegate resolve(CommunityIvornParser parser)
138 throws RegistryException, CommunityIdentifierException, CommunityResolverException
139 {
140 log.debug("") ;
141 log.debug("----\"----") ;
142 log.debug("SecurityServiceResolver.resolve()") ;
143 log.debug(" Ivorn : " + ((null != parser) ? parser.getIvorn() : null)) ;
144
145
146 if (null == parser)
147 {
148 throw new CommunityIdentifierException(
149 "Null identifier"
150 ) ;
151 }
152
153
154 if (parser.isMock())
155 {
156 log.debug("Ivorn is mock.") ;
157 log.debug("Creating mock delegate.") ;
158
159
160 return new SecurityServiceMockDelegate() ;
161 }
162
163
164 else {
165 log.debug("Ivorn is real.") ;
166 log.debug("Resolving endpoint URL.") ;
167
168
169 URL endpoint = resolver.resolve(parser, SecurityService.class) ;
170 log.debug("PASS : Got endpoint url") ;
171 log.debug(" URL : " + endpoint) ;
172 log.debug("Creating SOAP delegate.") ;
173
174
175 return this.resolve(endpoint) ;
176 }
177 }
178
179 /***
180 * Resolve a WebService endpoint into a SecurityServiceDelegate.
181 * @param url The SecurityService endpoint URL.
182 * @return A new SecurityServiceDelegate.
183 *
184 */
185 protected SecurityServiceDelegate resolve(URL url)
186 {
187 return new SecurityServiceSoapDelegate(url) ;
188 }
189 }