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