View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filemanager/client/src/java/org/astrogrid/filemanager/client/FileManagerClientFactory.java,v $</cvs:source>
3    * <cvs:author>$Author: clq2 $</cvs:author>
4    * <cvs:date>$Date: 2005/01/28 10:43:57 $</cvs:date>
5    * <cvs:version>$Revision: 1.2 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileManagerClientFactory.java,v $
8    *   Revision 1.2  2005/01/28 10:43:57  clq2
9    *   dave_dev_200501141257 (filemanager)
10   *
11   *   Revision 1.1.2.3  2005/01/25 08:01:15  dave
12   *   Added tests for FileManagerClientFactory ....
13   *
14   *   Revision 1.1.2.2  2005/01/23 06:16:10  dave
15   *   Changed tabs to spaces ...
16   *
17   *   Revision 1.1.2.1  2005/01/23 05:39:44  dave
18   *   Added initial implementation of FileManagerClient ...
19   *
20   * </cvs:log>
21   *
22   */
23  package org.astrogrid.filemanager.client ;
24  
25  import java.net.URL;
26  
27  import org.astrogrid.store.Ivorn;
28  
29  import org.astrogrid.community.common.security.data.SecurityToken;
30  
31  import org.astrogrid.community.resolver.CommunityTokenResolver;
32  import org.astrogrid.community.resolver.CommunityPasswordResolver;
33  
34  import org.astrogrid.filemanager.client.exception.FileManagerLoginException;
35  
36  /***
37   * A factory for instances of the FileManager client interface.
38   *
39   */
40  public class FileManagerClientFactory
41      {
42      /***
43       * Public constructor using the default Registry endpoint.
44       *
45       */
46      public FileManagerClientFactory()
47          {
48          this.registry = null;
49          //
50          // Create our resolvers.
51          tokenResolver = new CommunityTokenResolver();
52          loginResolver = new CommunityPasswordResolver();
53          }
54  
55      /***
56       * Public constructor using a specific Registry endpoint.
57       *
58       */
59      public FileManagerClientFactory(URL registry)
60          {
61          this.registry = registry;
62          //
63          // Create our resolvers.
64          tokenResolver = new CommunityTokenResolver(
65              this.registry
66              );
67          loginResolver = new CommunityPasswordResolver(
68              this.registry
69              );
70          }
71  
72      /***
73       * Our registry endpoint URL.
74       *
75       */
76      private URL registry ;
77  
78      /***
79       * Our Community token resolver.
80       *
81       */
82      private CommunityTokenResolver tokenResolver ;
83  
84      /***
85       * Our Community password resolver.
86       *
87       */
88      private CommunityPasswordResolver loginResolver ;
89  
90      /***
91       * Login to a Community account using acciunt the identifier and password.
92       * @param account  The Community account identifier.
93       * @param password The Community account password.
94       * @return A FileManagerClient authenticated using the account identifier and password.
95       * @throws FileManagerLoginException If the login fails.
96       *
97       */
98      public FileManagerClient login(Ivorn account, String password)
99          throws FileManagerLoginException
100         {
101         try {
102             //
103             // Validate the account and password.
104 // Add an Ivorn method to the community resolver.
105             SecurityToken token = loginResolver.checkPassword(
106                 account.toString(),
107                 password
108                 );
109             //
110             // Create a FileManagerClient with the new token.
111             return new FileManagerClientImpl(
112                 this.registry,
113                 token
114                 );
115             }
116         catch (Exception ouch)
117             {
118             throw new FileManagerLoginException(
119                 "Unable to login",
120                 ouch
121                 );
122             }
123         }
124 
125     /***
126      * Login with a security token.
127      * @param token A valid security token containing the account details and authentication.
128      * @return A FileManagerClient authenticated using the security token.
129      * @throws FileManagerLoginException If the unable to validate the token.
130      *
131      */
132     public FileManagerClient login(SecurityToken token)
133         throws FileManagerLoginException
134         {
135         try {
136             //
137             // Validate the security token.
138             token = tokenResolver.checkToken(token);
139             //
140             // Create a FileManagerClient with the new token.
141             return new FileManagerClientImpl(
142                 this.registry,
143                 token
144                 );
145             }
146         catch (Exception ouch)
147             {
148             throw new FileManagerLoginException(
149                 "Unable to validate token",
150                 ouch
151                 );
152             }
153         }
154 
155     /***
156      * Login anonymously.
157      * @return A FileManagerClient with no associated account.
158      *
159      */
160     public FileManagerClient login()
161         {
162         //
163         // Create a FileManagerClient with no authentication.
164         return new FileManagerClientImpl(
165             this.registry
166             );
167         }
168     }
169 
170