cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject [6/7] git commit: updated refs/heads/ldapplugin to 25e8e9b
Date Fri, 02 Aug 2013 10:42:18 GMT
Add SSL Support

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/00c17add
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/00c17add
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/00c17add

Branch: refs/heads/ldapplugin
Commit: 00c17add3ce5ac125cfb6bc01c6612c3ee05d37c
Parents: 23f0187
Author: Ian Duffy <ian@ianduffy.ie>
Authored: Fri Aug 2 09:28:19 2013 +0100
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Fri Aug 2 14:20:47 2013 +0530

----------------------------------------------------------------------
 .../api/command/LdapAddConfigurationCmd.java    | 124 +++----
 .../api/command/LdapCreateAccount.java          | 223 ++++++------
 .../api/command/LdapDeleteConfigurationCmd.java |  70 ++--
 .../api/command/LdapListAllUsersCmd.java        |  91 ++---
 .../api/command/LdapListConfigurationCmd.java   | 142 ++++----
 .../api/command/LdapUserSearchCmd.java          | 117 +++---
 .../api/response/LdapConfigurationResponse.java |  77 ++--
 .../api/response/LdapUserResponse.java          | 149 ++++----
 .../cloudstack/ldap/LdapAuthenticator.java      |  73 ++--
 .../cloudstack/ldap/LdapConfiguration.java      | 209 ++++++-----
 .../cloudstack/ldap/LdapConfigurationVO.java    |  54 +--
 .../cloudstack/ldap/LdapContextFactory.java     | 168 +++++----
 .../org/apache/cloudstack/ldap/LdapManager.java |  23 +-
 .../apache/cloudstack/ldap/LdapManagerImpl.java | 355 ++++++++++---------
 .../org/apache/cloudstack/ldap/LdapUser.java    |  94 ++---
 .../apache/cloudstack/ldap/LdapUserManager.java | 136 ++++---
 .../org/apache/cloudstack/ldap/LdapUtils.java   |  71 ++--
 .../ldap/NoLdapUserMatchingQueryException.java  |  18 +-
 .../ldap/NoSuchLdapUserException.java           |  18 +-
 .../ldap/dao/LdapConfigurationDao.java          |   8 +-
 .../ldap/dao/LdapConfigurationDaoImpl.java      |  66 ++--
 server/src/com/cloud/configuration/Config.java  |   3 +
 setup/db/db/schema-410to420.sql                 |   3 +
 23 files changed, 1217 insertions(+), 1075 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java
index b8e08e5..d5ccdaf 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java
@@ -2,8 +2,6 @@ package org.apache.cloudstack.api.command;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseCmd;
@@ -11,70 +9,74 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.ldap.LdapManager;
+import org.apache.log4j.Logger;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.user.Account;
 
 @APICommand(name = "addLdapConfiguration", description = "Add a new Ldap Configuration", responseObject = LdapConfigurationResponse.class, since = "4.2.0")
 public class LdapAddConfigurationCmd extends BaseCmd {
-    public static final Logger s_logger = Logger.getLogger(LdapAddConfigurationCmd.class.getName());
-    private static final String s_name = "ldapconfigurationresponse";
-
-    @Inject
-    private LdapManager _ldapManager;
-
-    @Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
-    private String hostname;
-
-    @Parameter(name = "port", type = CommandType.INTEGER, required = true, description = "Port")
-    private int port;
-
-    public LdapAddConfigurationCmd() {
-        super();
-    }
-
-    public LdapAddConfigurationCmd(final LdapManager ldapManager) {
-        super();
-        _ldapManager = ldapManager;
-    }
-
-    @Override
-    public void execute() throws ServerApiException {
-        try {
-            final LdapConfigurationResponse response = _ldapManager.addConfiguration(hostname, port);
-            response.setObjectName("LdapAddConfiguration");
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } catch (final InvalidParameterValueException e) {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
-        }
-
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
-
-    public String getHostname() {
-        return hostname;
-    }
-
-    public int getPort() {
-        return port;
-    }
-
-    public void setHostname(final String hostname) {
-        this.hostname = hostname;
-    }
-
-    public void setPort(final int port) {
-        this.port = port;
-    }
+	public static final Logger s_logger = Logger
+			.getLogger(LdapAddConfigurationCmd.class.getName());
+	private static final String s_name = "ldapconfigurationresponse";
+
+	@Inject
+	private LdapManager _ldapManager;
+
+	@Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
+	private String hostname;
+
+	@Parameter(name = "port", type = CommandType.INTEGER, required = true, description = "Port")
+	private int port;
+
+	public LdapAddConfigurationCmd() {
+		super();
+	}
+
+	public LdapAddConfigurationCmd(final LdapManager ldapManager) {
+		super();
+		_ldapManager = ldapManager;
+	}
+
+	@Override
+	public void execute() throws ServerApiException {
+		try {
+			final LdapConfigurationResponse response = _ldapManager
+					.addConfiguration(hostname, port);
+			response.setObjectName("LdapAddConfiguration");
+			response.setResponseName(getCommandName());
+			setResponseObject(response);
+		} catch (final InvalidParameterValueException e) {
+			throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
+					e.toString());
+		}
+
+	}
+
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
+
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
+
+	public String getHostname() {
+		return hostname;
+	}
+
+	public int getPort() {
+		return port;
+	}
+
+	public void setHostname(final String hostname) {
+		this.hostname = hostname;
+	}
+
+	public void setPort(final int port) {
+		this.port = port;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
index 82c6e4a..47e5bf4 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
@@ -23,9 +23,6 @@ import java.util.Map;
 import javax.inject.Inject;
 import javax.naming.NamingException;
 
-import org.apache.log4j.Logger;
-import org.bouncycastle.util.encoders.Base64;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -37,6 +34,8 @@ import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.ldap.LdapManager;
 import org.apache.cloudstack.ldap.LdapUser;
+import org.apache.log4j.Logger;
+import org.bouncycastle.util.encoders.Base64;
 
 import com.cloud.user.Account;
 import com.cloud.user.AccountService;
@@ -44,105 +43,121 @@ import com.cloud.user.UserAccount;
 
 @APICommand(name = "ldapCreateAccount", description = "Creates an account from an LDAP user", responseObject = AccountResponse.class, since = "4.2.0")
 public class LdapCreateAccount extends BaseCmd {
-    public static final Logger s_logger = Logger.getLogger(LdapCreateAccount.class.getName());
-    private static final String s_name = "createaccountresponse";
-
-    @Inject
-    private LdapManager _ldapManager;
-
-    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
-    private String accountName;
-
-    @Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account.  Specify 0 for user, 1 for root admin, and 2 for domain admin")
-    private Short accountType;
-
-    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
-            description = "Creates the user under the specified domain.")
-    private Long domainId;
-
-    @Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
-    private String timezone;
-
-    @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Unique username.")
-    private String username;
-
-    @Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING, description = "Network domain for the account's networks")
-    private String networkDomain;
-
-    @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
-    private Map<String, String> details;
-
-    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "Account UUID, required for adding account from external provisioning system")
-    private String accountUUID;
-
-    @Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING, description = "User UUID, required for adding account from external provisioning system")
-    private String userUUID;
-
-    public LdapCreateAccount() {
-        super();
-    }
-
-    public LdapCreateAccount(final LdapManager ldapManager, final AccountService accountService) {
-        super();
-        _ldapManager = ldapManager;
-	_accountService = accountService;
-    }
-
-    @Override
-    public void execute() throws ServerApiException {
-	updateCallContext();
-        try {
-	    LdapUser user = _ldapManager.getUser(username);
-            validateUser(user);
-	    UserAccount userAccount = _accountService.createUserAccount(username, generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone,
-                    accountName, accountType, domainId, networkDomain, details, accountUUID, userUUID);
-            if (userAccount != null) {
-                AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
-                response.setResponseName(getCommandName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account");
-            }
-        } catch (NamingException e) {
-	    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, "No LDAP user exists with the username of " + username);
-        }
-    }
-
-    private void updateCallContext() {
-	CallContext.current().setEventDetails("Account Name: " + accountName + ", Domain Id:" + domainId);
-    }
-
-    private String generatePassword() throws ServerApiException {
-        try {
-            SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
-            byte bytes[] = new byte[20];
-            randomGen.nextBytes(bytes);
-            return Base64.encode(bytes).toString();
-        } catch (NoSuchAlgorithmException e) {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password");
-        }
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
-
-    private boolean validateUser(LdapUser user) throws ServerApiException {
-        if (user.getEmail() == null) {
-	    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username + " has no email address set within LDAP");
-        }
-        if (user.getFirstname() == null) {
-	    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username + " has no firstname set within LDAP");
-        }
-        if (user.getLastname() == null) {
-	    throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username + " has no lastname set within LDAP");
-        }
-	return true;
-    }
+	public static final Logger s_logger = Logger
+			.getLogger(LdapCreateAccount.class.getName());
+	private static final String s_name = "createaccountresponse";
+
+	@Inject
+	private LdapManager _ldapManager;
+
+	@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
+	private String accountName;
+
+	@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account.  Specify 0 for user, 1 for root admin, and 2 for domain admin")
+	private Short accountType;
+
+	@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Creates the user under the specified domain.")
+	private Long domainId;
+
+	@Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
+	private String timezone;
+
+	@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Unique username.")
+	private String username;
+
+	@Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING, description = "Network domain for the account's networks")
+	private String networkDomain;
+
+	@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
+	private Map<String, String> details;
+
+	@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "Account UUID, required for adding account from external provisioning system")
+	private String accountUUID;
+
+	@Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING, description = "User UUID, required for adding account from external provisioning system")
+	private String userUUID;
+
+	public LdapCreateAccount() {
+		super();
+	}
+
+	public LdapCreateAccount(final LdapManager ldapManager,
+			final AccountService accountService) {
+		super();
+		_ldapManager = ldapManager;
+		_accountService = accountService;
+	}
+
+	@Override
+	public void execute() throws ServerApiException {
+		updateCallContext();
+		try {
+			LdapUser user = _ldapManager.getUser(username);
+			validateUser(user);
+			UserAccount userAccount = _accountService.createUserAccount(
+					username, generatePassword(), user.getFirstname(),
+					user.getLastname(), user.getEmail(), timezone, accountName,
+					accountType, domainId, networkDomain, details, accountUUID,
+					userUUID);
+			if (userAccount != null) {
+				AccountResponse response = _responseGenerator
+						.createUserAccountResponse(userAccount);
+				response.setResponseName(getCommandName());
+				setResponseObject(response);
+			} else {
+				throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
+						"Failed to create a user account");
+			}
+		} catch (NamingException e) {
+			throw new ServerApiException(
+					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,
+					"No LDAP user exists with the username of " + username);
+		}
+	}
+
+	private String generatePassword() throws ServerApiException {
+		try {
+			SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
+			byte bytes[] = new byte[20];
+			randomGen.nextBytes(bytes);
+			return Base64.encode(bytes).toString();
+		} catch (NoSuchAlgorithmException e) {
+			throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
+					"Failed to generate random password");
+		}
+	}
+
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
+
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
+
+	private void updateCallContext() {
+		CallContext.current().setEventDetails(
+				"Account Name: " + accountName + ", Domain Id:" + domainId);
+	}
+
+	private boolean validateUser(LdapUser user) throws ServerApiException {
+		if (user.getEmail() == null) {
+			throw new ServerApiException(
+					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
+							+ " has no email address set within LDAP");
+		}
+		if (user.getFirstname() == null) {
+			throw new ServerApiException(
+					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
+							+ " has no firstname set within LDAP");
+		}
+		if (user.getLastname() == null) {
+			throw new ServerApiException(
+					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
+							+ " has no lastname set within LDAP");
+		}
+		return true;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java
index b45bce5..d57c9a3 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java
@@ -18,8 +18,6 @@ package org.apache.cloudstack.api.command;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseCmd;
@@ -27,50 +25,54 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.ldap.LdapManager;
+import org.apache.log4j.Logger;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.user.Account;
 
 @APICommand(name = "deleteLdapConfiguration", description = "Remove an Ldap Configuration", responseObject = LdapConfigurationResponse.class, since = "4.2.0")
 public class LdapDeleteConfigurationCmd extends BaseCmd {
-    public static final Logger s_logger = Logger.getLogger(LdapDeleteConfigurationCmd.class.getName());
-    private static final String s_name = "ldapconfigurationresponse";
+	public static final Logger s_logger = Logger
+			.getLogger(LdapDeleteConfigurationCmd.class.getName());
+	private static final String s_name = "ldapconfigurationresponse";
 
-    @Inject
-    private LdapManager _ldapManager;
+	@Inject
+	private LdapManager _ldapManager;
 
-    @Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
-    private String hostname;
+	@Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
+	private String hostname;
 
-    public LdapDeleteConfigurationCmd() {
-        super();
-    }
+	public LdapDeleteConfigurationCmd() {
+		super();
+	}
 
-    public LdapDeleteConfigurationCmd(final LdapManager ldapManager) {
-        super();
-        _ldapManager = ldapManager;
-    }
+	public LdapDeleteConfigurationCmd(final LdapManager ldapManager) {
+		super();
+		_ldapManager = ldapManager;
+	}
 
-    @Override
-    public void execute() throws ServerApiException {
-        try {
-            final LdapConfigurationResponse response = _ldapManager.deleteConfiguration(hostname);
-            response.setObjectName("LdapDeleteConfiguration");
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } catch (final InvalidParameterValueException e) {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
-        }
+	@Override
+	public void execute() throws ServerApiException {
+		try {
+			final LdapConfigurationResponse response = _ldapManager
+					.deleteConfiguration(hostname);
+			response.setObjectName("LdapDeleteConfiguration");
+			response.setResponseName(getCommandName());
+			setResponseObject(response);
+		} catch (final InvalidParameterValueException e) {
+			throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
+					e.toString());
+		}
 
-    }
+	}
 
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
 
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
index c5d6b40..c5cecc7 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
@@ -21,8 +21,6 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.ServerApiException;
@@ -31,59 +29,62 @@ import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.ldap.LdapManager;
 import org.apache.cloudstack.ldap.LdapUser;
 import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException;
+import org.apache.log4j.Logger;
 
 import com.cloud.user.Account;
 
 @APICommand(name = "listAllLdapUsers", responseObject = LdapUserResponse.class, description = "Lists all LDAP Users", since = "4.2.0")
 public class LdapListAllUsersCmd extends BaseListCmd {
 
-    public static final Logger s_logger = Logger.getLogger(LdapListAllUsersCmd.class.getName());
-    private static final String s_name = "ldapuserresponse";
-    @Inject
-    private LdapManager _ldapManager;
+	public static final Logger s_logger = Logger
+			.getLogger(LdapListAllUsersCmd.class.getName());
+	private static final String s_name = "ldapuserresponse";
+	@Inject
+	private LdapManager _ldapManager;
 
-    public LdapListAllUsersCmd() {
-        super();
-    }
+	public LdapListAllUsersCmd() {
+		super();
+	}
 
-    public LdapListAllUsersCmd(final LdapManager ldapManager) {
-        super();
-        _ldapManager = ldapManager;
-    }
+	public LdapListAllUsersCmd(final LdapManager ldapManager) {
+		super();
+		_ldapManager = ldapManager;
+	}
 
-    private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
-        final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
-        for (final LdapUser user : users) {
-            final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
-            ldapResponse.setObjectName("LdapUser");
-            ldapResponses.add(ldapResponse);
-        }
-        return ldapResponses;
-    }
+	private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
+		final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
+		for (final LdapUser user : users) {
+			final LdapUserResponse ldapResponse = _ldapManager
+					.createLdapUserResponse(user);
+			ldapResponse.setObjectName("LdapUser");
+			ldapResponses.add(ldapResponse);
+		}
+		return ldapResponses;
+	}
 
-    @Override
-    public void execute() throws ServerApiException {
-	List<LdapUserResponse> ldapResponses = null;
-	final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
-        try {
-            final List<LdapUser> users = _ldapManager.getUsers();
-	    ldapResponses = createLdapUserResponse(users);
-	} catch (final NoLdapUserMatchingQueryException ex) {
-	    ldapResponses = new ArrayList<LdapUserResponse>();
-	} finally {
-            response.setResponses(ldapResponses);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        }
-    }
+	@Override
+	public void execute() throws ServerApiException {
+		List<LdapUserResponse> ldapResponses = null;
+		final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
+		try {
+			final List<LdapUser> users = _ldapManager.getUsers();
+			ldapResponses = createLdapUserResponse(users);
+		} catch (final NoLdapUserMatchingQueryException ex) {
+			ldapResponses = new ArrayList<LdapUserResponse>();
+		} finally {
+			response.setResponses(ldapResponses);
+			response.setResponseName(getCommandName());
+			setResponseObject(response);
+		}
+	}
 
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
 
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
index fc9bd35..7abfefe 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
@@ -21,8 +21,6 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
@@ -30,77 +28,83 @@ import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.ldap.LdapConfigurationVO;
 import org.apache.cloudstack.ldap.LdapManager;
+import org.apache.log4j.Logger;
 
 import com.cloud.user.Account;
 import com.cloud.utils.Pair;
 
 @APICommand(name = "listLdapConfigurations", responseObject = LdapConfigurationResponse.class, description = "Lists all LDAP configurations", since = "4.2.0")
 public class LdapListConfigurationCmd extends BaseListCmd {
-    public static final Logger s_logger = Logger.getLogger(LdapListConfigurationCmd.class.getName());
-
-    private static final String s_name = "ldapconfigurationresponse";
-
-    @Inject
-    private LdapManager _ldapManager;
-
-    @Parameter(name = "hostname", type = CommandType.STRING, required = false, description = "Hostname")
-    private String hostname;
-
-    @Parameter(name = "port", type = CommandType.INTEGER, required = false, description = "Port")
-    private int port;
-
-    public LdapListConfigurationCmd() {
-        super();
-    }
-
-    public LdapListConfigurationCmd(final LdapManager ldapManager) {
-        super();
-        _ldapManager = ldapManager;
-    }
-
-    private List<LdapConfigurationResponse> createLdapConfigurationResponses(List<? extends LdapConfigurationVO> configurations) {
-        final List<LdapConfigurationResponse> responses = new ArrayList<LdapConfigurationResponse>();
-        for (final LdapConfigurationVO resource : configurations) {
-            final LdapConfigurationResponse configurationResponse = _ldapManager.createLdapConfigurationResponse(resource);
-            configurationResponse.setObjectName("LdapConfiguration");
-            responses.add(configurationResponse);
-        }
-        return responses;
-    }
-
-    @Override
-    public void execute() {
-        final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(this);
-        final List<LdapConfigurationResponse> responses = createLdapConfigurationResponses(result.first());
-        final ListResponse<LdapConfigurationResponse> response = new ListResponse<LdapConfigurationResponse>();
-        response.setResponses(responses, result.second());
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
-
-    public String getHostname() {
-        return hostname;
-    }
-
-    public int getPort() {
-        return port;
-    }
-
-    public void setHostname(final String hostname) {
-        this.hostname = hostname;
-    }
-
-    public void setPort(final int port) {
-        this.port = port;
-    }
+	public static final Logger s_logger = Logger
+			.getLogger(LdapListConfigurationCmd.class.getName());
+
+	private static final String s_name = "ldapconfigurationresponse";
+
+	@Inject
+	private LdapManager _ldapManager;
+
+	@Parameter(name = "hostname", type = CommandType.STRING, required = false, description = "Hostname")
+	private String hostname;
+
+	@Parameter(name = "port", type = CommandType.INTEGER, required = false, description = "Port")
+	private int port;
+
+	public LdapListConfigurationCmd() {
+		super();
+	}
+
+	public LdapListConfigurationCmd(final LdapManager ldapManager) {
+		super();
+		_ldapManager = ldapManager;
+	}
+
+	private List<LdapConfigurationResponse> createLdapConfigurationResponses(
+			List<? extends LdapConfigurationVO> configurations) {
+		final List<LdapConfigurationResponse> responses = new ArrayList<LdapConfigurationResponse>();
+		for (final LdapConfigurationVO resource : configurations) {
+			final LdapConfigurationResponse configurationResponse = _ldapManager
+					.createLdapConfigurationResponse(resource);
+			configurationResponse.setObjectName("LdapConfiguration");
+			responses.add(configurationResponse);
+		}
+		return responses;
+	}
+
+	@Override
+	public void execute() {
+		final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager
+				.listConfigurations(this);
+		final List<LdapConfigurationResponse> responses = createLdapConfigurationResponses(result
+				.first());
+		final ListResponse<LdapConfigurationResponse> response = new ListResponse<LdapConfigurationResponse>();
+		response.setResponses(responses, result.second());
+		response.setResponseName(getCommandName());
+		setResponseObject(response);
+	}
+
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
+
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
+
+	public String getHostname() {
+		return hostname;
+	}
+
+	public int getPort() {
+		return port;
+	}
+
+	public void setHostname(final String hostname) {
+		this.hostname = hostname;
+	}
+
+	public void setPort(final int port) {
+		this.port = port;
+	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
index 314581b..7359882 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
@@ -21,8 +21,6 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
@@ -31,66 +29,69 @@ import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.ldap.LdapManager;
 import org.apache.cloudstack.ldap.LdapUser;
 import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException;
+import org.apache.log4j.Logger;
 
 import com.cloud.user.Account;
 
 @APICommand(name = "searchLdap", responseObject = LdapUserResponse.class, description = "Searches LDAP based on the username attribute", since = "4.2.0")
 public class LdapUserSearchCmd extends BaseListCmd {
 
-    public static final Logger s_logger = Logger.getLogger(LdapUserSearchCmd.class.getName());
-    private static final String s_name = "ldapuserresponse";
-    @Inject
-    private LdapManager _ldapManager;
-
-    @Parameter(name = "query", type = CommandType.STRING, entityType = LdapUserResponse.class, required = true, description = "query to search using")
-    private String query;
-
-    public LdapUserSearchCmd() {
-        super();
-    }
-
-    public LdapUserSearchCmd(final LdapManager ldapManager) {
-        super();
-        _ldapManager = ldapManager;
-    }
-
-    private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
-        final List<LdapUserResponse> ldapUserResponses = new ArrayList<LdapUserResponse>();
-        if (users != null) {
-            for (final LdapUser user : users) {
-                final LdapUserResponse ldapUserResponse = _ldapManager.createLdapUserResponse(user);
-                ldapUserResponse.setObjectName("LdapUser");
-                ldapUserResponses.add(ldapUserResponse);
-            }
-        }
-        return ldapUserResponses;
-    }
-
-    @Override
-    public void execute() {
-        final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
-        List<LdapUser> users = null;
-
-        try {
-            users = _ldapManager.searchUsers(query);
-        } catch (final NoLdapUserMatchingQueryException e) {
-            s_logger.debug(e.getMessage());
-        }
-
-        final List<LdapUserResponse> ldapUserResponses = createLdapUserResponse(users);
-
-        response.setResponses(ldapUserResponses);
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
+	public static final Logger s_logger = Logger
+			.getLogger(LdapUserSearchCmd.class.getName());
+	private static final String s_name = "ldapuserresponse";
+	@Inject
+	private LdapManager _ldapManager;
+
+	@Parameter(name = "query", type = CommandType.STRING, entityType = LdapUserResponse.class, required = true, description = "query to search using")
+	private String query;
+
+	public LdapUserSearchCmd() {
+		super();
+	}
+
+	public LdapUserSearchCmd(final LdapManager ldapManager) {
+		super();
+		_ldapManager = ldapManager;
+	}
+
+	private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
+		final List<LdapUserResponse> ldapUserResponses = new ArrayList<LdapUserResponse>();
+		if (users != null) {
+			for (final LdapUser user : users) {
+				final LdapUserResponse ldapUserResponse = _ldapManager
+						.createLdapUserResponse(user);
+				ldapUserResponse.setObjectName("LdapUser");
+				ldapUserResponses.add(ldapUserResponse);
+			}
+		}
+		return ldapUserResponses;
+	}
+
+	@Override
+	public void execute() {
+		final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
+		List<LdapUser> users = null;
+
+		try {
+			users = _ldapManager.searchUsers(query);
+		} catch (final NoLdapUserMatchingQueryException e) {
+			s_logger.debug(e.getMessage());
+		}
+
+		final List<LdapUserResponse> ldapUserResponses = createLdapUserResponse(users);
+
+		response.setResponses(ldapUserResponses);
+		response.setResponseName(getCommandName());
+		setResponseObject(response);
+	}
+
+	@Override
+	public String getCommandName() {
+		return s_name;
+	}
+
+	@Override
+	public long getEntityOwnerId() {
+		return Account.ACCOUNT_ID_SYSTEM;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapConfigurationResponse.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapConfigurationResponse.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapConfigurationResponse.java
index a4e4782..39d5bae 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapConfigurationResponse.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapConfigurationResponse.java
@@ -16,48 +16,47 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.BaseResponse;
 
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 public class LdapConfigurationResponse extends BaseResponse {
-    @SerializedName("hostname")
-    @Param(description = "hostname")
-    private String hostname;
-
-    @SerializedName("port")
-    @Param(description = "port")
-    private int port;
-
-    public LdapConfigurationResponse() {
-        super();
-    }
-
-    public LdapConfigurationResponse(final String hostname) {
-        super();
-        this.hostname = hostname;
-    }
-
-    public LdapConfigurationResponse(final String hostname, final int port) {
-        this.hostname = hostname;
-        this.port = port;
-    }
-
-    public String getHostname() {
-        return hostname;
-    }
-
-    public int getPort() {
-        return port;
-    }
-
-    public void setHostname(final String hostname) {
-        this.hostname = hostname;
-    }
-
-    public void setPort(final int port) {
-        this.port = port;
-    }
+	@SerializedName("hostname")
+	@Param(description = "hostname")
+	private String hostname;
+
+	@SerializedName("port")
+	@Param(description = "port")
+	private int port;
+
+	public LdapConfigurationResponse() {
+		super();
+	}
+
+	public LdapConfigurationResponse(final String hostname) {
+		super();
+		this.hostname = hostname;
+	}
+
+	public LdapConfigurationResponse(final String hostname, final int port) {
+		this.hostname = hostname;
+		this.port = port;
+	}
+
+	public String getHostname() {
+		return hostname;
+	}
+
+	public int getPort() {
+		return port;
+	}
+
+	public void setHostname(final String hostname) {
+		this.hostname = hostname;
+	}
+
+	public void setPort(final int port) {
+		this.port = port;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapUserResponse.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapUserResponse.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapUserResponse.java
index eb1c14c..9b21c8f 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapUserResponse.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/response/LdapUserResponse.java
@@ -16,83 +16,84 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.BaseResponse;
 
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 public class LdapUserResponse extends BaseResponse {
-    @SerializedName("email")
-    @Param(description = "The user's email")
-    private String email;
-
-    @SerializedName("principal")
-    @Param(description = "The user's principle")
-    private String principal;
-
-    @SerializedName("firstname")
-    @Param(description = "The user's firstname")
-    private String firstname;
-
-    @SerializedName("lastname")
-    @Param(description = "The user's lastname")
-    private String lastname;
-
-    @SerializedName("username")
-    @Param(description = "The user's username")
-    private String username;
-
-    public LdapUserResponse() {
-        super();
-    }
-
-    public LdapUserResponse(final String username, final String email, final String firstname, final String lastname, final String principal) {
-        super();
-        this.username = username;
-        this.email = email;
-        this.firstname = firstname;
-        this.lastname = lastname;
-        this.principal = principal;
-    }
-
-    public String getEmail() {
-        return email;
-    }
-
-    public String getFirstname() {
-        return firstname;
-    }
-
-    public String getLastname() {
-        return lastname;
-    }
-
-    public String getPrincipal() {
-        return principal;
-    }
-
-    public String getUsername() {
-        return username;
-    }
-
-    public void setEmail(final String email) {
-        this.email = email;
-    }
-
-    public void setFirstname(final String firstname) {
-        this.firstname = firstname;
-    }
-
-    public void setLastname(final String lastname) {
-        this.lastname = lastname;
-    }
-
-    public void setPrincipal(final String principal) {
-        this.principal = principal;
-    }
-
-    public void setUsername(final String username) {
-        this.username = username;
-    }
+	@SerializedName("email")
+	@Param(description = "The user's email")
+	private String email;
+
+	@SerializedName("principal")
+	@Param(description = "The user's principle")
+	private String principal;
+
+	@SerializedName("firstname")
+	@Param(description = "The user's firstname")
+	private String firstname;
+
+	@SerializedName("lastname")
+	@Param(description = "The user's lastname")
+	private String lastname;
+
+	@SerializedName("username")
+	@Param(description = "The user's username")
+	private String username;
+
+	public LdapUserResponse() {
+		super();
+	}
+
+	public LdapUserResponse(final String username, final String email,
+			final String firstname, final String lastname,
+			final String principal) {
+		super();
+		this.username = username;
+		this.email = email;
+		this.firstname = firstname;
+		this.lastname = lastname;
+		this.principal = principal;
+	}
+
+	public String getEmail() {
+		return email;
+	}
+
+	public String getFirstname() {
+		return firstname;
+	}
+
+	public String getLastname() {
+		return lastname;
+	}
+
+	public String getPrincipal() {
+		return principal;
+	}
+
+	public String getUsername() {
+		return username;
+	}
+
+	public void setEmail(final String email) {
+		this.email = email;
+	}
+
+	public void setFirstname(final String firstname) {
+		this.firstname = firstname;
+	}
+
+	public void setLastname(final String lastname) {
+		this.lastname = lastname;
+	}
+
+	public void setPrincipal(final String principal) {
+		this.principal = principal;
+	}
+
+	public void setUsername(final String username) {
+		this.username = username;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
index 54b6a8b..fdea9b6 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
@@ -20,54 +20,59 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.command.LdapListConfigurationCmd;
+import org.apache.log4j.Logger;
 
 import com.cloud.server.auth.DefaultUserAuthenticator;
 import com.cloud.user.UserAccount;
 import com.cloud.user.dao.UserAccountDao;
 
 public class LdapAuthenticator extends DefaultUserAuthenticator {
-    private static final Logger s_logger = Logger.getLogger(LdapAuthenticator.class.getName());
+	private static final Logger s_logger = Logger
+			.getLogger(LdapAuthenticator.class.getName());
 
-    @Inject
-    private LdapManager _ldapManager;
-    @Inject
-    private UserAccountDao _userAccountDao;
+	@Inject
+	private LdapManager _ldapManager;
+	@Inject
+	private UserAccountDao _userAccountDao;
 
-    public LdapAuthenticator() {
-        super();
-    }
+	public LdapAuthenticator() {
+		super();
+	}
 
-    public LdapAuthenticator(final LdapManager ldapManager, final UserAccountDao userAccountDao) {
-        super();
-        _ldapManager = ldapManager;
-        _userAccountDao = userAccountDao;
-    }
+	public LdapAuthenticator(final LdapManager ldapManager,
+			final UserAccountDao userAccountDao) {
+		super();
+		_ldapManager = ldapManager;
+		_userAccountDao = userAccountDao;
+	}
 
-    @Override
-    public boolean authenticate(final String username, final String password, final Long domainId, final Map<String, Object[]> requestParameters) {
+	@Override
+	public boolean authenticate(final String username, final String password,
+			final Long domainId, final Map<String, Object[]> requestParameters) {
 
-        final UserAccount user = _userAccountDao.getUserAccount(username, domainId);
+		final UserAccount user = _userAccountDao.getUserAccount(username,
+				domainId);
 
-        if (user == null) {
-            s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
-            return false;
-        } else if (isLdapConfigurationPresent()) {
-            return _ldapManager.canAuthenticate(username, password);
-        } else {
-            return false;
-        }
-    }
+		if (user == null) {
+			s_logger.debug("Unable to find user with " + username
+					+ " in domain " + domainId);
+			return false;
+		} else if (isLdapConfigurationPresent()) {
+			return _ldapManager.canAuthenticate(username, password);
+		} else {
+			return false;
+		}
+	}
 
-    @Override
-    public String encode(final String password) {
-        return password;
-    }
+	@Override
+	public String encode(final String password) {
+		return password;
+	}
 
-    private boolean isLdapConfigurationPresent() {
-        return _ldapManager.listConfigurations(new LdapListConfigurationCmd(_ldapManager)).second() > 0;
-    }
+	private boolean isLdapConfigurationPresent() {
+		return _ldapManager.listConfigurations(
+				new LdapListConfigurationCmd(_ldapManager)).second() > 0;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
index 1d2ddfb..c0b4a32 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
@@ -27,94 +27,123 @@ import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.utils.Pair;
 
 public class LdapConfiguration {
-    private final static String factory = "com.sun.jndi.ldap.LdapCtxFactory";
-
-    private final static int scope = SearchControls.SUBTREE_SCOPE;
-
-    @Inject
-    private ConfigurationDao _configDao;
-
-    @Inject
-    private LdapManager _ldapManager;
-
-    public LdapConfiguration() {
-    }
-
-    public LdapConfiguration(final ConfigurationDao configDao, final LdapManager ldapManager) {
-        _configDao = configDao;
-        _ldapManager = ldapManager;
-    }
-
-    public String getAuthentication() {
-        if ((getBindPrincipal() == null) && (getBindPassword() == null)) {
-            return "none";
-        } else {
-            return "simple";
-        }
-    }
-
-    public String getBaseDn() {
-        return _configDao.getValue("ldap.basedn");
-    }
-
-    public String getBindPassword() {
-        return _configDao.getValue("ldap.bind.password");
-    }
-
-    public String getBindPrincipal() {
-        return _configDao.getValue("ldap.bind.principal");
-    }
-
-    public String getEmailAttribute() {
-        final String emailAttribute = _configDao.getValue("ldap.email.attribute");
-        return emailAttribute == null ? "mail" : emailAttribute;
-    }
-
-    public String getFactory() {
-        return factory;
-    }
-
-    public String getFirstnameAttribute() {
-        final String firstnameAttribute = _configDao.getValue("ldap.firstname.attribute");
-        return firstnameAttribute == null ? "givenname" : firstnameAttribute;
-    }
-
-    public String getLastnameAttribute() {
-        final String lastnameAttribute = _configDao.getValue("ldap.lastname.attribute");
-        return lastnameAttribute == null ? "sn" : lastnameAttribute;
-    }
-
-    public String getProviderUrl() {
-        final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(new LdapListConfigurationCmd(_ldapManager));
-        final StringBuilder providerUrls = new StringBuilder();
-        String delim = "";
-        for (final LdapConfigurationVO resource : result.first()) {
-            final String providerUrl = "ldap://" + resource.getHostname() + ":" + resource.getPort();
-            providerUrls.append(delim).append(providerUrl);
-            delim = " ";
-        }
-        return providerUrls.toString();
-    }
-
-    public String[] getReturnAttributes() {
-        return new String[] {getUsernameAttribute(), getEmailAttribute(), getFirstnameAttribute(), getLastnameAttribute()};
-    }
-
-    public int getScope() {
-        return scope;
-    }
-
-    public String getUsernameAttribute() {
-        final String usernameAttribute = _configDao.getValue("ldap.username.attribute");
-        return usernameAttribute == null ? "uid" : usernameAttribute;
-    }
-
-    public String getUserObject() {
-        final String userObject = _configDao.getValue("ldap.user.object");
-        return userObject == null ? "inetOrgPerson" : userObject;
-    }
-
-    public String getSearchGroupPrinciple() {
-	return _configDao.getValue("ldap.search.group.principle");
-    }
+	private final static String factory = "com.sun.jndi.ldap.LdapCtxFactory";
+
+	private final static int scope = SearchControls.SUBTREE_SCOPE;
+
+	@Inject
+	private ConfigurationDao _configDao;
+
+	@Inject
+	private LdapManager _ldapManager;
+
+	public LdapConfiguration() {
+	}
+
+	public LdapConfiguration(final ConfigurationDao configDao,
+			final LdapManager ldapManager) {
+		_configDao = configDao;
+		_ldapManager = ldapManager;
+	}
+
+	public String getAuthentication() {
+		if ((getBindPrincipal() == null) && (getBindPassword() == null)) {
+			return "none";
+		} else {
+			return "simple";
+		}
+	}
+
+	public String getBaseDn() {
+		return _configDao.getValue("ldap.basedn");
+	}
+
+	public String getBindPassword() {
+		return _configDao.getValue("ldap.bind.password");
+	}
+
+	public String getBindPrincipal() {
+		return _configDao.getValue("ldap.bind.principal");
+	}
+
+	public String getEmailAttribute() {
+		final String emailAttribute = _configDao
+				.getValue("ldap.email.attribute");
+		return emailAttribute == null ? "mail" : emailAttribute;
+	}
+
+	public String getFactory() {
+		return factory;
+	}
+
+	public String getFirstnameAttribute() {
+		final String firstnameAttribute = _configDao
+				.getValue("ldap.firstname.attribute");
+		return firstnameAttribute == null ? "givenname" : firstnameAttribute;
+	}
+
+	public String getLastnameAttribute() {
+		final String lastnameAttribute = _configDao
+				.getValue("ldap.lastname.attribute");
+		return lastnameAttribute == null ? "sn" : lastnameAttribute;
+	}
+
+	public String getProviderUrl() {
+		final String protocol = getSSLStatus() == true ? "ldaps://" : "ldap://";
+		final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager
+				.listConfigurations(new LdapListConfigurationCmd(_ldapManager));
+		final StringBuilder providerUrls = new StringBuilder();
+		String delim = "";
+		for (final LdapConfigurationVO resource : result.first()) {
+			final String providerUrl = protocol + resource.getHostname() + ":"
+					+ resource.getPort();
+			providerUrls.append(delim).append(providerUrl);
+			delim = " ";
+		}
+		return providerUrls.toString();
+	}
+
+	public String[] getReturnAttributes() {
+		return new String[] { getUsernameAttribute(), getEmailAttribute(),
+				getFirstnameAttribute(), getLastnameAttribute() };
+	}
+
+	public int getScope() {
+		return scope;
+	}
+
+	public String getSearchGroupPrinciple() {
+		return _configDao.getValue("ldap.search.group.principle");
+	}
+
+	public boolean getSSLStatus() {
+		boolean sslStatus = false;
+		String dbValueForSSLStatus = _configDao.getValue("ldap.ssl.enabled");
+		if (dbValueForSSLStatus != null) {
+			sslStatus = dbValueForSSLStatus == "false" ? false : true;
+		}
+		if (getTrustStore() == null || getTrustStorePassword() == null) {
+			sslStatus = false;
+		}
+		return sslStatus;
+	}
+
+	public String getTrustStore() {
+		return _configDao.getValue("ldap.truststore");
+	}
+
+	public String getTrustStorePassword() {
+		return _configDao.getValue("ldap.truststore.password");
+	}
+
+	public String getUsernameAttribute() {
+		final String usernameAttribute = _configDao
+				.getValue("ldap.username.attribute");
+		return usernameAttribute == null ? "uid" : usernameAttribute;
+	}
+
+	public String getUserObject() {
+		final String userObject = _configDao.getValue("ldap.user.object");
+		return userObject == null ? "inetOrgPerson" : userObject;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
index 5a243f2..0b548f3 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
@@ -28,39 +28,39 @@ import org.apache.cloudstack.api.InternalIdentity;
 @Entity
 @Table(name = "ldap_configuration")
 public class LdapConfigurationVO implements InternalIdentity {
-    @Column(name = "hostname")
-    private String hostname;
+	@Column(name = "hostname")
+	private String hostname;
 
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @Column(name = "id")
-    private Long id;
+	@Id
+	@GeneratedValue(strategy = GenerationType.IDENTITY)
+	@Column(name = "id")
+	private Long id;
 
-    @Column(name = "port")
-    private int port;
+	@Column(name = "port")
+	private int port;
 
-    public LdapConfigurationVO() {
-    }
+	public LdapConfigurationVO() {
+	}
 
-    public LdapConfigurationVO(final String hostname, final int port) {
-        this.hostname = hostname;
-        this.port = port;
-    }
+	public LdapConfigurationVO(final String hostname, final int port) {
+		this.hostname = hostname;
+		this.port = port;
+	}
 
-    public String getHostname() {
-        return hostname;
-    }
+	public String getHostname() {
+		return hostname;
+	}
 
-    @Override
-    public long getId() {
-        return id;
-    }
+	@Override
+	public long getId() {
+		return id;
+	}
 
-    public int getPort() {
-        return port;
-    }
+	public int getPort() {
+		return port;
+	}
 
-    public void setId(long id) {
-        this.id = id;
-    }
+	public void setId(long id) {
+		this.id = id;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
index fd33e88..c971b70 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
@@ -27,77 +27,99 @@ import javax.naming.directory.InitialDirContext;
 import org.apache.log4j.Logger;
 
 public class LdapContextFactory {
-    private static final Logger s_logger = Logger.getLogger(LdapContextFactory.class.getName());
-
-    @Inject
-    private LdapConfiguration _ldapConfiguration;
-
-    public LdapContextFactory() {
-    }
-
-    public LdapContextFactory(final LdapConfiguration ldapConfiguration) {
-        _ldapConfiguration = ldapConfiguration;
-    }
-
-    public DirContext createBindContext() throws NamingException {
-        return createBindContext(null);
-    }
-
-    public DirContext createBindContext(final String providerUrl) throws NamingException {
-        final String bindPrincipal = _ldapConfiguration.getBindPrincipal();
-        final String bindPassword = _ldapConfiguration.getBindPassword();
-        return createInitialDirContext(bindPrincipal, bindPassword, providerUrl, true);
-    }
-
-    private DirContext createInitialDirContext(final String principal, final String password, final boolean isSystemContext) throws NamingException {
-        return createInitialDirContext(principal, password, null, isSystemContext);
-    }
-
-    private DirContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext) throws NamingException {
-        return new InitialDirContext(getEnvironment(principal, password, providerUrl, isSystemContext));
-    }
-
-    public DirContext createUserContext(final String principal, final String password) throws NamingException {
-        return createInitialDirContext(principal, password, false);
-    }
-
-    private Hashtable<String, String> getEnvironment(final String principal, final String password, final String providerUrl, final boolean isSystemContext) {
-        final String factory = _ldapConfiguration.getFactory();
-        final String url = providerUrl == null ? _ldapConfiguration.getProviderUrl() : providerUrl;
-        final String authentication = _ldapConfiguration.getAuthentication();
-
-        final Hashtable<String, String> environment = new Hashtable<String, String>();
-
-        environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
-        environment.put(Context.PROVIDER_URL, url);
-        environment.put("com.sun.jndi.ldap.read.timeout", "500");
-        environment.put("com.sun.jndi.ldap.connect.pool", "true");
-
-        if ("none".equals(authentication) && !isSystemContext) {
-            environment.put(Context.SECURITY_AUTHENTICATION, "simple");
-        } else {
-            environment.put(Context.SECURITY_AUTHENTICATION, authentication);
-        }
-
-        if (principal != null) {
-            environment.put(Context.SECURITY_PRINCIPAL, principal);
-        }
-
-        if (password != null) {
-            environment.put(Context.SECURITY_CREDENTIALS, password);
-        }
-
-        return environment;
-    }
-
-    public void testConnection(final String providerUrl) throws NamingException {
-        try {
-            createBindContext(providerUrl);
-            s_logger.info("LDAP Connection was successful");
-        } catch (final NamingException e) {
-            s_logger.warn("LDAP Connection failed");
-            s_logger.error(e.getMessage(), e);
-            throw e;
-        }
-    }
+	private static final Logger s_logger = Logger
+			.getLogger(LdapContextFactory.class.getName());
+
+	@Inject
+	private LdapConfiguration _ldapConfiguration;
+
+	public LdapContextFactory() {
+	}
+
+	public LdapContextFactory(final LdapConfiguration ldapConfiguration) {
+		_ldapConfiguration = ldapConfiguration;
+	}
+
+	public DirContext createBindContext() throws NamingException {
+		return createBindContext(null);
+	}
+
+	public DirContext createBindContext(final String providerUrl)
+			throws NamingException {
+		final String bindPrincipal = _ldapConfiguration.getBindPrincipal();
+		final String bindPassword = _ldapConfiguration.getBindPassword();
+		return createInitialDirContext(bindPrincipal, bindPassword,
+				providerUrl, true);
+	}
+
+	private DirContext createInitialDirContext(final String principal,
+			final String password, final boolean isSystemContext)
+			throws NamingException {
+		return createInitialDirContext(principal, password, null,
+				isSystemContext);
+	}
+
+	private DirContext createInitialDirContext(final String principal,
+			final String password, final String providerUrl,
+			final boolean isSystemContext) throws NamingException {
+		return new InitialDirContext(getEnvironment(principal, password,
+				providerUrl, isSystemContext));
+	}
+
+	public DirContext createUserContext(final String principal,
+			final String password) throws NamingException {
+		return createInitialDirContext(principal, password, false);
+	}
+
+	private Hashtable<String, String> getEnvironment(final String principal,
+			final String password, final String providerUrl,
+			final boolean isSystemContext) {
+		final String factory = _ldapConfiguration.getFactory();
+		final String url = providerUrl == null ? _ldapConfiguration
+				.getProviderUrl() : providerUrl;
+		final String authentication = _ldapConfiguration.getAuthentication();
+		final boolean sslStatus = _ldapConfiguration.getSSLStatus();
+
+		final Hashtable<String, String> environment = new Hashtable<String, String>();
+
+		environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
+		environment.put(Context.PROVIDER_URL, url);
+		environment.put("com.sun.jndi.ldap.read.timeout", "500");
+		environment.put("com.sun.jndi.ldap.connect.pool", "true");
+
+		if (sslStatus) {
+			environment.put(Context.SECURITY_PROTOCOL, "ssl");
+			System.setProperty("javax.net.ssl.trustStore",
+					_ldapConfiguration.getTrustStore());
+			System.setProperty("javax.net.ssl.trustStorePassword",
+					_ldapConfiguration.getTrustStorePassword());
+		}
+
+		if ("none".equals(authentication) && !isSystemContext) {
+			environment.put(Context.SECURITY_AUTHENTICATION, "simple");
+		} else {
+			environment.put(Context.SECURITY_AUTHENTICATION, authentication);
+		}
+
+		if (principal != null) {
+			environment.put(Context.SECURITY_PRINCIPAL, principal);
+		}
+
+		if (password != null) {
+			environment.put(Context.SECURITY_CREDENTIALS, password);
+		}
+
+		return environment;
+	}
+
+	public void testConnection(final String providerUrl) throws NamingException {
+		try {
+			createBindContext(providerUrl);
+			s_logger.info("LDAP Connection was successful");
+		} catch (final NamingException e) {
+			s_logger.warn("LDAP Connection failed");
+			s_logger.error(e.getMessage(), e);
+			throw e;
+		}
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
index aa0b751..eb4332d 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
@@ -30,21 +30,26 @@ import com.cloud.utils.component.PluggableService;
 
 public interface LdapManager extends PluggableService {
 
-    LdapConfigurationResponse addConfiguration(String hostname, int port) throws InvalidParameterValueException;
+	LdapConfigurationResponse addConfiguration(String hostname, int port)
+			throws InvalidParameterValueException;
 
-    boolean canAuthenticate(String username, String password);
+	boolean canAuthenticate(String username, String password);
 
-    LdapConfigurationResponse createLdapConfigurationResponse(LdapConfigurationVO configuration);
+	LdapConfigurationResponse createLdapConfigurationResponse(
+			LdapConfigurationVO configuration);
 
-    LdapUserResponse createLdapUserResponse(LdapUser user);
+	LdapUserResponse createLdapUserResponse(LdapUser user);
 
-    LdapConfigurationResponse deleteConfiguration(String hostname) throws InvalidParameterValueException;
+	LdapConfigurationResponse deleteConfiguration(String hostname)
+			throws InvalidParameterValueException;
 
-    LdapUser getUser(final String username) throws NamingException;
+	LdapUser getUser(final String username) throws NamingException;
 
-    List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException;
+	List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException;
 
-    Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(LdapListConfigurationCmd cmd);
+	Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(
+			LdapListConfigurationCmd cmd);
 
-    List<LdapUser> searchUsers(String query) throws NoLdapUserMatchingQueryException;
+	List<LdapUser> searchUsers(String query)
+			throws NoLdapUserMatchingQueryException;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java
index 5d73ce9..d358ae3 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java
@@ -24,9 +24,6 @@ import javax.inject.Inject;
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.LdapValidator;
 import org.apache.cloudstack.api.command.LdapAddConfigurationCmd;
 import org.apache.cloudstack.api.command.LdapCreateAccount;
@@ -37,6 +34,8 @@ import org.apache.cloudstack.api.command.LdapUserSearchCmd;
 import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.api.response.LdapUserResponse;
 import org.apache.cloudstack.ldap.dao.LdapConfigurationDao;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.utils.Pair;
@@ -44,168 +43,190 @@ import com.cloud.utils.Pair;
 @Component
 @Local(value = LdapManager.class)
 public class LdapManagerImpl implements LdapManager, LdapValidator {
-    private static final Logger s_logger = Logger.getLogger(LdapManagerImpl.class.getName());
-
-    @Inject
-    private LdapConfigurationDao _ldapConfigurationDao;
-
-    @Inject
-    private LdapContextFactory _ldapContextFactory;
-
-    @Inject
-    private LdapUserManager _ldapUserManager;
-
-    public LdapManagerImpl() {
-        super();
-    }
-
-    public LdapManagerImpl(final LdapConfigurationDao ldapConfigurationDao, final LdapContextFactory ldapContextFactory, final LdapUserManager ldapUserManager) {
-        super();
-        _ldapConfigurationDao = ldapConfigurationDao;
-        _ldapContextFactory = ldapContextFactory;
-        _ldapUserManager = ldapUserManager;
-    }
-
-    @Override
-    public LdapConfigurationResponse addConfiguration(final String hostname, final int port) throws InvalidParameterValueException {
-        LdapConfigurationVO configuration = _ldapConfigurationDao.findByHostname(hostname);
-        if (configuration == null) {
-            try {
-                final String providerUrl = "ldap://" + hostname + ":" + port;
-                _ldapContextFactory.createBindContext(providerUrl);
-                configuration = new LdapConfigurationVO(hostname, port);
-                _ldapConfigurationDao.persist(configuration);
-                s_logger.info("Added new ldap server with hostname: " + hostname);
-                return new LdapConfigurationResponse(hostname, port);
-            } catch (final NamingException e) {
-                throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
-            }
-        } else {
-            throw new InvalidParameterValueException("Duplicate configuration");
-        }
-    }
-
-    @Override
-    public boolean canAuthenticate(final String username, final String password) {
-        final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
-        try {
-            final LdapUser user = getUser(escapedUsername);
-            final String principal = user.getPrincipal();
-            final DirContext context = _ldapContextFactory.createUserContext(principal, password);
-            closeContext(context);
-            return true;
-        } catch (final NamingException e) {
-            s_logger.info("Failed to authenticate user: " + username + ". incorrect password.");
-            return false;
-        }
-    }
-
-    private void closeContext(final DirContext context) {
-        try {
-            if (context != null) {
-                context.close();
-            }
-        } catch (final NamingException e) {
-            s_logger.warn(e.getMessage());
-        }
-    }
-
-    @Override
-    public LdapConfigurationResponse createLdapConfigurationResponse(final LdapConfigurationVO configuration) {
-        final LdapConfigurationResponse response = new LdapConfigurationResponse();
-        response.setHostname(configuration.getHostname());
-        response.setPort(configuration.getPort());
-        return response;
-    }
-
-    @Override
-    public LdapUserResponse createLdapUserResponse(final LdapUser user) {
-        final LdapUserResponse response = new LdapUserResponse();
-        response.setUsername(user.getUsername());
-        response.setFirstname(user.getFirstname());
-        response.setLastname(user.getLastname());
-        response.setEmail(user.getEmail());
-        response.setPrincipal(user.getPrincipal());
-        return response;
-    }
-
-    @Override
-    public LdapConfigurationResponse deleteConfiguration(final String hostname) throws InvalidParameterValueException {
-        final LdapConfigurationVO configuration = _ldapConfigurationDao.findByHostname(hostname);
-        if (configuration == null) {
-            throw new InvalidParameterValueException("Cannot find configuration with hostname " + hostname);
-        } else {
-            _ldapConfigurationDao.remove(configuration.getId());
-            s_logger.info("Removed ldap server with hostname: " + hostname);
-            return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort());
-        }
-    }
-
-    @Override
-    public List<Class<?>> getCommands() {
-        final List<Class<?>> cmdList = new ArrayList<Class<?>>();
-        cmdList.add(LdapUserSearchCmd.class);
-        cmdList.add(LdapListAllUsersCmd.class);
-        cmdList.add(LdapAddConfigurationCmd.class);
-        cmdList.add(LdapDeleteConfigurationCmd.class);
-        cmdList.add(LdapListConfigurationCmd.class);
-        cmdList.add(LdapCreateAccount.class);
-        return cmdList;
-    }
-
-    @Override
-    public LdapUser getUser(final String username) throws NamingException {
-        DirContext context = null;
-        try {
-            context = _ldapContextFactory.createBindContext();
-
-            final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
-            return _ldapUserManager.getUser(escapedUsername, context);
-
-        } catch (final NamingException e) {
-            throw e;
-        } finally {
-            closeContext(context);
-        }
-    }
-
-    @Override
-    public List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException {
-        DirContext context = null;
-        try {
-            context = _ldapContextFactory.createBindContext();
-            return _ldapUserManager.getUsers(context);
-        } catch (final NamingException e) {
-            throw new NoLdapUserMatchingQueryException("*");
-        } finally {
-            closeContext(context);
-        }
-    }
-
-    @Override
-    public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(final LdapListConfigurationCmd cmd) {
-        final String hostname = cmd.getHostname();
-        final int port = cmd.getPort();
-        final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port);
-        return new Pair<List<? extends LdapConfigurationVO>, Integer>(result.first(), result.second());
-    }
-
-    @Override
-    public List<LdapUser> searchUsers(final String username) throws NoLdapUserMatchingQueryException {
-        DirContext context = null;
-        try {
-            context = _ldapContextFactory.createBindContext();
-            final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
-            return _ldapUserManager.getUsers("*" + escapedUsername + "*", context);
-        } catch (final NamingException e) {
-            throw new NoLdapUserMatchingQueryException(username);
-        } finally {
-            closeContext(context);
-        }
-    }
-
-    @Override
-    public boolean isLdapEnabled() {
-	return listConfigurations(new LdapListConfigurationCmd(this)).second() > 0;
-    }
+	private static final Logger s_logger = Logger
+			.getLogger(LdapManagerImpl.class.getName());
+
+	@Inject
+	private LdapConfigurationDao _ldapConfigurationDao;
+
+	@Inject
+	private LdapContextFactory _ldapContextFactory;
+
+	@Inject
+	private LdapUserManager _ldapUserManager;
+
+	public LdapManagerImpl() {
+		super();
+	}
+
+	public LdapManagerImpl(final LdapConfigurationDao ldapConfigurationDao,
+			final LdapContextFactory ldapContextFactory,
+			final LdapUserManager ldapUserManager) {
+		super();
+		_ldapConfigurationDao = ldapConfigurationDao;
+		_ldapContextFactory = ldapContextFactory;
+		_ldapUserManager = ldapUserManager;
+	}
+
+	@Override
+	public LdapConfigurationResponse addConfiguration(final String hostname,
+			final int port) throws InvalidParameterValueException {
+		LdapConfigurationVO configuration = _ldapConfigurationDao
+				.findByHostname(hostname);
+		if (configuration == null) {
+			try {
+				final String providerUrl = "ldap://" + hostname + ":" + port;
+				_ldapContextFactory.createBindContext(providerUrl);
+				configuration = new LdapConfigurationVO(hostname, port);
+				_ldapConfigurationDao.persist(configuration);
+				s_logger.info("Added new ldap server with hostname: "
+						+ hostname);
+				return new LdapConfigurationResponse(hostname, port);
+			} catch (final NamingException e) {
+				throw new InvalidParameterValueException(
+						"Unable to bind to the given LDAP server");
+			}
+		} else {
+			throw new InvalidParameterValueException("Duplicate configuration");
+		}
+	}
+
+	@Override
+	public boolean canAuthenticate(final String username, final String password) {
+		final String escapedUsername = LdapUtils
+				.escapeLDAPSearchFilter(username);
+		try {
+			final LdapUser user = getUser(escapedUsername);
+			final String principal = user.getPrincipal();
+			final DirContext context = _ldapContextFactory.createUserContext(
+					principal, password);
+			closeContext(context);
+			return true;
+		} catch (final NamingException e) {
+			s_logger.info("Failed to authenticate user: " + username
+					+ ". incorrect password.");
+			return false;
+		}
+	}
+
+	private void closeContext(final DirContext context) {
+		try {
+			if (context != null) {
+				context.close();
+			}
+		} catch (final NamingException e) {
+			s_logger.warn(e.getMessage());
+		}
+	}
+
+	@Override
+	public LdapConfigurationResponse createLdapConfigurationResponse(
+			final LdapConfigurationVO configuration) {
+		final LdapConfigurationResponse response = new LdapConfigurationResponse();
+		response.setHostname(configuration.getHostname());
+		response.setPort(configuration.getPort());
+		return response;
+	}
+
+	@Override
+	public LdapUserResponse createLdapUserResponse(final LdapUser user) {
+		final LdapUserResponse response = new LdapUserResponse();
+		response.setUsername(user.getUsername());
+		response.setFirstname(user.getFirstname());
+		response.setLastname(user.getLastname());
+		response.setEmail(user.getEmail());
+		response.setPrincipal(user.getPrincipal());
+		return response;
+	}
+
+	@Override
+	public LdapConfigurationResponse deleteConfiguration(final String hostname)
+			throws InvalidParameterValueException {
+		final LdapConfigurationVO configuration = _ldapConfigurationDao
+				.findByHostname(hostname);
+		if (configuration == null) {
+			throw new InvalidParameterValueException(
+					"Cannot find configuration with hostname " + hostname);
+		} else {
+			_ldapConfigurationDao.remove(configuration.getId());
+			s_logger.info("Removed ldap server with hostname: " + hostname);
+			return new LdapConfigurationResponse(configuration.getHostname(),
+					configuration.getPort());
+		}
+	}
+
+	@Override
+	public List<Class<?>> getCommands() {
+		final List<Class<?>> cmdList = new ArrayList<Class<?>>();
+		cmdList.add(LdapUserSearchCmd.class);
+		cmdList.add(LdapListAllUsersCmd.class);
+		cmdList.add(LdapAddConfigurationCmd.class);
+		cmdList.add(LdapDeleteConfigurationCmd.class);
+		cmdList.add(LdapListConfigurationCmd.class);
+		cmdList.add(LdapCreateAccount.class);
+		return cmdList;
+	}
+
+	@Override
+	public LdapUser getUser(final String username) throws NamingException {
+		DirContext context = null;
+		try {
+			context = _ldapContextFactory.createBindContext();
+
+			final String escapedUsername = LdapUtils
+					.escapeLDAPSearchFilter(username);
+			return _ldapUserManager.getUser(escapedUsername, context);
+
+		} catch (final NamingException e) {
+			throw e;
+		} finally {
+			closeContext(context);
+		}
+	}
+
+	@Override
+	public List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException {
+		DirContext context = null;
+		try {
+			context = _ldapContextFactory.createBindContext();
+			return _ldapUserManager.getUsers(context);
+		} catch (final NamingException e) {
+			throw new NoLdapUserMatchingQueryException("*");
+		} finally {
+			closeContext(context);
+		}
+	}
+
+	@Override
+	public boolean isLdapEnabled() {
+		return listConfigurations(new LdapListConfigurationCmd(this)).second() > 0;
+	}
+
+	@Override
+	public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(
+			final LdapListConfigurationCmd cmd) {
+		final String hostname = cmd.getHostname();
+		final int port = cmd.getPort();
+		final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao
+				.searchConfigurations(hostname, port);
+		return new Pair<List<? extends LdapConfigurationVO>, Integer>(
+				result.first(), result.second());
+	}
+
+	@Override
+	public List<LdapUser> searchUsers(final String username)
+			throws NoLdapUserMatchingQueryException {
+		DirContext context = null;
+		try {
+			context = _ldapContextFactory.createBindContext();
+			final String escapedUsername = LdapUtils
+					.escapeLDAPSearchFilter(username);
+			return _ldapUserManager.getUsers("*" + escapedUsername + "*",
+					context);
+		} catch (final NamingException e) {
+			throw new NoLdapUserMatchingQueryException(username);
+		} finally {
+			closeContext(context);
+		}
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00c17add/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUser.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUser.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUser.java
index 6bc1a78..18ad7d9 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUser.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUser.java
@@ -17,59 +17,61 @@
 package org.apache.cloudstack.ldap;
 
 public class LdapUser implements Comparable<LdapUser> {
-    private final String email;
-    private final String principal;
-    private final String firstname;
-    private final String lastname;
-    private final String username;
+	private final String email;
+	private final String principal;
+	private final String firstname;
+	private final String lastname;
+	private final String username;
 
-    public LdapUser(final String username, final String email, final String firstname, final String lastname, final String principal) {
-        this.username = username;
-        this.email = email;
-        this.firstname = firstname;
-        this.lastname = lastname;
-        this.principal = principal;
-    }
+	public LdapUser(final String username, final String email,
+			final String firstname, final String lastname,
+			final String principal) {
+		this.username = username;
+		this.email = email;
+		this.firstname = firstname;
+		this.lastname = lastname;
+		this.principal = principal;
+	}
 
-    @Override
-    public int compareTo(final LdapUser other) {
-        return getUsername().compareTo(other.getUsername());
-    }
+	@Override
+	public int compareTo(final LdapUser other) {
+		return getUsername().compareTo(other.getUsername());
+	}
 
-    @Override
-    public boolean equals(final Object other) {
-        if (this == other) {
-            return true;
-        }
-        if (other instanceof LdapUser) {
-            final LdapUser otherLdapUser = (LdapUser)other;
-            return getUsername().equals(otherLdapUser.getUsername());
-        }
-        return false;
-    }
+	@Override
+	public boolean equals(final Object other) {
+		if (this == other) {
+			return true;
+		}
+		if (other instanceof LdapUser) {
+			final LdapUser otherLdapUser = (LdapUser) other;
+			return getUsername().equals(otherLdapUser.getUsername());
+		}
+		return false;
+	}
 
-    public String getEmail() {
-        return email;
-    }
+	public String getEmail() {
+		return email;
+	}
 
-    public String getFirstname() {
-        return firstname;
-    }
+	public String getFirstname() {
+		return firstname;
+	}
 
-    public String getLastname() {
-        return lastname;
-    }
+	public String getLastname() {
+		return lastname;
+	}
 
-    public String getPrincipal() {
-        return principal;
-    }
+	public String getPrincipal() {
+		return principal;
+	}
 
-    public String getUsername() {
-        return username;
-    }
+	public String getUsername() {
+		return username;
+	}
 
-    @Override
-    public int hashCode() {
-        return getUsername().hashCode();
-    }
+	@Override
+	public int hashCode() {
+		return getUsername().hashCode();
+	}
 }
\ No newline at end of file


Mime
View raw message