|
1 | | -// Copyright 2012 Citrix Systems, Inc. Licensed under the |
2 | | -// Apache License, Version 2.0 (the "License"); you may not use this |
3 | | -// file except in compliance with the License. Citrix Systems, Inc. |
4 | | -// reserves all rights not expressly granted by the License. |
5 | | -// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
6 | | -// Unless required by applicable law or agreed to in writing, software |
7 | | -// distributed under the License is distributed on an "AS IS" BASIS, |
8 | | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | -// See the License for the specific language governing permissions and |
10 | | -// limitations under the License. |
11 | | -// |
12 | | -// Automatically generated by addcopyright.py at 04/03/2012 |
13 | | -package com.cloud.server.auth; |
14 | | - |
15 | | -import java.math.BigInteger; |
16 | | -import java.security.MessageDigest; |
17 | | -import java.security.NoSuchAlgorithmException; |
18 | | -import java.util.Map; |
19 | | - |
20 | | -import javax.ejb.Local; |
21 | | -import javax.naming.ConfigurationException; |
22 | | - |
23 | | -import org.apache.log4j.Logger; |
24 | | - |
25 | | -import com.cloud.server.ManagementServer; |
26 | | -import com.cloud.user.UserAccount; |
27 | | -import com.cloud.user.dao.UserAccountDao; |
28 | | -import com.cloud.utils.component.ComponentLocator; |
29 | | -import com.cloud.utils.exception.CloudRuntimeException; |
30 | | - |
31 | | - |
32 | | -@Local(value={UserAuthenticator.class}) |
33 | | -public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { |
34 | | - public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); |
35 | | - |
36 | | - private UserAccountDao _userAccountDao; |
37 | | - |
38 | | - @Override |
39 | | - public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) { |
40 | | - if (s_logger.isDebugEnabled()) { |
41 | | - s_logger.debug("Retrieving user: " + username); |
42 | | - } |
43 | | - UserAccount user = _userAccountDao.getUserAccount(username, domainId); |
44 | | - if (user == null) { |
45 | | - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); |
46 | | - return false; |
47 | | - } |
48 | | - |
49 | | - |
50 | | - MessageDigest md5; |
51 | | - try { |
52 | | - md5 = MessageDigest.getInstance("MD5"); |
53 | | - } catch (NoSuchAlgorithmException e) { |
54 | | - throw new CloudRuntimeException("Error", e); |
55 | | - } |
56 | | - md5.reset(); |
57 | | - BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); |
58 | | - |
59 | | - // make sure our MD5 hash value is 32 digits long... |
60 | | - StringBuffer sb = new StringBuffer(); |
61 | | - String pwStr = pwInt.toString(16); |
62 | | - int padding = 32 - pwStr.length(); |
63 | | - for (int i = 0; i < padding; i++) { |
64 | | - sb.append('0'); |
65 | | - } |
66 | | - sb.append(pwStr); |
67 | | - |
68 | | - |
69 | | - // Will: The MD5Authenticator is now a straight pass-through comparison of the |
70 | | - // the passwords because we will not assume that the password passed in has |
71 | | - // already been MD5 hashed. I am keeping the above code in case this requirement changes |
72 | | - // or people need examples of how to MD5 hash passwords in java. |
73 | | - if (!user.getPassword().equals(sb.toString())) { |
74 | | - s_logger.debug("Password does not match"); |
75 | | - return false; |
76 | | - } |
77 | | - return true; |
78 | | - } |
79 | | - |
80 | | - public boolean configure(String name, Map<String, Object> params) |
81 | | - throws ConfigurationException { |
82 | | - super.configure(name, params); |
83 | | - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); |
84 | | - _userAccountDao = locator.getDao(UserAccountDao.class); |
85 | | - return true; |
86 | | - } |
87 | | -} |
| 1 | +// Copyright 2012 Citrix Systems, Inc. Licensed under the |
| 2 | +// Apache License, Version 2.0 (the "License"); you may not use this |
| 3 | +// file except in compliance with the License. Citrix Systems, Inc. |
| 4 | +// reserves all rights not expressly granted by the License. |
| 5 | +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// Unless required by applicable law or agreed to in writing, software |
| 7 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +// See the License for the specific language governing permissions and |
| 10 | +// limitations under the License. |
| 11 | +// |
| 12 | +// Automatically generated by addcopyright.py at 04/03/2012 |
| 13 | +package com.cloud.server.auth; |
| 14 | + |
| 15 | +import java.math.BigInteger; |
| 16 | +import java.security.MessageDigest; |
| 17 | +import java.security.NoSuchAlgorithmException; |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +import javax.ejb.Local; |
| 21 | +import javax.naming.ConfigurationException; |
| 22 | + |
| 23 | +import org.apache.log4j.Logger; |
| 24 | + |
| 25 | +import com.cloud.server.ManagementServer; |
| 26 | +import com.cloud.user.UserAccount; |
| 27 | +import com.cloud.user.dao.UserAccountDao; |
| 28 | +import com.cloud.utils.component.ComponentLocator; |
| 29 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 30 | + |
| 31 | + |
| 32 | +@Local(value={UserAuthenticator.class}) |
| 33 | +public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { |
| 34 | + public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); |
| 35 | + |
| 36 | + private UserAccountDao _userAccountDao; |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) { |
| 40 | + if (s_logger.isDebugEnabled()) { |
| 41 | + s_logger.debug("Retrieving user: " + username); |
| 42 | + } |
| 43 | + UserAccount user = _userAccountDao.getUserAccount(username, domainId); |
| 44 | + if (user == null) { |
| 45 | + s_logger.debug("Unable to find user with " + username + " in domain " + domainId); |
| 46 | + return false; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + MessageDigest md5; |
| 51 | + try { |
| 52 | + md5 = MessageDigest.getInstance("MD5"); |
| 53 | + } catch (NoSuchAlgorithmException e) { |
| 54 | + throw new CloudRuntimeException("Error", e); |
| 55 | + } |
| 56 | + md5.reset(); |
| 57 | + BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); |
| 58 | + |
| 59 | + // make sure our MD5 hash value is 32 digits long... |
| 60 | + StringBuffer sb = new StringBuffer(); |
| 61 | + String pwStr = pwInt.toString(16); |
| 62 | + int padding = 32 - pwStr.length(); |
| 63 | + for (int i = 0; i < padding; i++) { |
| 64 | + sb.append('0'); |
| 65 | + } |
| 66 | + sb.append(pwStr); |
| 67 | + |
| 68 | + |
| 69 | + // Will: The MD5Authenticator is now a straight pass-through comparison of the |
| 70 | + // the passwords because we will not assume that the password passed in has |
| 71 | + // already been MD5 hashed. I am keeping the above code in case this requirement changes |
| 72 | + // or people need examples of how to MD5 hash passwords in java. |
| 73 | + if (!user.getPassword().equals(sb.toString())) { |
| 74 | + s_logger.debug("Password does not match"); |
| 75 | + return false; |
| 76 | + } |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + public boolean configure(String name, Map<String, Object> params) |
| 81 | + throws ConfigurationException { |
| 82 | + super.configure(name, params); |
| 83 | + ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); |
| 84 | + _userAccountDao = locator.getDao(UserAccountDao.class); |
| 85 | + return true; |
| 86 | + } |
| 87 | +} |
0 commit comments