View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/security/service/SecurityServiceResolver.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: SecurityServiceResolver.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.28.2  2004/06/17 15:17:30  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.3.28.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.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          // Initialise a default resolver.
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          // Initialise a resolver with the url.
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         // Check for null ivorn.
113         if (null == ivorn)
114             {
115             throw new CommunityIdentifierException(
116                 "Null identifier"
117                 ) ;
118             }
119         //
120         // Parse the ivorn and resolve it.
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         // Check for null parser.
146         if (null == parser)
147             {
148             throw new CommunityIdentifierException(
149                 "Null identifier"
150                 ) ;
151             }
152         //
153         // Check for a mock ivorn.
154         if (parser.isMock())
155             {
156             log.debug("Ivorn is mock.") ;
157             log.debug("Creating mock delegate.") ;
158             //
159             // Return a mock delegate.
160             return new SecurityServiceMockDelegate() ;
161             }
162         //
163         // If the ident is real.
164         else {
165             log.debug("Ivorn is real.") ;
166             log.debug("Resolving endpoint URL.") ;
167             //
168             // Lookup the endpoint in the registry.
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             // Return a new delegate
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     }