1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 passwords into tokens.
50 *
51 */
52 public class CommunityPasswordResolver
53 {
54 /***
55 * Our debug logger.
56 *
57 */
58 private static Log log = LogFactory.getLog(CommunityPasswordResolver.class);
59
60 /***
61 * Public constructor, using the default Registry service.
62 *
63 */
64 public CommunityPasswordResolver()
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 CommunityPasswordResolver(URL registry)
75 {
76 resolver = new SecurityServiceResolver(registry) ;
77 }
78
79 /***
80 * Our SecurityServiceResolver resolver.
81 *
82 */
83 private SecurityServiceResolver resolver ;
84
85 /***
86 * Check an Account password.
87 * @param account The account ident.
88 * @param password The account password.
89 * @return A valid SecurityToken if the ident and password are 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 account identifier 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 checkPassword(String account, String password)
98 throws RegistryException, CommunityResolverException, CommunityServiceException, CommunitySecurityException, CommunityIdentifierException
99 {
100 log.debug("") ;
101 log.debug("----\"----") ;
102 log.debug("CommunityPasswordResolver.checkPassword()") ;
103 log.debug(" Account : " + account) ;
104
105
106 if (null == account)
107 {
108 throw new CommunityIdentifierException(
109 "Null account"
110 ) ;
111 }
112
113
114 CommunityIvornParser parser = new CommunityIvornParser(account) ;
115
116
117 SecurityServiceDelegate delegate = resolver.resolve(parser) ;
118
119
120 return delegate.checkPassword(
121 account,
122 password
123 ) ;
124 }
125 }