View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/CommunityTokenResolver.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.5 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityTokenResolver.java,v $
9    *   Revision 1.5  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.4.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.4  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.3.32.2  2004/06/17 15:17:30  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.3.32.1  2004/06/17 13:38:59  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
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         // Check for null param.
106         if (null == token)
107             {
108             throw new CommunityIdentifierException(
109                 "Null token"
110                 ) ;
111             }
112         //
113         // Check for null value.
114         if (null == token.getToken())
115             {
116             throw new CommunityIdentifierException(
117                 "Null token value"
118                 ) ;
119             }
120         //
121         // Parse the token value into an ivorn.
122         CommunityIvornParser parser = new CommunityIvornParser(token.getToken()) ;
123         //
124         // Resolve the ivorn into a SecurityServiceDelegate.
125         SecurityServiceDelegate delegate = resolver.resolve(parser) ;
126         //
127         // Ask the SecurityServiceDelegate to check the token.
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         // Check for null param.
155         if (null == token)
156             {
157             throw new CommunityIdentifierException(
158                 "Null token"
159                 ) ;
160             }
161         //
162         // Check for null value.
163         if (null == token.getToken())
164             {
165             throw new CommunityIdentifierException(
166                 "Null token value"
167                 ) ;
168             }
169         //
170         // Parse the token value into an ivorn.
171         CommunityIvornParser parser = new CommunityIvornParser(token.getToken()) ;
172         //
173         // Resolve the ivorn into a SecurityServiceDelegate.
174         SecurityServiceDelegate delegate = resolver.resolve(parser) ;
175         //
176         // Ask the SecurityServiceDelegate to split the token.
177         return delegate.splitToken(
178             token,
179             count
180             ) ;
181         }
182     }