cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject git commit: updated refs/heads/master to 5fa2d1c
Date Wed, 30 Jul 2014 06:33:02 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master fefb0028f -> 5fa2d1c7c


Fixed Bug: CLOUDSTACK-7200 [LDAP] importUsersCmd for a group fails incase any member of a
group is not an user


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

Branch: refs/heads/master
Commit: 5fa2d1c7ca26d199f0dcd499db8db245c2593a5b
Parents: fefb002
Author: Rajani Karuturi <rajanikaruturi@gmail.com>
Authored: Wed Jul 30 11:56:25 2014 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Wed Jul 30 12:02:24 2014 +0530

----------------------------------------------------------------------
 .../apache/cloudstack/ldap/LdapUserManager.java |  8 +++-
 .../cloudstack/ldap/LdapUserManagerSpec.groovy  | 45 ++++++++++++++++++--
 .../src/com/cloud/user/AccountManagerImpl.java  |  7 +--
 3 files changed, 52 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5fa2d1c7/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 afdf975..beff9db 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
@@ -30,8 +30,10 @@ import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 
 public class LdapUserManager {
+    private static final Logger s_logger = Logger.getLogger(LdapUserManager.class.getName());
 
     @Inject
     private LdapConfiguration _ldapConfiguration;
@@ -155,7 +157,11 @@ public class LdapUserManager {
 
             while (values.hasMoreElements()) {
                 String userdn = String.valueOf(values.nextElement());
-                users.add(getUserForDn(userdn, context));
+                try{
+                    users.add(getUserForDn(userdn, context));
+                } catch (NamingException e){
+                    s_logger.info("Userdn: " + userdn + " Not Found:: Exception message:
" + e.getMessage());
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5fa2d1c7/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy
b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy
index 9fbc81f..c8edb3f 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy
@@ -48,7 +48,7 @@ class LdapUserManagerSpec extends spock.lang.Specification {
     @Shared
     private def principal
 
-    private def createGroupSearchContext() {
+    private def createGroupSearchContextOneUser() {
 
         def umSearchResult = Mock(SearchResult)
         umSearchResult.getName() >> principal;
@@ -75,7 +75,34 @@ class LdapUserManagerSpec extends spock.lang.Specification {
         searchUsersResults.add(userSearchResult);
 
         def context = Mock(LdapContext)
-        context.search(_, _, _) >>> [searchGroupResults, searchUsersResults];
+        context.search(_, _, _) >>> [searchGroupResults, searchUsersResults, searchGroupResults,
new BasicNamingEnumerationImpl()];
+
+        return context
+    }
+
+    private def createGroupSearchContextNoUser() {
+
+        def umSearchResult = Mock(SearchResult)
+        umSearchResult.getName() >> principal;
+        umSearchResult.getAttributes() >> principal
+
+        def uniqueMembers = new BasicNamingEnumerationImpl()
+        uniqueMembers.add(umSearchResult);
+        def attributes = Mock(Attributes)
+        def uniqueMemberAttribute = Mock(Attribute)
+        uniqueMemberAttribute.getId() >> "uniquemember"
+        uniqueMemberAttribute.getAll() >> uniqueMembers
+        attributes.get("uniquemember") >> uniqueMemberAttribute
+
+        def groupSearchResult = Mock(SearchResult)
+        groupSearchResult.getName() >> principal;
+        groupSearchResult.getAttributes() >> attributes
+
+        def searchGroupResults = new BasicNamingEnumerationImpl()
+        searchGroupResults.add(groupSearchResult);
+
+        def context = Mock(LdapContext)
+        context.search(_, _, _) >>> [searchGroupResults, new BasicNamingEnumerationImpl()];
 
         return context
     }
@@ -254,16 +281,26 @@ class LdapUserManagerSpec extends spock.lang.Specification {
         varGroupName << ["", null, "Murphy"]
     }
 
-    def "test successful getUsersInGroup"() {
+    def "test successful getUsersInGroup one user"() {
         given: "ldap user manager and ldap config"
         def ldapUserManager = new LdapUserManager(ldapConfiguration)
 
         when: "A request for users is made"
-        def result = ldapUserManager.getUsersInGroup("engineering", createGroupSearchContext())
+        def result = ldapUserManager.getUsersInGroup("engineering", createGroupSearchContextOneUser())
         then: "one user is returned"
         result.size() == 1
     }
 
+    def "test successful getUsersInGroup no user"() {
+        given: "ldap user manager and ldap config"
+        def ldapUserManager = new LdapUserManager(ldapConfiguration)
+
+        when: "A request for users is made"
+        def result = ldapUserManager.getUsersInGroup("engineering", createGroupSearchContextNoUser())
+        then: "no user is returned"
+        result.size() == 0
+    }
+
     def "test successful getUserForDn"() {
         given: "ldap user manager and ldap config"
         def ldapUserManager = new LdapUserManager(ldapConfiguration)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5fa2d1c7/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 75a97bc..11876fa 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -39,6 +39,7 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.acl.ControlledEntity;
@@ -989,15 +990,15 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
             domainId = Domain.ROOT_DOMAIN;
         }
 
-        if (userName.isEmpty()) {
+        if (StringUtils.isEmpty(userName)) {
             throw new InvalidParameterValueException("Username is empty");
         }
 
-        if (firstName.isEmpty()) {
+        if (StringUtils.isEmpty(firstName)) {
             throw new InvalidParameterValueException("Firstname is empty");
         }
 
-        if (lastName.isEmpty()) {
+        if (StringUtils.isEmpty(lastName)) {
             throw new InvalidParameterValueException("Lastname is empty");
         }
 


Mime
View raw message