]> source.dussan.org Git - archiva.git/commitdiff
implements those methods with ldap call
authorOlivier Lamy <olamy@apache.org>
Mon, 21 Jan 2013 16:36:10 +0000 (16:36 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 21 Jan 2013 16:36:10 +0000 (16:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1436466 13f79535-47bb-0310-9956-ffa450edef68

redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java

index 4ac0fd64eb7c59c1aa7b70401fc769b7e81b9786..230091bbf7e9a25223631eb6b060d103b43fe9b4 100644 (file)
@@ -982,22 +982,46 @@ public class LdapRbacManager
             closeContext( context );
             closeLdapConnection( ldapConnection );
         }
-
-        //this.rbacImpl.saveUserAssignment( userAssignment );
-
-        //return userAssignment;
     }
 
     public boolean userAssignmentExists( String principal )
     {
-        // TODO here
-        return this.rbacImpl.userAssignmentExists( principal );
+        LdapConnection ldapConnection = null;
+        DirContext context = null;
+        try
+        {
+            ldapConnection = ldapConnectionFactory.getConnection();
+            context = ldapConnection.getDirContext();
+            List<String> roles = ldapRoleMapper.getRoles( principal, context );
+            if ( roles == null || roles.isEmpty() )
+            {
+                return false;
+            }
+            return true;
+        }
+        catch ( LdapException e )
+        {
+            log.warn( "fail to call userAssignmentExists: {}", e.getMessage() );
+        }
+        catch ( MappingException e )
+        {
+            log.warn( "fail to call userAssignmentExists: {}", e.getMessage() );
+        }
+        finally
+        {
+            closeContext( context );
+            closeLdapConnection( ldapConnection );
+        }
+        return false;
     }
 
     public boolean userAssignmentExists( UserAssignment assignment )
     {
-        // TODO here
-        return this.rbacImpl.userAssignmentExists( assignment );
+        if ( assignment == null )
+        {
+            return false;
+        }
+        return this.userAssignmentExists( assignment.getPrincipal() );
     }
 
     public RBACManager getRbacImpl()