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 ;
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.community.common.security.data.SecurityToken ;
36
37 import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
38
39 import org.astrogrid.community.client.security.service.SecurityServiceDelegate ;
40 import org.astrogrid.community.resolver.security.service.SecurityServiceResolver ;
41
42 import org.astrogrid.registry.RegistryException;
43 import org.astrogrid.community.common.exception.CommunityServiceException ;
44 import org.astrogrid.community.common.exception.CommunitySecurityException ;
45 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
46 import org.astrogrid.community.resolver.exception.CommunityResolverException ;
47
48 /***
49 * A utility to resolve security tokens.
50 *
51 */
52 public class CommunityTokenResolver
53 {
54 /***
55 * Our debug logger.
56 *
57 */
58 private static Log log = LogFactory.getLog(CommunityTokenResolver.class);
59
60 /***
61 * Public constructor, using the default Registry service.
62 *
63 */
64 public CommunityTokenResolver()
65 {
66 resolver = new SecurityServiceResolver() ;
67 }
68
69 /***
70 * Public constructor, for a specific Registry service.
71 * @param registry The endpoint address for our RegistryDelegate.
72 *
73 */
74 public CommunityTokenResolver(URL registry)
75 {
76 resolver = new SecurityServiceResolver(registry) ;
77 }
78
79 /***
80 * Our SecurityServiceResolver resolver.
81 *
82 */
83 private SecurityServiceResolver resolver ;
84
85 /***
86 * Validate a SecurityToken.
87 * Validates a token, and creates a new token issued to the same account.
88 * @param token The token to validate.
89 * @return A new SecurityToken if the original was valid.
90 * @throws CommunitySecurityException If the security check fails.
91 * @throws CommunityServiceException If there is an internal error in service.
92 * @throws CommunityIdentifierException If the token is invalid.
93 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
94 * @throws RegistryException If the Registry is unable to resolve the identifier.
95 *
96 */
97 public SecurityToken checkToken(SecurityToken token)
98 throws RegistryException, CommunityResolverException, CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
99 {
100 log.debug("") ;
101 log.debug("----\"----") ;
102 log.debug("CommunityTokenResolver.checkToken()") ;
103 log.debug(" Token : " + token) ;
104
105
106 if (null == token)
107 {
108 throw new CommunityIdentifierException(
109 "Null token"
110 ) ;
111 }
112
113
114 if (null == token.getToken())
115 {
116 throw new CommunityIdentifierException(
117 "Null token value"
118 ) ;
119 }
120
121
122 CommunityIvornParser parser = new CommunityIvornParser(token.getToken()) ;
123
124
125 SecurityServiceDelegate delegate = resolver.resolve(parser) ;
126
127
128 return delegate.checkToken(
129 token
130 ) ;
131 }
132
133 /***
134 * Split a SecurityToken.
135 * Validates a token, and then creates a new set of tokens issued to the same account.
136 * @param token The token to validate.
137 * @param count The number of new tokens required.
138 * @return An array of new SecurityToken(s).
139 * @throws CommunitySecurityException If the security check fails.
140 * @throws CommunityServiceException If there is an internal error in service.
141 * @throws CommunityIdentifierException If the token is invalid.
142 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
143 * @throws RegistryException If the Registry is unable to resolve the identifier.
144 *
145 */
146 public Object[] splitToken(SecurityToken token, int count)
147 throws RegistryException, CommunityResolverException, CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
148 {
149 log.debug("") ;
150 log.debug("----\"----") ;
151 log.debug("CommunityTokenResolver.splitToken()") ;
152 log.debug(" Token : " + token) ;
153
154
155 if (null == token)
156 {
157 throw new CommunityIdentifierException(
158 "Null token"
159 ) ;
160 }
161
162
163 if (null == token.getToken())
164 {
165 throw new CommunityIdentifierException(
166 "Null token value"
167 ) ;
168 }
169
170
171 CommunityIvornParser parser = new CommunityIvornParser(token.getToken()) ;
172
173
174 SecurityServiceDelegate delegate = resolver.resolve(parser) ;
175
176
177 return delegate.splitToken(
178 token,
179 count
180 ) ;
181 }
182 }