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.client.security.service ;
29
30 import org.apache.commons.logging.Log ;
31 import org.apache.commons.logging.LogFactory ;
32
33 import java.rmi.RemoteException ;
34
35 import org.astrogrid.community.common.security.data.SecurityToken ;
36 import org.astrogrid.community.common.security.service.SecurityService ;
37
38 import org.astrogrid.community.client.service.CommunityServiceCoreDelegate ;
39
40 import org.astrogrid.community.common.exception.CommunityServiceException ;
41 import org.astrogrid.community.common.exception.CommunitySecurityException ;
42 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
43
44 /***
45 * The core delegate code for our SecurityService service.
46 * This acts as a wrapper for a SecurityService service, and handles any RemoteExceptions internally.
47 *
48 */
49 public class SecurityServiceCoreDelegate
50 extends CommunityServiceCoreDelegate
51 implements SecurityService, SecurityServiceDelegate
52 {
53 /***
54 * Our debug logger.
55 *
56 */
57 private static Log log = LogFactory.getLog(SecurityServiceCoreDelegate.class);
58
59 /***
60 * Public constructor.
61 *
62 */
63 public SecurityServiceCoreDelegate()
64 {
65 }
66
67 /***
68 * Our SecurityService service.
69 *
70 */
71 private SecurityService service = null ;
72
73 /***
74 * Get a reference to our SecurityService service.
75 *
76 */
77 protected SecurityService getSecurityService()
78 {
79 return this.service ;
80 }
81
82 /***
83 * Set our our SecurityService service.
84 *
85 */
86 protected void setSecurityService(SecurityService service)
87 {
88 this.setCommunityService(service) ;
89 this.service = service ;
90 }
91
92 /***
93 * Check an Account password.
94 * @param account The account ident.
95 * @param password The account password.
96 * @return A valid SecurityToken if the ident and password are valid.
97 * @throws CommunitySecurityException If the security check fails.
98 * @throws CommunityServiceException If there is an internal error in service.
99 * @throws CommunityIdentifierException If the account identifier is invalid.
100 *
101 */
102 public SecurityToken checkPassword(String account, String pass)
103 throws CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
104 {
105
106
107 if (null != this.service)
108 {
109
110
111 try {
112 return this.service.checkPassword(account, pass) ;
113 }
114
115
116 catch (RemoteException ouch)
117 {
118
119
120 serviceException(ouch) ;
121 securityException(ouch) ;
122 identifierException(ouch) ;
123
124
125 throw new CommunityServiceException(
126 "WebService call failed - " + ouch,
127 ouch
128 ) ;
129 }
130 }
131
132
133 else {
134 throw new CommunityServiceException(
135 "Service not initialised"
136 ) ;
137 }
138 }
139
140 /***
141 * Validate a SecurityToken.
142 * Validates a token, and creates a new tokens issued to the same account.
143 * @param token The token to validate.
144 * @return A new SecurityToken if the original was valid.
145 * @throws CommunitySecurityException If the security check fails.
146 * @throws CommunityServiceException If there is an internal error in service.
147 * @throws CommunityIdentifierException If the token is invalid.
148 * @todo This should make the original token invalid IF it has been used.
149 *
150 */
151 public SecurityToken checkToken(SecurityToken token)
152 throws CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
153 {
154
155
156 if (null != this.service)
157 {
158
159
160 try {
161 return this.service.checkToken(token) ;
162 }
163
164
165 catch (RemoteException ouch)
166 {
167
168
169 token.setStatus(SecurityToken.INVALID_TOKEN) ;
170
171
172 serviceException(ouch) ;
173 securityException(ouch) ;
174 identifierException(ouch) ;
175
176
177 throw new CommunityServiceException(
178 "WebService call failed - " + ouch,
179 ouch
180 ) ;
181 }
182 }
183
184
185 else {
186 throw new CommunityServiceException(
187 "Service not initialised"
188 ) ;
189 }
190 }
191
192 /***
193 * Split a SecurityToken.
194 * Validates a token, and then creates a new set of tokens issued to the same account.
195 * @throws CommunitySecurityException If the security check fails.
196 * @throws CommunityServiceException If there is an internal error in service.
197 * @throws CommunityIdentifierException If the token is invalid.
198 * @todo This should make the original token invalid
199 * @todo This should make the original token invalid IF it has been used.
200 *
201 */
202 public Object[] splitToken(SecurityToken token, int count)
203 throws CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
204 {
205
206
207 if (null != this.service)
208 {
209
210
211 try {
212 return this.service.splitToken(token, count) ;
213 }
214
215
216 catch (RemoteException ouch)
217 {
218
219
220 serviceException(ouch) ;
221 securityException(ouch) ;
222 identifierException(ouch) ;
223
224
225 throw new CommunityServiceException(
226 "WebService call failed - " + ouch,
227 ouch
228 ) ;
229 }
230 }
231
232
233 else {
234 throw new CommunityServiceException(
235 "Service not initialised"
236 ) ;
237 }
238 }
239 }