1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49:
50: import ;
51:
52:
55: public class SRPAuthInfoProvider
56: implements IAuthInfoProvider
57: {
58: private PasswordFile passwordFile = null;
59:
60:
61:
62: public void activate(Map context) throws AuthenticationException
63: {
64: try
65: {
66: if (context == null)
67: passwordFile = new PasswordFile();
68: else
69: {
70: passwordFile = (PasswordFile) context.get(SRPRegistry.PASSWORD_DB);
71: if (passwordFile == null)
72: {
73: String pfn = (String) context.get(SRPRegistry.PASSWORD_FILE);
74: if (pfn == null)
75: passwordFile = new PasswordFile();
76: else
77: passwordFile = new PasswordFile(pfn);
78: }
79: }
80: }
81: catch (IOException x)
82: {
83: throw new AuthenticationException("activate()", x);
84: }
85: }
86:
87: public void passivate() throws AuthenticationException
88: {
89: passwordFile = null;
90: }
91:
92: public boolean contains(String userName) throws AuthenticationException
93: {
94: if (passwordFile == null)
95: throw new AuthenticationException("contains()",
96: new IllegalStateException());
97: boolean result = false;
98: try
99: {
100: result = passwordFile.contains(userName);
101: }
102: catch (IOException x)
103: {
104: throw new AuthenticationException("contains()", x);
105: }
106: return result;
107: }
108:
109: public Map lookup(Map userID) throws AuthenticationException
110: {
111: if (passwordFile == null)
112: throw new AuthenticationException("lookup()", new IllegalStateException());
113: Map result = new HashMap();
114: try
115: {
116: String userName = (String) userID.get(Registry.SASL_USERNAME);
117: if (userName == null)
118: throw new NoSuchUserException("");
119: String mdName = (String) userID.get(SRPRegistry.MD_NAME_FIELD);
120: String[] data = passwordFile.lookup(userName, mdName);
121: result.put(SRPRegistry.USER_VERIFIER_FIELD, data[0]);
122: result.put(SRPRegistry.SALT_FIELD, data[1]);
123: result.put(SRPRegistry.CONFIG_NDX_FIELD, data[2]);
124: }
125: catch (Exception x)
126: {
127: if (x instanceof AuthenticationException)
128: throw (AuthenticationException) x;
129: throw new AuthenticationException("lookup()", x);
130: }
131: return result;
132: }
133:
134: public void update(Map userCredentials) throws AuthenticationException
135: {
136: if (passwordFile == null)
137: throw new AuthenticationException("update()", new IllegalStateException());
138: try
139: {
140: String userName = (String) userCredentials.get(Registry.SASL_USERNAME);
141: String password = (String) userCredentials.get(Registry.SASL_PASSWORD);
142: String salt = (String) userCredentials.get(SRPRegistry.SALT_FIELD);
143: String config = (String) userCredentials.get(SRPRegistry.CONFIG_NDX_FIELD);
144: if (salt == null || config == null)
145: passwordFile.changePasswd(userName, password);
146: else
147: passwordFile.add(userName, password, Util.fromBase64(salt), config);
148: }
149: catch (Exception x)
150: {
151: if (x instanceof AuthenticationException)
152: throw (AuthenticationException) x;
153: throw new AuthenticationException("update()", x);
154: }
155: }
156:
157: public Map getConfiguration(String mode) throws AuthenticationException
158: {
159: if (passwordFile == null)
160: throw new AuthenticationException("getConfiguration()",
161: new IllegalStateException());
162: Map result = new HashMap();
163: try
164: {
165: String[] data = passwordFile.lookupConfig(mode);
166: result.put(SRPRegistry.SHARED_MODULUS, data[0]);
167: result.put(SRPRegistry.FIELD_GENERATOR, data[1]);
168: }
169: catch (Exception x)
170: {
171: if (x instanceof AuthenticationException)
172: throw (AuthenticationException) x;
173: throw new AuthenticationException("getConfiguration()", x);
174: }
175: return result;
176: }
177: }