View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/client/src/java/org/astrogrid/community/client/security/service/SecurityServiceCoreDelegate.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.9 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: SecurityServiceCoreDelegate.java,v $
9    *   Revision 1.9  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.8.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.8  2004/06/18 13:45:19  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.7.32.3  2004/06/17 15:10:03  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.7.32.2  2004/06/17 13:38:58  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
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         // If we have a valid service reference.
107         if (null != this.service)
108             {
109             //
110             // Try calling the service method.
111             try {
112                 return this.service.checkPassword(account, pass) ;
113                 }
114             //
115             // Catch anything that went BANG.
116             catch (RemoteException ouch)
117                 {
118                 //
119                 // Try converting the Exception.
120                 serviceException(ouch) ;
121                 securityException(ouch) ;
122                 identifierException(ouch) ;
123                 //
124                 // If we get this far, then we don't know what it is.
125                 throw new CommunityServiceException(
126                     "WebService call failed - " + ouch,
127                     ouch
128                     ) ;
129                 }
130             }
131         //
132         // If we don't have a valid service.
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         // If we have a valid service reference.
156         if (null != this.service)
157             {
158             //
159             // Try calling the service method.
160             try {
161                 return this.service.checkToken(token) ;
162                 }
163             //
164             // Catch anything that went BANG.
165             catch (RemoteException ouch)
166                 {
167                 //
168                 // Set the token staus.
169                 token.setStatus(SecurityToken.INVALID_TOKEN) ;
170                 //
171                 // Try converting the Exception.
172                 serviceException(ouch) ;
173                 securityException(ouch) ;
174                 identifierException(ouch) ;
175                 //
176                 // If we get this far, then we don't know what it is.
177                 throw new CommunityServiceException(
178                     "WebService call failed - " + ouch,
179                     ouch
180                     ) ;
181                 }
182             }
183         //
184         // If we don't have a valid service.
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         // If we have a valid service reference.
207         if (null != this.service)
208             {
209             //
210             // Try calling the service method.
211             try {
212                 return this.service.splitToken(token, count) ;
213                 }
214             //
215             // Catch anything that went BANG.
216             catch (RemoteException ouch)
217                 {
218                 //
219                 // Try converting the Exception.
220                 serviceException(ouch) ;
221                 securityException(ouch) ;
222                 identifierException(ouch) ;
223                 //
224                 // If we get this far, then we don't know what it is.
225                 throw new CommunityServiceException(
226                     "WebService call failed - " + ouch,
227                     ouch
228                     ) ;
229                 }
230             }
231         //
232         // If we don't have a valid service.
233         else {
234             throw new CommunityServiceException(
235                 "Service not initialised"
236                 ) ;
237             }
238         }
239     }