diff --git a/build/build-cloud-plugins.xml b/build/build-cloud-plugins.xml index fad40908ae4..efd84334213 100755 --- a/build/build-cloud-plugins.xml +++ b/build/build-cloud-plugins.xml @@ -236,19 +236,25 @@ - - + + - + - + + + + + + + diff --git a/plugins/user-authenticators/plain-text/.classpath b/plugins/user-authenticators/plain-text/.classpath new file mode 100755 index 00000000000..e39771ada09 --- /dev/null +++ b/plugins/user-authenticators/plain-text/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/plugins/user-authenticators/plain-text/.project b/plugins/user-authenticators/plain-text/.project new file mode 100755 index 00000000000..98414afbab5 --- /dev/null +++ b/plugins/user-authenticators/plain-text/.project @@ -0,0 +1,17 @@ + + + plaintext-user-authenticator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/plugins/user-authenticators/plain-text/build.xml b/plugins/user-authenticators/plain-text/build.xml new file mode 100755 index 00000000000..a59bb5d9e65 --- /dev/null +++ b/plugins/user-authenticators/plain-text/build.xml @@ -0,0 +1,128 @@ + + + + + + + Cloud Stack ant build file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/src/com/cloud/server/auth/PlainTextUserAuthenticator.java b/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java similarity index 97% rename from server/src/com/cloud/server/auth/PlainTextUserAuthenticator.java rename to plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java index 11de1e76632..f05a8cd815f 100644 --- a/server/src/com/cloud/server/auth/PlainTextUserAuthenticator.java +++ b/plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java @@ -1,87 +1,87 @@ -// Copyright 2012 Citrix Systems, Inc. Licensed under the -// Apache License, Version 2.0 (the "License"); you may not use this -// file except in compliance with the License. Citrix Systems, Inc. -// reserves all rights not expressly granted by the License. -// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.server.auth; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.server.ManagementServer; -import com.cloud.user.UserAccount; -import com.cloud.user.dao.UserAccountDao; -import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.exception.CloudRuntimeException; - - -@Local(value={UserAuthenticator.class}) -public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { - public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); - - private UserAccountDao _userAccountDao; - - @Override - public boolean authenticate(String username, String password, Long domainId, Map requestParameters ) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Retrieving user: " + username); - } - UserAccount user = _userAccountDao.getUserAccount(username, domainId); - if (user == null) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); - return false; - } - - - MessageDigest md5; - try { - md5 = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - throw new CloudRuntimeException("Error", e); - } - md5.reset(); - BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); - - // make sure our MD5 hash value is 32 digits long... - StringBuffer sb = new StringBuffer(); - String pwStr = pwInt.toString(16); - int padding = 32 - pwStr.length(); - for (int i = 0; i < padding; i++) { - sb.append('0'); - } - sb.append(pwStr); - - - // Will: The MD5Authenticator is now a straight pass-through comparison of the - // the passwords because we will not assume that the password passed in has - // already been MD5 hashed. I am keeping the above code in case this requirement changes - // or people need examples of how to MD5 hash passwords in java. - if (!user.getPassword().equals(sb.toString())) { - s_logger.debug("Password does not match"); - return false; - } - return true; - } - - public boolean configure(String name, Map params) - throws ConfigurationException { - super.configure(name, params); - ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - _userAccountDao = locator.getDao(UserAccountDao.class); - return true; - } -} +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.server.auth; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Map; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.server.ManagementServer; +import com.cloud.user.UserAccount; +import com.cloud.user.dao.UserAccountDao; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.exception.CloudRuntimeException; + + +@Local(value={UserAuthenticator.class}) +public class PlainTextUserAuthenticator extends DefaultUserAuthenticator { + public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); + + private UserAccountDao _userAccountDao; + + @Override + public boolean authenticate(String username, String password, Long domainId, Map requestParameters ) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Retrieving user: " + username); + } + UserAccount user = _userAccountDao.getUserAccount(username, domainId); + if (user == null) { + s_logger.debug("Unable to find user with " + username + " in domain " + domainId); + return false; + } + + + MessageDigest md5; + try { + md5 = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new CloudRuntimeException("Error", e); + } + md5.reset(); + BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); + + // make sure our MD5 hash value is 32 digits long... + StringBuffer sb = new StringBuffer(); + String pwStr = pwInt.toString(16); + int padding = 32 - pwStr.length(); + for (int i = 0; i < padding; i++) { + sb.append('0'); + } + sb.append(pwStr); + + + // Will: The MD5Authenticator is now a straight pass-through comparison of the + // the passwords because we will not assume that the password passed in has + // already been MD5 hashed. I am keeping the above code in case this requirement changes + // or people need examples of how to MD5 hash passwords in java. + if (!user.getPassword().equals(sb.toString())) { + s_logger.debug("Password does not match"); + return false; + } + return true; + } + + public boolean configure(String name, Map params) + throws ConfigurationException { + super.configure(name, params); + ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); + _userAccountDao = locator.getDao(UserAccountDao.class); + return true; + } +}