|
34 | 34 |
|
35 | 35 | @Local(value={UserAuthenticator.class}) |
36 | 36 | public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { |
37 | | - public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); |
38 | | - |
39 | | - @Inject private UserAccountDao _userAccountDao; |
40 | | - |
41 | | - @Override |
42 | | - public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) { |
43 | | - if (s_logger.isDebugEnabled()) { |
| 37 | + public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); |
| 38 | + |
| 39 | + @Inject private UserAccountDao _userAccountDao; |
| 40 | + |
| 41 | + @Override |
| 42 | + public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) { |
| 43 | + if (s_logger.isDebugEnabled()) { |
44 | 44 | s_logger.debug("Retrieving user: " + username); |
45 | 45 | } |
| 46 | + |
46 | 47 | UserAccount user = _userAccountDao.getUserAccount(username, domainId); |
47 | 48 | if (user == null) { |
48 | 49 | s_logger.debug("Unable to find user with " + username + " in domain " + domainId); |
49 | 50 | return false; |
50 | 51 | } |
51 | | - |
52 | | - |
53 | | - MessageDigest md5; |
54 | | - try { |
55 | | - md5 = MessageDigest.getInstance("MD5"); |
56 | | - } catch (NoSuchAlgorithmException e) { |
57 | | - throw new CloudRuntimeException("Error", e); |
58 | | - } |
59 | | - md5.reset(); |
60 | | - BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); |
61 | 52 |
|
62 | | - // make sure our MD5 hash value is 32 digits long... |
63 | | - StringBuffer sb = new StringBuffer(); |
64 | | - String pwStr = pwInt.toString(16); |
65 | | - int padding = 32 - pwStr.length(); |
66 | | - for (int i = 0; i < padding; i++) { |
67 | | - sb.append('0'); |
68 | | - } |
69 | | - sb.append(pwStr); |
70 | | - |
71 | | - |
72 | | - // Will: The MD5Authenticator is now a straight pass-through comparison of the |
73 | | - // the passwords because we will not assume that the password passed in has |
74 | | - // already been MD5 hashed. I am keeping the above code in case this requirement changes |
75 | | - // or people need examples of how to MD5 hash passwords in java. |
76 | | - if (!user.getPassword().equals(sb.toString())) { |
| 53 | + if (!user.getPassword().equals(password)) { |
77 | 54 | s_logger.debug("Password does not match"); |
78 | 55 | return false; |
79 | 56 | } |
80 | | - return true; |
81 | | - } |
| 57 | + return true; |
| 58 | + } |
82 | 59 |
|
83 | | - public boolean configure(String name, Map<String, Object> params) |
84 | | - throws ConfigurationException { |
85 | | - super.configure(name, params); |
86 | | - return true; |
87 | | - } |
| 60 | + public boolean configure(String name, Map<String, Object> params) |
| 61 | + throws ConfigurationException { |
| 62 | + super.configure(name, params); |
| 63 | + return true; |
| 64 | + } |
88 | 65 |
|
89 | | - @Override |
90 | | - public String encode(String password) { |
91 | | - // Plaintext so no encoding at all |
92 | | - return password; |
93 | | - } |
| 66 | + @Override |
| 67 | + public String encode(String password) { |
| 68 | + // Plaintext so no encoding at all |
| 69 | + return password; |
| 70 | + } |
94 | 71 | } |
0 commit comments