01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.authentication;
04:
05: import java.util.*;
06:
07: public class MultiUserAuthenticator extends Authenticator {
08: private Map users = new HashMap();
09:
10: private PasswordCipher cipher;
11:
12: public MultiUserAuthenticator(String passwdFile) throws Exception {
13: PasswordFile passwords = new PasswordFile(passwdFile);
14: users = passwords.getPasswordMap();
15: cipher = passwords.getCipher();
16: }
17:
18: public boolean isAuthenticated(String username, String password)
19: throws Exception {
20: if (username == null || password == null)
21: return false;
22:
23: String foundPassword = (String) users.get(username);
24: if (foundPassword == null)
25: return false;
26:
27: String encryptedPassword = cipher.encrypt(password);
28: return encryptedPassword.equals(foundPassword);
29: }
30:
31: public int userCount() {
32: return users.size();
33: }
34:
35: public String getPasswd(String user) {
36: return (String) users.get(user);
37: }
38: }
|