cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject git commit: updated refs/heads/ldapplugin to c6e9617
Date Thu, 25 Jul 2013 03:49:21 GMT
Updated Branches:
  refs/heads/ldapplugin 7bc705e9e -> c6e9617e2


General clean up of LDAP plugin

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/c6e9617e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c6e9617e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c6e9617e

Branch: refs/heads/ldapplugin
Commit: c6e9617e209987147531a5aa10189a606b938c3e
Parents: 7bc705e
Author: Ian Duffy <ian@ianduffy.ie>
Authored: Wed Jul 24 11:21:22 2013 +0100
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Wed Jul 24 20:59:09 2013 +0530

----------------------------------------------------------------------
 .../api/command/LdapAddConfigurationCmd.java    |  9 +---
 .../api/command/LdapDeleteConfigurationCmd.java | 19 +--------
 .../api/command/LdapListAllUsersCmd.java        | 27 ++++++------
 .../api/command/LdapListConfigurationCmd.java   | 39 +++++++----------
 .../api/command/LdapUserSearchCmd.java          | 44 ++++++++------------
 .../api/response/LdapConfigurationResponse.java |  1 +
 .../api/response/LdapUserResponse.java          |  1 +
 .../cloudstack/ldap/LdapAuthenticator.java      |  6 ++-
 .../cloudstack/ldap/LdapConfiguration.java      | 23 ++++------
 .../cloudstack/ldap/LdapConfigurationVO.java    | 14 ++-----
 .../cloudstack/ldap/LdapContextFactory.java     | 20 ++++-----
 .../apache/cloudstack/ldap/LdapManagerImpl.java | 14 +++----
 .../apache/cloudstack/ldap/LdapUserManager.java | 12 +++---
 .../org/apache/cloudstack/ldap/LdapUtils.java   | 39 +++++++++--------
 .../ldap/LdapConfigurationSpec.groovy           | 15 -------
 .../cloudstack/ldap/LdapConfigurationVO.groovy  | 36 +++++-----------
 .../ldap/LdapDeleteConfigurationCmdSpec.groovy  | 10 -----
 .../ldap/LdapListConfigurationCmdSpec.groovy    |  2 +-
 .../ldap/LdapSearchUserCmdSpec.groovy           | 12 +-----
 19 files changed, 121 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 62736b1..2a7ebc2 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
@@ -12,11 +12,7 @@ import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.ldap.LdapManager;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
 
 @APICommand(name = "addLdapConfiguration", description = "Add a new Ldap Configuration",
responseObject = LdapConfigurationResponse.class, since = "4.2.0")
 public class LdapAddConfigurationCmd extends BaseCmd {
@@ -42,10 +38,9 @@ public class LdapAddConfigurationCmd extends BaseCmd {
     }
 
     @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException {
+    public void execute() throws ServerApiException {
         try {
-            final LdapConfigurationResponse response = _ldapManager.addConfiguration(getHostname(),
getPort());
+            final LdapConfigurationResponse response = _ldapManager.addConfiguration(hostname,
port);
             response.setObjectName("LdapAddConfiguration");
             response.setResponseName(getCommandName());
             setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 329b91b..714ea8b 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
@@ -28,11 +28,7 @@ import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.LdapConfigurationResponse;
 import org.apache.cloudstack.ldap.LdapManager;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
 
 @APICommand(name = "deleteLdapConfiguration", description = "Remove an Ldap Configuration",
responseObject = LdapConfigurationResponse.class, since = "4.2.0")
 public class LdapDeleteConfigurationCmd extends BaseCmd {
@@ -55,11 +51,9 @@ public class LdapDeleteConfigurationCmd extends BaseCmd {
     }
 
     @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException {
-
+    public void execute() throws ServerApiException {
         try {
-            final LdapConfigurationResponse response = _ldapManager.deleteConfiguration(getHostname());
+            final LdapConfigurationResponse response = _ldapManager.deleteConfiguration(hostname);
             response.setObjectName("LdapDeleteConfiguration");
             response.setResponseName(getCommandName());
             setResponseObject(response);
@@ -78,13 +72,4 @@ public class LdapDeleteConfigurationCmd extends BaseCmd {
     public long getEntityOwnerId() {
         return 0;
     }
-
-    public String getHostname() {
-        return hostname;
-    }
-
-    public void setHostname(final String hostname) {
-        this.hostname = hostname;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 087d156..bad9ce1 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
@@ -33,11 +33,6 @@ import org.apache.cloudstack.ldap.LdapManager;
 import org.apache.cloudstack.ldap.LdapUser;
 import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-
 @APICommand(name = "listAllLdapUsers", responseObject = LdapUserResponse.class, description
= "Lists all LDAP Users", since = "4.2.0")
 public class LdapListAllUsersCmd extends BaseListCmd {
 
@@ -56,19 +51,11 @@ public class LdapListAllUsersCmd extends BaseListCmd {
     }
 
     @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException {
+    public void execute() throws ServerApiException {
         try {
             final List<LdapUser> users = _ldapManager.getUsers();
             final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
-            final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
-
-            for (final LdapUser user : users) {
-                final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
-                ldapResponse.setObjectName("LdapUser");
-                ldapResponses.add(ldapResponse);
-            }
-
+            final List<LdapUserResponse> ldapResponses = createLdapUserResponse(users);
             response.setResponses(ldapResponses);
             response.setResponseName(getCommandName());
             setResponseObject(response);
@@ -77,6 +64,16 @@ public class LdapListAllUsersCmd extends BaseListCmd {
         }
     }
 
+    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 String getCommandName() {
         return s_name;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 6707878..82022ca 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
@@ -24,20 +24,13 @@ 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.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
 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 com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.utils.Pair;
 
 @APICommand(name = "listLdapConfigurations", responseObject = LdapConfigurationResponse.class,
description = "Lists all LDAP configurations", since = "4.2.0")
@@ -64,24 +57,24 @@ public class LdapListConfigurationCmd extends BaseListCmd {
         _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() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException
{
+    public void execute() {
         final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(this);
-        if (result.second() > 0) {
-            final ListResponse<LdapConfigurationResponse> response = new ListResponse<LdapConfigurationResponse>();
-            final List<LdapConfigurationResponse> responses = new ArrayList<LdapConfigurationResponse>();
-            for (final LdapConfigurationVO resource : result.first()) {
-                final LdapConfigurationResponse configurationResponse = _ldapManager.createLdapConfigurationResponse(resource);
-                configurationResponse.setObjectName("LdapConfiguration");
-                responses.add(configurationResponse);
-            }
-            response.setResponses(responses, result.second());
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find any
LDAP Configurations");
-        }
+        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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 e6a40d0..1244bd0 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
@@ -24,21 +24,14 @@ 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.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.LdapUserResponse;
 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 com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-
 @APICommand(name = "searchLdap", responseObject = LdapUserResponse.class, description = "Searches
LDAP based on the username attribute", since = "4.2.0")
 public class LdapUserSearchCmd extends BaseListCmd {
 
@@ -60,26 +53,33 @@ public class LdapUserSearchCmd extends BaseListCmd {
     }
 
     @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException {
+    public void execute() {
+        final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
+        List<LdapUser> users = null;
+
         try {
-            final List<LdapUser> users = _ldapManager.searchUsers(getQuery());
+            users = _ldapManager.searchUsers(query);
+        } catch (final NoLdapUserMatchingQueryException e) {
+            s_logger.debug(e.getMessage());
+        }
+
+        final List<LdapUserResponse> ldapUserResponses = createLdapUserResponse(users);
 
-            final ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
-            final List<LdapUserResponse> ldapUserResponses = new ArrayList<LdapUserResponse>();
+        response.setResponses(ldapUserResponses);
+        response.setResponseName(getCommandName());
+        setResponseObject(response);
+    }
 
+    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);
             }
-
-            response.setResponses(ldapUserResponses);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } catch (final NoLdapUserMatchingQueryException e) {
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
         }
+        return ldapUserResponses;
     }
 
     @Override
@@ -91,12 +91,4 @@ public class LdapUserSearchCmd extends BaseListCmd {
     public long getEntityOwnerId() {
         return 0;
     }
-
-    public String getQuery() {
-        return query;
-    }
-
-    public void setQuery(final String query) {
-        this.query = query;
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 d583346..a4e4782 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
@@ -36,6 +36,7 @@ public class LdapConfigurationResponse extends BaseResponse {
     }
 
     public LdapConfigurationResponse(final String hostname) {
+        super();
         this.hostname = hostname;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 40ba0ce..a6d5ddd 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
@@ -44,6 +44,7 @@ public class LdapUserResponse extends BaseResponse {
     }
 
     public LdapUserResponse(final String username, final String email, final String realname,
final String principal) {
+        super();
         this.username = username;
         this.email = email;
         this.realname = realname;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 2916202..7791eff 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
@@ -54,13 +54,17 @@ public class LdapAuthenticator extends DefaultUserAuthenticator {
         if (user == null) {
             s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
             return false;
-        } else if (_ldapManager.listConfigurations(new LdapListConfigurationCmd(_ldapManager)).second()
> 0) {
+        } else if (isLdapConfigurationPresent()) {
             return _ldapManager.canAuthenticate(username, password);
         } else {
             return false;
         }
     }
 
+    private boolean isLdapConfigurationPresent() {
+        return _ldapManager.listConfigurations(new LdapListConfigurationCmd(_ldapManager)).second()
> 0;
+    }
+
     @Override
     public String encode(final String password) {
         return password;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 8f31ce5..a015000 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
@@ -21,8 +21,6 @@ import java.util.List;
 import javax.inject.Inject;
 import javax.naming.directory.SearchControls;
 
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.LdapListConfigurationCmd;
 
 import com.cloud.configuration.dao.ConfigurationDao;
@@ -77,20 +75,15 @@ public class LdapConfiguration {
     }
 
     public String getProviderUrl() {
-        final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager
-                .listConfigurations(new LdapListConfigurationCmd(_ldapManager));
-        if (result.second() > 0) {
-            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();
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to get Ldap
Configuration(s)");
+        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 getRealnameAttribute() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 d3ff820..762f6bc 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
@@ -56,19 +56,11 @@ public class LdapConfigurationVO implements InternalIdentity {
         return id;
     }
 
-    public int getPort() {
-        return port;
-    }
-
-    public void setHostname(final String hostname) {
-        this.hostname = hostname;
-    }
-
-    public void setId(final long id) {
+    public void setId(long id) {
         this.id = id;
     }
 
-    public void setPort(final int port) {
-        this.port = port;
+    public int getPort() {
+        return port;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 30bdc5b..fd33e88 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
@@ -21,8 +21,8 @@ import java.util.Hashtable;
 import javax.inject.Inject;
 import javax.naming.Context;
 import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
 
 import org.apache.log4j.Logger;
 
@@ -39,27 +39,25 @@ public class LdapContextFactory {
         _ldapConfiguration = ldapConfiguration;
     }
 
-    public LdapContext createBindContext() throws NamingException {
+    public DirContext createBindContext() throws NamingException {
         return createBindContext(null);
     }
 
-    public LdapContext createBindContext(final String providerUrl) throws NamingException
{
+    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 LdapContext createInitialDirContext(final String principal, final String password,
final boolean isSystemContext)
-            throws NamingException {
+    private DirContext createInitialDirContext(final String principal, final String password,
final boolean isSystemContext) throws NamingException {
         return createInitialDirContext(principal, password, null, isSystemContext);
     }
 
-    private LdapContext createInitialDirContext(final String principal, final String password,
final String providerUrl, final boolean isSystemContext)
-            throws NamingException {
-        return new InitialLdapContext(getEnvironment(principal, password, providerUrl, isSystemContext),
null);
+    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 LdapContext createUserContext(final String principal, final String password) throws
NamingException {
+    public DirContext createUserContext(final String principal, final String password) throws
NamingException {
         return createInitialDirContext(principal, password, false);
     }
 
@@ -72,7 +70,7 @@ public class LdapContextFactory {
 
         environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
         environment.put(Context.PROVIDER_URL, url);
-        environment.put("com.sun.jndi.ldap.read.timeout", "1000");
+        environment.put("com.sun.jndi.ldap.read.timeout", "500");
         environment.put("com.sun.jndi.ldap.connect.pool", "true");
 
         if ("none".equals(authentication) && !isSystemContext) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/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 be9b3d5..9417542 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
@@ -22,7 +22,7 @@ import java.util.List;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
+import javax.naming.directory.DirContext;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -89,16 +89,16 @@ public class LdapManagerImpl implements LdapManager {
         try {
             final LdapUser user = getUser(escapedUsername);
             final String principal = user.getPrincipal();
-            final LdapContext context = _ldapContextFactory.createUserContext(principal,
password);
+            final DirContext context = _ldapContextFactory.createUserContext(principal, password);
             closeContext(context);
             return true;
         } catch (final NamingException e) {
-            s_logger.info("Failed to authenticate user: " + username + ". incorrent password.");
+            s_logger.info("Failed to authenticate user: " + username + ". incorrect password.");
             return false;
         }
     }
 
-    private void closeContext(final LdapContext context) {
+    private void closeContext(final DirContext context) {
         try {
             if (context != null) {
                 context.close();
@@ -150,7 +150,7 @@ public class LdapManagerImpl implements LdapManager {
     }
 
     public LdapUser getUser(final String username) throws NamingException {
-        LdapContext context = null;
+        DirContext context = null;
         try {
             context = _ldapContextFactory.createBindContext();
 
@@ -166,7 +166,7 @@ public class LdapManagerImpl implements LdapManager {
 
     @Override
     public List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException {
-        LdapContext context = null;
+        DirContext context = null;
         try {
             context = _ldapContextFactory.createBindContext();
             return _ldapUserManager.getUsers(context);
@@ -187,7 +187,7 @@ public class LdapManagerImpl implements LdapManager {
 
     @Override
     public List<LdapUser> searchUsers(final String username) throws NoLdapUserMatchingQueryException
{
-        LdapContext context = null;
+        DirContext context = null;
         try {
             context = _ldapContextFactory.createBindContext();
             final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
index 54802cf..8fd9d26 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
@@ -24,9 +24,9 @@ import javax.inject.Inject;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
-import javax.naming.ldap.LdapContext;
 
 public class LdapUserManager {
 
@@ -51,7 +51,7 @@ public class LdapUserManager {
         return new LdapUser(username, email, realname, principal);
     }
 
-    public LdapUser getUser(final String username, final LdapContext context) throws NamingException
{
+    public LdapUser getUser(final String username, final DirContext context) throws NamingException
{
         final NamingEnumeration<SearchResult> result = searchUsers(username, context);
         if (result.hasMoreElements()) {
             return createUser(result.nextElement());
@@ -60,11 +60,11 @@ public class LdapUserManager {
         }
     }
 
-    public List<LdapUser> getUsers(final LdapContext context) throws NamingException
{
+    public List<LdapUser> getUsers(final DirContext context) throws NamingException
{
         return getUsers(null, context);
     }
 
-    public List<LdapUser> getUsers(final String username, final LdapContext context)
throws NamingException {
+    public List<LdapUser> getUsers(final String username, final DirContext context)
throws NamingException {
         final NamingEnumeration<SearchResult> results = searchUsers(username, context);
 
         final List<LdapUser> users = new ArrayList<LdapUser>();
@@ -79,11 +79,11 @@ public class LdapUserManager {
         return users;
     }
 
-    public NamingEnumeration<SearchResult> searchUsers(final LdapContext context) throws
NamingException {
+    public NamingEnumeration<SearchResult> searchUsers(final DirContext context) throws
NamingException {
         return searchUsers(null, context);
     }
 
-    public NamingEnumeration<SearchResult> searchUsers(final String username, final
LdapContext context) throws NamingException {
+    public NamingEnumeration<SearchResult> searchUsers(final String username, final
DirContext context) throws NamingException {
         final SearchControls controls = new SearchControls();
 
         controls.setSearchScope(_ldapConfiguration.getScope());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
index 453dc0a..e572128 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
@@ -21,28 +21,30 @@ import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
 public final class LdapUtils {
+    private LdapUtils() {
+    }
 
     public static String escapeLDAPSearchFilter(final String filter) {
         final StringBuilder sb = new StringBuilder();
         for (char character : filter.toCharArray()) {
             switch (character) {
-            case '\\':
-                sb.append("\\5c");
-                break;
-            case '*':
-                sb.append("\\2a");
-                break;
-            case '(':
-                sb.append("\\28");
-                break;
-            case ')':
-                sb.append("\\29");
-                break;
-            case '\u0000':
-                sb.append("\\00");
-                break;
-            default:
-                sb.append(character);
+                case '\\':
+                    sb.append("\\5c");
+                    break;
+                case '*':
+                    sb.append("\\2a");
+                    break;
+                case '(':
+                    sb.append("\\28");
+                    break;
+                case ')':
+                    sb.append("\\29");
+                    break;
+                case '\u0000':
+                    sb.append("\\00");
+                    break;
+                default:
+                    sb.append(character);
             }
         }
         return sb.toString();
@@ -56,7 +58,4 @@ public final class LdapUtils {
         }
         return null;
     }
-
-    private LdapUtils() {
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
index 91c9baf..b474948 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
@@ -46,21 +46,6 @@ class LdapConfigurationSpec extends spock.lang.Specification {
         providerUrl == "ldap://localhost:389"
     }
 
-    def "Test that exception is thrown when no configuration is found"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        def ldapManager = Mock(LdapManager)
-        List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
-        Pair<List<LdapConfigurationVO>, Integer> result = new Pair<List<LdapConfigurationVO>,
Integer>();
-        result.set(ldapConfigurationList, ldapConfigurationList.size())
-        ldapManager.listConfigurations(_) >> result
-        LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        ldapConfiguration.getProviderUrl()
-        then:
-        thrown ServerApiException
-    }
-
     def "Test that getAuthentication returns simple"() {
         given:
         def configDao = Mock(ConfigurationDao)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVO.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVO.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVO.groovy
index 8135901..27f3dfc 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVO.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVO.groovy
@@ -20,33 +20,17 @@ import org.apache.cloudstack.ldap.LdapConfigurationVO
 
 
 class LdapConfigurationVOSpec extends spock.lang.Specification {
-    def "Testing that the hostname is correctly set with the LDAP configuration VO"() {
-        given: "You have created a LDAP configuration VO with a hostname set"
-        def configuration = new LdapConfigurationVO()
-        configuration.setHostname(hostname)
-        expect: "The hostname is equal to the given data source"
+    def "Testing that the ID hostname and port is correctly set within the LDAP configuration
VO"() {
+        given: "You have created an LDAP Configuration VO"
+        def configuration = new LdapConfigurationVO(hostname, port)
+        configuration.setId(id)
+        expect: "The id hostname and port is equal to the given data source"
+        configuration.getId() == id
         configuration.getHostname() == hostname
-        where: "The hostname is set to "
-        hostname << ["", null, "localhost"]
-    }
-
-    def "Testing that the port is correctly set within the LDAP configuration VO"() {
-        given: "You have created a LDAP configuration VO with a port set"
-        def configuration = new LdapConfigurationVO()
-        configuration.setPort(port)
-        expect: "The port is equal to the given data source"
         configuration.getPort() == port
-        where: "The port is set to "
-        port << [0, 1000, -1000, -0]
-    }
-
-    def "Testing that the ID is correctly set within the LDAP configuration VO"() {
-        given: "You have created an LDAP Configuration VO"
-        def configuration = new LdapConfigurationVO("localhost", 389);
-        configuration.setId(id);
-        expect: "The id is equal to the given data source"
-        configuration.getId() == id;
-        where: "The id is set to "
-        id << [0, 1000, -1000, -0]
+        where: "The id, hostname and port is set to "
+        hostname << ["", null, "localhost"]
+        id << [0, 1000, -1000]
+        port << [0, 1000, -1000]
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
index 664fd64..2a5e2b4 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
@@ -46,16 +46,6 @@ class LdapDeleteConfigurationCmdSpec extends spock.lang.Specification {
         thrown ServerApiException
     }
 
-    def "Test successful setting of hostname"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
-        when:
-        ldapDeleteConfigurationCmd.setHostname("localhost")
-        then:
-        ldapDeleteConfigurationCmd.getHostname() == "localhost"
-    }
-
     def "Test getEntityOwnerId is 0"() {
         given:
         def ldapManager = Mock(LdapManager)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
index a7c1979..039d886 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
@@ -55,7 +55,7 @@ class LdapListConfigurationCmdSpec extends spock.lang.Specification {
         when:
         ldapListConfigurationCmd.execute()
         then:
-        thrown ServerApiException
+        ldapListConfigurationCmd.getResponseObject().getResponses().size() == 0
     }
 
     def "Test successful setting of hostname"() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6e9617e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy
index d72878b..eeff2cc 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy
@@ -47,7 +47,7 @@ class LdapSearchUserCmdSpec extends spock.lang.Specification {
         when:
         ldapUserSearchCmd.execute()
         then:
-        thrown ServerApiException
+        ldapUserSearchCmd.responseObject.getResponses().size() == 0
     }
 
     def "Test getEntityOwnerId is 0"() {
@@ -60,16 +60,6 @@ class LdapSearchUserCmdSpec extends spock.lang.Specification {
         ownerId == 0
     }
 
-    def "Test successful setting of ldapUserSearchCmd Query"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapUserSearchCmd = new LdapUserSearchCmd(ldapManager)
-        when:
-        ldapUserSearchCmd.setQuery("")
-        then:
-        ldapUserSearchCmd.getQuery() == ""
-    }
-
     def "Test successful return of getCommandName"() {
         given:
         def ldapManager = Mock(LdapManager)


Mime
View raw message