Skip to content

Commit 3dc916a

Browse files
Kishan Kavalachipchilders
authored andcommitted
CLOUDSTACK-2516: Added PlainText to Authenticator list for backward compatibility
1 parent 2fdeee4 commit 3dc916a

3 files changed

Lines changed: 25 additions & 44 deletions

File tree

‎client/tomcatconf/applicationContext.xml.in‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
<bean id="LDAPUserAuthenticator" class="com.cloud.server.auth.LDAPUserAuthenticator">
372372
<property name="name" value="LDAP"/>
373373
</bean>
374+
<bean id="PlainTextUserAuthenticator" class="com.cloud.server.auth.PlainTextUserAuthenticator">
375+
<property name="name" value="PLAINTEXT"/>
376+
</bean>
374377

375378
<!--
376379
Network Elements

‎client/tomcatconf/componentContext.xml.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<list>
7373
<ref bean="MD5UserAuthenticator"/>
7474
<ref bean="LDAPUserAuthenticator"/>
75+
<ref bean="PlainTextUserAuthenticator"/>
7576
</list>
7677
</property>
7778
</bean>

‎plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java‎

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,38 @@
3434

3535
@Local(value={UserAuthenticator.class})
3636
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()) {
4444
s_logger.debug("Retrieving user: " + username);
4545
}
46+
4647
UserAccount user = _userAccountDao.getUserAccount(username, domainId);
4748
if (user == null) {
4849
s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
4950
return false;
5051
}
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()));
6152

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)) {
7754
s_logger.debug("Password does not match");
7855
return false;
7956
}
80-
return true;
81-
}
57+
return true;
58+
}
8259

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+
}
8865

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+
}
9471
}

0 commit comments

Comments
 (0)