1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
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
104
105 SecurityToken token = loginResolver.checkPassword(
106 account.toString(),
107 password
108 );
109
110
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
138 token = tokenResolver.checkToken(token);
139
140
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
164 return new FileManagerClientImpl(
165 this.registry
166 );
167 }
168 }
169
170