portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r929034 [1/2] - in /portals/jetspeed-2/portal/trunk: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/ components/jetspeed-...
Date Tue, 30 Mar 2010 08:17:56 GMT
Author: ate
Date: Tue Mar 30 08:17:56 2010
New Revision: 929034

URL: http://svn.apache.org/viewvc?rev=929034&view=rev
Log:
JS2-1136: Cleanup and strengthening the Security Entity/LDAP mapping
- much further optimalization of (amount of) LDAP access operations
- untangle from Spring LDAP "wrapper" inefficiencies
- several bugs fixed
- cleanout of unused / outdated interfaces and implementations
- start of separate relationship (attributes) handling -> next step

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java   (with props)
Removed:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/SearchUtil.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/EntityDAO.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/EntityRelationDAO.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/DefaultEntityRelationSearch.java
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/LDAPEntityDAOConfiguration.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityFactory.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java Tue Mar 30 08:17:56 2010
@@ -16,10 +16,9 @@
  */
 package org.apache.jetspeed.security.mapping;
 
-import javax.naming.directory.DirContext;
-
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.mapping.model.Entity;
+import org.springframework.ldap.core.DirContextOperations;
 
 /**
  * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
@@ -34,5 +33,5 @@ public interface EntityFactory
     
     Entity createEntity(JetspeedPrincipal principal);
 
-    Entity createEntity(DirContext ctx);
+    Entity createEntity(DirContextOperations ctx);
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java Tue Mar 30 08:17:56 2010
@@ -23,7 +23,6 @@ import java.util.Set;
 
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
 
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.SecurityAttribute;
@@ -36,6 +35,9 @@ import org.apache.jetspeed.security.mapp
 import org.apache.jetspeed.security.mapping.model.Entity;
 import org.apache.jetspeed.security.mapping.model.impl.AttributeImpl;
 import org.apache.jetspeed.security.mapping.model.impl.EntityImpl;
+import org.springframework.ldap.core.DirContextOperations;
+import org.springframework.ldap.core.DistinguishedName;
+import org.springframework.ldap.core.LdapRdn;
 import org.springframework.ldap.support.LdapUtils;
 
 /**
@@ -58,7 +60,7 @@ public class EntityFactoryImpl implement
 
     protected EntityImpl internalCreateEntity(String entityId, String internalId, Set<Attribute> attributes)
     {
-        EntityImpl entity = new EntityImpl(searchConfiguration.getEntityType(), entityId, searchConfiguration.getAttributeDefinitions());
+        EntityImpl entity = new EntityImpl(searchConfiguration.getEntityType(), entityId, searchConfiguration.getAttributeDefinitionsMap());
         entity.setAttributes(attributes);
         if (internalId != null)
         {
@@ -71,7 +73,7 @@ public class EntityFactoryImpl implement
     {
         Set<Attribute> ldapAttrValues = new HashSet<Attribute>();
         SecurityAttributes sas = principal.getSecurityAttributes();
-        for (AttributeDef attrDef : searchConfiguration.getAttributeDefinitions())
+        for (AttributeDef attrDef : searchConfiguration.getEntityAttributeDefinitionsMap().values())
         {
             SecurityAttribute sa = sas.getAttribute(attrDef.getMappedName());
             if (sa != null)
@@ -111,65 +113,75 @@ public class EntityFactoryImpl implement
         return attributes;
     }
     
-    public Entity createEntity(DirContext ctx)
+    public Entity createEntity(DirContextOperations ctx)
     {
-        try
+        String entityId = null;
+        Entity entity = null;
+        String dn = ctx.getNameInNamespace();
+        Set<Attribute> attributes = new HashSet<Attribute>();
+        Attributes attrs = ctx.getAttributes();
+        for (AttributeDef attrDef : searchConfiguration.getEntityAttributeDefinitionsMap().values())
         {
-            String entityId = null;
-            Entity entity = null;
-            String dn = ctx.getNameInNamespace();
-            Set<Attribute> attributes = new HashSet<Attribute>();
-            Attributes attrs = ctx.getAttributes("", searchConfiguration.getAttributeNames());
-            for (AttributeDef attrDef : searchConfiguration.getAttributeDefinitions())
+            List<String> values = null;
+            values = getStringAttributes(attrs, attrDef.getName());
+            if (values != null)
             {
-                List<String> values = null;
-                values = getStringAttributes(attrs, attrDef.getName());
-                if (values != null)
+                Attribute a = new AttributeImpl(attrDef);
+                if (attrDef.isMultiValue())
                 {
-                    Attribute a = new AttributeImpl(attrDef);
-                    if (attrDef.isMultiValue())
+                        
+                    // remove the dummy value for required fields when present.
+                    if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null)
                     {
-                        // remove the dummy value for required fields when present.
-                        if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null)
+                        String defaultValue = attrDef.getRequiredDefaultValue();
+                        if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(defaultValue))
                         {
-                            String defaultValue = attrDef.getRequiredDefaultValue();
-                            if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(defaultValue))
-                            {
-                                defaultValue = dn;
-                            }
-                            if (values.contains(defaultValue))
-                            {
-                                values.remove(attrDef.getRequiredDefaultValue());
-                            }
+                            defaultValue = dn;
                         }
-                        if (values.size() != 0)
+                        if (values.contains(defaultValue))
                         {
-                            a.setValues(values);
-                        }
-                        else
-                        {
-                            attributes.add(a);
+                            values.remove(attrDef.getRequiredDefaultValue());
                         }
                     }
+                        
+                    if (values.size() != 0)
+                    {
+                        a.setValues(values);
+                    }
+                        
                     else
                     {
-                        String value = values.get(0);
-                        // TODO: make this a boolean flag check
-                        if (attrDef.getName().equals(searchConfiguration.getLdapIdAttribute()))
-                        {
-                            entityId = value;
-                        }
-                        a.setValue(value);
+                        attributes.add(a);
+                    }                        
+                }
+                else
+                {
+                    String value = values.get(0);
+                    if (attrDef.isIdAttributeName())
+                    {
+                        entityId = value;
                     }
-                    attributes.add(a);
+                    a.setValue(value);
                 }
+                attributes.add(a);
             }
-            entity = internalCreateEntity(entityId, dn, attributes);
-            return entity;
         }
-        catch (NamingException e)
+        if (entityId == null)
         {
-            throw LdapUtils.convertLdapException(e);
+            DistinguishedName name = new DistinguishedName(dn);            
+            LdapRdn rdn = name.getLdapRdn(name.size()-1);
+            if (rdn.getKey().equals(searchConfiguration.getLdapIdAttribute()))
+            {
+                entityId = rdn.getValue();
+            }
+            else
+            {
+                // TODO: throw exception???
+                return null;
+            }
         }
+        entity = internalCreateEntity(entityId, dn, attributes);
+        entity.setLive(true);
+        return entity;
     }
 }

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java?rev=929034&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java Tue Mar 30 08:17:56 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.dao;
+
+import javax.naming.Binding;
+import javax.naming.NameClassPair;
+
+import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
+
+/**
+ * @version $Id$
+ *
+ */
+public class CollectingBindingsCallbackHandler extends CollectingNameClassPairCallbackHandler
+{
+    /* (non-Javadoc)
+     * @see org.springframework.ldap.core.CollectingNameClassPairCallbackHandler#getObjectFromNameClassPair(javax.naming.NameClassPair)
+     */
+    @Override
+    public Object getObjectFromNameClassPair(NameClassPair nameClassPair)
+    {
+        if (!(nameClassPair instanceof Binding)) {
+            throw new IllegalArgumentException("Parameter must be an instance of Binding");
+        }
+        return nameClassPair;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java Tue Mar 30 08:17:56 2010
@@ -17,14 +17,16 @@
 package org.apache.jetspeed.security.mapping.ldap.dao;
 
 import org.apache.jetspeed.security.mapping.EntityFactory;
+import org.apache.jetspeed.security.mapping.model.Entity;
 import org.springframework.ldap.core.DirContextOperations;
-import org.springframework.ldap.core.support.AbstractContextMapper;
+import org.springframework.ldap.core.simple.AbstractParameterizedContextMapper;
 
 /**
  * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
  * @version $Id$
+ * @param <T>
  */
-public class DefaultEntityContextMapper extends AbstractContextMapper
+public class DefaultEntityContextMapper extends AbstractParameterizedContextMapper<Entity> implements EntityContextMapper
 {
     EntityFactory entityFactory;
 
@@ -32,9 +34,14 @@ public class DefaultEntityContextMapper 
     {
         this.entityFactory = entityFactory;
     }
+    
+    public EntityFactory getEntityFactory()
+    {
+        return entityFactory;
+    }
 
     @Override
-    public Object doMapFromContext(DirContextOperations ctx)
+    protected Entity doMapFromContext(DirContextOperations ctx)
     {
         return entityFactory.createEntity(ctx);
     }

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java?rev=929034&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java Tue Mar 30 08:17:56 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.dao;
+
+import org.apache.jetspeed.security.mapping.EntityFactory;
+import org.apache.jetspeed.security.mapping.model.Entity;
+import org.springframework.ldap.core.simple.ParameterizedContextMapper;
+
+/**
+ * @version $Id$
+ *
+ */
+public interface EntityContextMapper extends ParameterizedContextMapper<Entity>
+{
+    EntityFactory getEntityFactory();
+}
\ No newline at end of file

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/LDAPEntityDAOConfiguration.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/LDAPEntityDAOConfiguration.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/LDAPEntityDAOConfiguration.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/LDAPEntityDAOConfiguration.java Tue Mar 30 08:17:56 2010
@@ -16,10 +16,13 @@
  */
 package org.apache.jetspeed.security.mapping.ldap.dao;
 
-import java.util.Set;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.security.mapping.model.AttributeDef;
+import org.springframework.ldap.core.DistinguishedName;
 import org.springframework.ldap.filter.Filter;
 
 /**
@@ -28,21 +31,39 @@ import org.springframework.ldap.filter.F
  */
 public class LDAPEntityDAOConfiguration
 {
-    private String            baseDN;
-    private String            searchDN;
-    private Filter            baseFilter;
-    private String            ldapIdAttribute;
-    private Set<AttributeDef> attributeDefinitions;
-    private String            entityType;
-    private String[]          objectClassesArr;
-    private String[]          attributeNames;
+    private DistinguishedName         baseDN = new DistinguishedName().immutableDistinguishedName();
+    private DistinguishedName         searchDN = new DistinguishedName().immutableDistinguishedName();
+    private Filter                    baseFilter;
+    private String                    ldapIdAttribute;
+    private Map<String, AttributeDef> attributeDefinitions;
+    private Map<String, AttributeDef> entityAttributeDefinitions;
+    private String                    entityType;
+    private String[]                  objectClassesArr;
+    private String[]                  entityAttributeNames;
 
     public void initialize() throws JetspeedException
     {
         checkNotEmpty("entityType", entityType);
-        checkNotNull("baseDN", baseDN);
         checkNotEmpty("ldapIdAttribute", ldapIdAttribute);
         checkNotNull("attributeDefinitions", attributeDefinitions);
+        boolean idAttributeNameFound = false;
+        for (AttributeDef def : attributeDefinitions.values())
+        {
+            if (ldapIdAttribute.equals(def.getName()))
+            {
+                if (def.isMultiValue() || !def.isRequired() || def.isRelationOnly())
+                {
+                    throw new RuntimeException("Unsupported ldapIdAttribute Attribute definition: multi-value, optional and/or relationOnly attribute");
+                }
+                def.setIdAttributeName(true);
+                idAttributeNameFound = true;
+                break;
+            }
+        }
+        if (!idAttributeNameFound)
+        {
+            throw new RuntimeException("No ldapIdAttribute Attribute definition provided");
+        }
     }
 
     private void checkNotNull(String fieldName, Object fieldValue) throws JetspeedException
@@ -61,24 +82,24 @@ public class LDAPEntityDAOConfiguration
         }
     }
 
-    public String getBaseDN()
+    public DistinguishedName getBaseDN()
     {
         return baseDN;
     }
 
-    public void setBaseDN(String baseDN)
+    public void setLdapBase(String ldapBase)
     {
-        this.baseDN = baseDN;
+        this.baseDN = new DistinguishedName(ldapBase).immutableDistinguishedName();
     }
 
-    public String getSearchDN()
+    public DistinguishedName getSearchDN()
     {
         return searchDN;
     }
 
-    public void setSearchDN(String searchDN)
+    public void setSearchBase(String searchBase)
     {
-        this.searchDN = searchDN;
+        this.searchDN = new DistinguishedName(searchBase).immutableDistinguishedName();
     }
 
     public Filter getSearchFilter()
@@ -91,25 +112,39 @@ public class LDAPEntityDAOConfiguration
         this.baseFilter = baseFilter;
     }
 
-    public Set<AttributeDef> getAttributeDefinitions()
+    public Map<String, AttributeDef> getAttributeDefinitionsMap()
+    {
+        return attributeDefinitions;
+    }
+
+    public Map<String, AttributeDef> getEntityAttributeDefinitionsMap()
     {
         return attributeDefinitions;
     }
 
-    public void setAttributeDefinitions(Set<AttributeDef> attributeDefinitions)
+    public AttributeDef getAttributeDef(String name)
+    {
+        return attributeDefinitions.get(name);
+    }
+
+    public void setAttributeDefinitions(Collection<AttributeDef> attributeDefinitions)
     {
-        this.attributeDefinitions = attributeDefinitions;
-        attributeNames = new String[attributeDefinitions.size()];
-        int i = 0;
+        this.attributeDefinitions = new HashMap<String, AttributeDef>();
+        this.entityAttributeDefinitions = new HashMap<String, AttributeDef>();
         for (AttributeDef def : attributeDefinitions)
         {
-            attributeNames[i++] = def.getName();
+            if (!def.isRelationOnly())
+            {
+                this.entityAttributeDefinitions.put(def.getName(), def);
+            }
+            this.attributeDefinitions.put(def.getName(), def);
         }
+        entityAttributeNames = entityAttributeDefinitions.keySet().toArray(new String[0]);
     }
-    
-    public String[] getAttributeNames()
+
+    public String[] getEntityAttributeNames()
     {
-        return attributeNames;
+        return entityAttributeNames;
     }
 
     public String getLdapIdAttribute()

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java Tue Mar 30 08:17:56 2010
@@ -19,10 +19,13 @@ package org.apache.jetspeed.security.map
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
-import javax.naming.InvalidNameException;
+import javax.naming.Binding;
 import javax.naming.Name;
+import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
@@ -31,19 +34,22 @@ import org.apache.commons.lang.StringUti
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.mapping.EntityFactory;
 import org.apache.jetspeed.security.mapping.ldap.EntityFactoryImpl;
+import org.apache.jetspeed.security.mapping.ldap.dao.CollectingBindingsCallbackHandler;
+import org.apache.jetspeed.security.mapping.ldap.dao.EntityContextMapper;
 import org.apache.jetspeed.security.mapping.ldap.dao.DefaultEntityContextMapper;
 import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
 import org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
-import org.apache.jetspeed.security.mapping.ldap.dao.SearchUtil;
-import org.apache.jetspeed.security.mapping.ldap.filter.SimpleFilter;
 import org.apache.jetspeed.security.mapping.model.Attribute;
 import org.apache.jetspeed.security.mapping.model.AttributeDef;
 import org.apache.jetspeed.security.mapping.model.Entity;
-import org.springframework.ldap.core.ContextMapper;
-import org.springframework.ldap.core.DirContextAdapter;
+import org.springframework.ldap.NameAlreadyBoundException;
+import org.springframework.ldap.NameNotFoundException;
 import org.springframework.ldap.core.DirContextOperations;
+import org.springframework.ldap.core.DirContextProcessor;
 import org.springframework.ldap.core.DistinguishedName;
 import org.springframework.ldap.core.LdapTemplate;
+import org.springframework.ldap.core.simple.SimpleLdapTemplate;
+import org.springframework.ldap.filter.AndFilter;
 import org.springframework.ldap.filter.EqualsFilter;
 import org.springframework.ldap.filter.Filter;
 import org.springframework.ldap.filter.OrFilter;
@@ -60,25 +66,26 @@ public class SpringLDAPEntityDAO impleme
     {
         MAPPED, INTERNAL, ALL
     };
+    
+    private static final DirContextProcessor nullDirContextProcessor = new DirContextProcessor()
+    {
+        public void postProcess(DirContext ctx) throws javax.naming.NamingException{}
+        public void preProcess(DirContext ctx) throws javax.naming.NamingException{}
+    };
 
-    protected LdapTemplate                     ldapTemplate;
-    protected final LDAPEntityDAOConfiguration configuration;
-    protected final DistinguishedName          searchDN;
-    protected ContextMapper                    contextMapper;
-    protected EntityFactory                    entityFactory;
+    private final LDAPEntityDAOConfiguration configuration;
+    private final EntityFactory              entityFactory;
+    private EntityContextMapper              contextMapper;
+    private LdapTemplate                     ldapTemplate;
+    private SimpleLdapTemplate               simpleLdapTemplate;
+    private String                           defaultSearchFilterStr;
 
     public SpringLDAPEntityDAO(LDAPEntityDAOConfiguration configuration)
     {
-        super();
         this.configuration = configuration;
-        searchDN = new DistinguishedName(getConfiguration().getSearchDN());
         this.entityFactory = new EntityFactoryImpl(configuration);
         this.contextMapper = new DefaultEntityContextMapper(entityFactory);
-    }
-
-    public void initialize(LdapTemplate ldapTemplate)
-    {
-        this.ldapTemplate = ldapTemplate;
+        this.defaultSearchFilterStr = createSearchFilter(null);
     }
 
     public LDAPEntityDAOConfiguration getConfiguration()
@@ -86,7 +93,7 @@ public class SpringLDAPEntityDAO impleme
         return configuration;
     }
 
-    public ContextMapper getContextMapper()
+    protected EntityContextMapper getContextMapper()
     {
         return contextMapper;
     }
@@ -100,21 +107,68 @@ public class SpringLDAPEntityDAO impleme
     {
         return entityFactory;
     }
+    
+    public void setEntityContextMapper(EntityContextMapper contextMapper)
+    {
+        this.contextMapper = contextMapper;
+    }
 
-    public void setLdapTemplate(LdapTemplate ldapTemplate)
+    public void setLdapTemplate(SimpleLdapTemplate simpleLdapTemplate)
     {
-        this.ldapTemplate = ldapTemplate;
+        this.simpleLdapTemplate = simpleLdapTemplate;
+        this.ldapTemplate = (LdapTemplate)simpleLdapTemplate.getLdapOperations();
     }
 
-    public void setContextMapper(ContextMapper contextMapper)
+    public Collection<Entity> getEntities(Filter filter)
     {
-        this.contextMapper = contextMapper;
+        String filterStr = createSearchFilter(filter);
+        Collection<Entity> results = null;
+        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+            results = simpleLdapTemplate.search(configuration.getSearchDN(), filterStr, 
+                                                getSearchControls(SearchControls.SUBTREE_SCOPE, true,configuration.getEntityAttributeNames()), 
+                                                getContextMapper(), nullDirContextProcessor);
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(currentClassLoader);
+        }
+        return results;
+    }
+
+    public Collection<Entity> getEntities(Entity parent, Filter filter)
+    {
+        String filterStr = createSearchFilter(filter);
+        Collection<Entity> results = null;
+        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+        DistinguishedName parentDN = getRelativeDN(parent.getInternalId());
+        if (configuration.getSearchDN().size() == 0 || parentDN.endsWith(configuration.getSearchDN()))
+        {
+            try
+            {
+                Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+                results = simpleLdapTemplate.search(parentDN, filterStr, 
+                                                    getSearchControls(SearchControls.ONELEVEL_SCOPE, true,configuration.getEntityAttributeNames()), 
+                                                    getContextMapper(), nullDirContextProcessor);
+                            }
+            finally
+            {
+                Thread.currentThread().setContextClassLoader(currentClassLoader);
+            }
+        }
+        return results;
+    }
+
+    public Collection<Entity> getAllEntities()
+    {
+        return getEntities(null);
     }
 
     public Entity getEntity(String entityId)
     {
-        Filter idFilter = createFilterForIdSearch(entityId);
-        Collection<Entity> entities = getEntities(idFilter);
+        Collection<Entity> entities = getEntities(new EqualsFilter(configuration.getLdapIdAttribute(), entityId));
         if (entities != null && entities.size() == 1)
         {
             return entities.iterator().next();
@@ -124,48 +178,32 @@ public class SpringLDAPEntityDAO impleme
 
     public Collection<Entity> getEntitiesById(Collection<String> entityIds)
     {
-        OrFilter idFilter = new OrFilter();
+        OrFilter filter = new OrFilter();
         String idAttr = configuration.getLdapIdAttribute();
         for (String id : entityIds)
         {
-            idFilter.or(new EqualsFilter(idAttr, id));
-        }
-        Filter filter = idFilter;
-        if (configuration.getSearchFilter() != null)
-        {
-            filter = SearchUtil.andFilters(idFilter, configuration.getSearchFilter());
+            filter.or(new EqualsFilter(idAttr, id));
         }
         return getEntities(filter);
     }
 
-    public Collection<Entity> getEntitiesByInternalId(Collection<String> internalIds)
-    {
-        final Collection<Entity> resultSet = new ArrayList<Entity>();
-        for (Iterator<String> iterator = internalIds.iterator(); iterator.hasNext();)
-        {
-            Entity resultEntity = getEntityByInternalId(iterator.next());
-            if (resultEntity != null)
-            {
-                resultSet.add(resultEntity);
-            }
-        }
-        return resultSet;
-    }
-
     public Entity getEntityByInternalId(String internalId)
     {
         Entity resultEntity = null;
         DistinguishedName principalDN = getRelativeDN(internalId);
-        String relativeDN = principalDN.toCompactString();
-        String searchDNStr = searchDN.toCompactString();
-        if (relativeDN.equals(searchDNStr) || relativeDN.endsWith(searchDNStr))
+        if (configuration.getSearchDN().size() == 0 || principalDN.endsWith(configuration.getSearchDN()))
         {
-            internalId = relativeDN;
             ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
             try
             {
                 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-                resultEntity = (Entity) ldapTemplate.lookup(internalId, getContextMapper());
+                List<Entity> result = simpleLdapTemplate.search(principalDN, defaultSearchFilterStr, 
+                                                                getSearchControls(SearchControls.OBJECT_SCOPE, true, configuration.getEntityAttributeNames()), 
+                                                                getContextMapper(), nullDirContextProcessor);
+                if (!result.isEmpty())
+                {
+                    resultEntity = result.get(0);
+                }
             }
             finally
             {
@@ -174,6 +212,20 @@ public class SpringLDAPEntityDAO impleme
         }
         return resultEntity;
     }
+    
+    public Collection<Entity> getEntitiesByInternalId(Collection<String> internalIds)
+    {
+        final Collection<Entity> resultSet = new ArrayList<Entity>();
+        for (Iterator<String> iterator = internalIds.iterator(); iterator.hasNext();)
+        {
+            Entity resultEntity = getEntityByInternalId(iterator.next());
+            if (resultEntity != null)
+            {
+                resultSet.add(resultEntity);
+            }
+        }
+        return resultSet;
+    }
 
     public Entity getParentEntity(Entity childEntity)
     {
@@ -182,128 +234,81 @@ public class SpringLDAPEntityDAO impleme
         return getEntityByInternalId(parentDN.encode());
     }
 
-    protected DistinguishedName getRelativeDN(String fullDN)
-    {
-        DistinguishedName principalDN = new DistinguishedName(fullDN);
-        if (configuration.getBaseDN() != null && configuration.getBaseDN().length() > 0)
-        {
-            principalDN.removeFirst(new DistinguishedName(configuration.getBaseDN()));
-        }
-        return principalDN;
-    }
-
-    protected String getFullDN(DistinguishedName relativeDN)
-    {        
-        String fullDN = relativeDN.toCompactString();
-        if (configuration.getBaseDN() != null && configuration.getBaseDN().length() > 0 && !fullDN.endsWith(configuration.getBaseDN()))
-        {
-            return fullDN + "," + configuration.getBaseDN();
-        }
-        return fullDN;
-    }
-
-    protected String createSearchFilter(Filter filter)
+    protected String getInternalId(Entity entity)
     {
-        if (configuration.getSearchFilter() != null)
+        if (entity.getInternalId() != null)
         {
-            if (filter == null)
-            {
-                filter = configuration.getSearchFilter();
-            }
-            else
-            {
-                filter = SearchUtil.andFilters(configuration.getSearchFilter(), filter);
-            }
+            return entity.getInternalId();
         }
-        String filterStr = filter.encode();
-        if (StringUtils.isEmpty(filterStr))
-        {
-            filterStr = "(objectClass=*)"; // trivial search query
-        }
-        return filterStr;
-    }
-
-    @SuppressWarnings("unchecked")
-    public Collection<Entity> getEntities(Filter filter)
-    {
-        String filterStr = createSearchFilter(filter);
-        Collection<Entity> results = null;
+        String filterStr = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entity.getId()));
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            results = ldapTemplate.search(configuration.getSearchDN(), filterStr, SearchControls.SUBTREE_SCOPE, getContextMapper());
+            CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
+            ldapTemplate.search(configuration.getSearchDN(), filterStr, getSearchControls(SearchControls.SUBTREE_SCOPE, false, new String[0]), handler);
+            if (handler.getList().isEmpty() || handler.getList().size() != 1)
+            {
+                return null;
+            }
+            return ((Binding)handler.getList().get(0)).getNameInNamespace();
         }
         finally
         {
             Thread.currentThread().setContextClassLoader(currentClassLoader);
-        }
-        return results;
+        }            
     }
-
-    @SuppressWarnings("unchecked")
-    public Collection<Entity> getEntities(Entity parent, Filter filter)
+    
+    public DirContextOperations getEntityContext(Entity entity, boolean withAttributes)
     {
-        String filterStr = createSearchFilter(filter);
-        Collection<Entity> results = null;
+        if (entity.getInternalId() != null)
+        {
+            return getEntityContext(entity.getInternalId(), withAttributes);
+        }
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            results = ldapTemplate.search(getRelativeDN(parent.getInternalId()), filterStr, SearchControls.ONELEVEL_SCOPE, getContextMapper());
+            CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
+            ldapTemplate.search(configuration.getSearchDN(), createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entity.getId())),
+                                getSearchControls(SearchControls.SUBTREE_SCOPE, true, withAttributes ? configuration.getEntityAttributeNames() : new String[0]), 
+                                handler);
+            if (!handler.getList().isEmpty() && handler.getList().size() == 1)
+            {
+                return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
+            }
         }
         finally
         {
             Thread.currentThread().setContextClassLoader(currentClassLoader);
         }
-        return results;
-    }
-
-    public Collection<Entity> getAllEntities()
-    {
-        final String finalFilter = configuration.getSearchFilter() != null ? configuration.getSearchFilter().encode() : "(objectClass=*)";
-        return getEntities(new SimpleFilter(finalFilter));
+        return null;
     }
 
-    private void internalUpdate(Entity entity, UpdateMode umode) throws SecurityException
+    public DirContextOperations getEntityContext(String internalId, boolean withAttributes)
     {
-        String internalId = entity.getInternalId();
-        if (internalId == null)
+        DistinguishedName principalDN = getRelativeDN(internalId);
+        if (configuration.getSearchDN().size() == 0 || principalDN.endsWith(configuration.getSearchDN()))
         {
-            Entity ldapEntity = getEntity(entity.getId());
-            if (ldapEntity == null || ldapEntity.getInternalId() == null)
+            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+            try
             {
-                throw new SecurityException(SecurityException.PRINCIPAL_UPDATE_FAILURE.createScoped(entity.getType(), entity.getId()));
+                Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+                CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
+                ldapTemplate.search(principalDN, createSearchFilter(null),
+                                    getSearchControls(SearchControls.OBJECT_SCOPE, true, withAttributes ? configuration.getEntityAttributeNames() : new String[0]), 
+                                    handler);
+                if (!handler.getList().isEmpty())
+                {
+                    return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
+                }
+            }
+            finally
+            {
+                Thread.currentThread().setContextClassLoader(currentClassLoader);
             }
-            internalId = ldapEntity.getInternalId();
-            entity.setInternalId(internalId);
-        }
-        Name dn = getRelativeDN(internalId);
-        DirContextOperations dirCtxOps = null;
-        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
-        try
-        {
-            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            dirCtxOps = ldapTemplate.lookupContext(dn);
-        }
-        finally
-        {
-            Thread.currentThread().setContextClassLoader(currentClassLoader);
-        }
-        if (dirCtxOps == null)
-        {
-            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(entity.getType(), entity.getId()));
-        }
-        Collection<ModificationItem> modItems = getModItems(entity, dirCtxOps, umode);
-        try
-        {
-            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[] {}));
-        }
-        finally
-        {
-            Thread.currentThread().setContextClassLoader(currentClassLoader);
         }
+        return null;
     }
 
     public void add(Entity entity, Entity parentEntity) throws SecurityException
@@ -320,34 +325,20 @@ public class SpringLDAPEntityDAO impleme
 
     public void add(Entity entity) throws SecurityException
     {
-        DistinguishedName dn = new DistinguishedName();
-        if (configuration.getSearchDN() != null && configuration.getSearchDN().length() > 0)
-        {
-            try
-            {
-                dn.addAll(new DistinguishedName(configuration.getSearchDN()));
-            }
-            catch (InvalidNameException inex)
-            {
-                throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "add(Entity entity)", inex));
-            }
-        }
-        internalAdd(entity, dn);
+        // add entity to "root" searchDN
+        internalAdd(entity, new DistinguishedName(configuration.getSearchDN()));
     }
 
     public void internalAdd(Entity entity, DistinguishedName dn) throws SecurityException
     {
-        if (entityExists(entity))
-        {
-            throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
-        }
-        DirContextAdapter context = new DirContextAdapter();
+        Attributes attributes = new BasicAttributes();
         if (dn != null)
         {
             dn.add(configuration.getLdapIdAttribute(), entity.getId());
-            for (AttributeDef attrDef : configuration.getAttributeDefinitions())
+            String fullDN = null;
+            for (AttributeDef attrDef : configuration.getAttributeDefinitionsMap().values())
             {
-                Attribute entityAttr = entity.getAttribute(attrDef.getName());
+                Attribute entityAttr = attrDef.isRelationOnly() ? null : entity.getAttribute(attrDef.getName());
                 BasicAttribute basicAttr = null;
                 if (entityAttr != null)
                 {
@@ -384,7 +375,11 @@ public class SpringLDAPEntityDAO impleme
                             basicAttr = new BasicAttribute(attrDef.getName());
                             if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(requiredValue))
                             {
-                                basicAttr.add(getFullDN(dn));
+                                if (fullDN == null)
+                                {
+                                    fullDN = getFullDN(dn).encode();
+                                }
+                                basicAttr.add(fullDN);
                             }
                             else
                             {
@@ -399,7 +394,7 @@ public class SpringLDAPEntityDAO impleme
                 }
                 if (basicAttr != null)
                 {
-                    context.setAttribute(basicAttr);
+                    attributes.put(basicAttr);
                 }
             }
             BasicAttribute attr = new BasicAttribute("objectClass");
@@ -407,12 +402,16 @@ public class SpringLDAPEntityDAO impleme
             {
                 attr.add(objClass);
             }
-            context.setAttribute(attr);
+            attributes.put(attr);
             ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
             try
             {
                 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-                ldapTemplate.bind(dn, context, null);
+                ldapTemplate.bind(dn, null, attributes);
+            }
+            catch (NameAlreadyBoundException e)
+            {
+                throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
             }
             finally
             {
@@ -421,33 +420,33 @@ public class SpringLDAPEntityDAO impleme
         }
     }
 
-    public void remove(Entity entity) throws SecurityException
+    public void update(Entity entity) throws SecurityException
     {
-        if (!entityExists(entity))
-        {
-            // cannot assume external security systems like LDAP which are not solely under the control of the Portal to be 100% in sync.
-            // removal of no longer existing entity therefore should not be considered an error.
-            return;
-        }
-        String internalIdStr = entity.getInternalId();
-        if (internalIdStr == null)
+        internalUpdate(entity, UpdateMode.MAPPED);
+    }
+
+    public void updateInternalAttributes(Entity entity) throws SecurityException
+    {
+        internalUpdate(entity, UpdateMode.INTERNAL);
+    }
+    
+    
+    protected void internalUpdate(Entity entity, UpdateMode umode) throws SecurityException
+    {
+        DirContextOperations dirCtxOps = getEntityContext(entity, true);
+        if (dirCtxOps == null)
         {
-            Entity ldapEntity = getEntity(entity.getId());
-            if (ldapEntity == null || ldapEntity.getInternalId() == null)
-            {
-                // TODO throw exception
-                return;
-            }
-            else
-            {
-                internalIdStr = ldapEntity.getInternalId();
-            }
+            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(entity.getType(), entity.getId()));
         }
+        String internalId = dirCtxOps.getNameInNamespace();
+        Name dn = getRelativeDN(internalId);
+        
+        Collection<ModificationItem> modItems = getModItems(entity, dirCtxOps, umode);
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            ldapTemplate.unbind(getRelativeDN(internalIdStr));
+            ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[] {}));
         }
         finally
         {
@@ -455,53 +454,53 @@ public class SpringLDAPEntityDAO impleme
         }
     }
 
-    public void update(Entity entity) throws SecurityException
+    public void remove(Entity entity) throws SecurityException
     {
-        internalUpdate(entity, UpdateMode.MAPPED);
+        String internalId = getInternalId(entity);
+        if (internalId == null)
+        {
+            // not found
+            return;
+        }
+        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+            ldapTemplate.unbind(getRelativeDN(internalId));
+        }
+        catch (NameNotFoundException e)
+        {
+            // ignore
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(currentClassLoader);
+        }
     }
 
-    public void updateInternalAttributes(Entity entity) throws SecurityException
+    public void addRelation(String entityId, String relatedEntityId, String attributeName)
     {
-        internalUpdate(entity, UpdateMode.INTERNAL);
+        // TODO
     }
 
-    protected boolean entityExists(Entity entity)
+    public void removeRelation(String EntityId, String relatedEntityId, String attributeName)
     {
-        return getEntity(entity.getId()) != null;
+        // TODO
     }
-
-    protected boolean setNamingAttribute(Attribute entityAttr, DirContextOperations dirCtxOps)
+    
+    protected SearchControls getSearchControls(int searchScope, boolean returningObjFlag, String[] attrs) 
     {
-        boolean attrAdded = false;
-        if (entityAttr != null)
-        {
-            AttributeDef attrDef = entityAttr.getDefinition();
-            if (attrDef.isMultiValue())
-            {
-                Collection<String> values = entityAttr.getValues();
-                if (values != null)
-                {
-                    dirCtxOps.setAttributeValues(attrDef.getName(), values.toArray());
-                    attrAdded = true;
-                }
-            }
-            else
-            {
-                String value = entityAttr.getValue();
-                if (value != null)
-                {
-                    dirCtxOps.setAttributeValue(attrDef.getName(), value);
-                    attrAdded = true;
-                }
-            }
-        }
-        return attrAdded;
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope(searchScope);
+        controls.setReturningObjFlag(returningObjFlag);
+        controls.setReturningAttributes(attrs);
+        return controls;
     }
 
     protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, UpdateMode umode)
     {
         Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
-        for (AttributeDef attrDef : configuration.getAttributeDefinitions())
+        for (AttributeDef attrDef : configuration.getEntityAttributeDefinitionsMap().values())
         {
             if (!attrDef.getName().equals(configuration.getLdapIdAttribute()))
             {
@@ -577,8 +576,44 @@ public class SpringLDAPEntityDAO impleme
         return modItems;
     }
 
-    protected Filter createFilterForIdSearch(String entityId)
+    protected DistinguishedName getRelativeDN(String fullDN)
     {
-        return SearchUtil.constructMatchingFieldsFilter(configuration.getSearchFilter(), new String[] { configuration.getLdapIdAttribute(), entityId });
+        DistinguishedName principalDN = new DistinguishedName(fullDN);
+        if (configuration.getBaseDN().size() > 0)
+        {
+            principalDN.removeFirst(configuration.getBaseDN());
+        }
+        return principalDN;
+    }
+
+    protected DistinguishedName getFullDN(DistinguishedName relativeDN)
+    {        
+        DistinguishedName fullDN = new DistinguishedName(relativeDN);
+        if (configuration.getBaseDN().size() > 0 && !fullDN.endsWith(configuration.getBaseDN()))
+        {
+            fullDN.prepend(configuration.getBaseDN());
+        }
+        return fullDN;
+    }
+
+    protected String createSearchFilter(Filter filter)
+    {
+        if (configuration.getSearchFilter() != null)
+        {
+            if (filter == null)
+            {
+                filter = configuration.getSearchFilter();
+            }
+            else
+            {
+                filter = new AndFilter().and(configuration.getSearchFilter()).and(filter);
+            }
+        }
+        String filterStr = filter != null ? filter.encode() : "";
+        if (StringUtils.isEmpty(filterStr))
+        {
+            filterStr = "(objectClass=*)"; // trivial search query
+        }
+        return filterStr;
     }
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java Tue Mar 30 08:17:56 2010
@@ -35,4 +35,10 @@ public interface AttributeDef
     String getRequiredDefaultValue();
 
     boolean isIdAttribute();
+    
+    boolean isRelationOnly();
+    
+    boolean isIdAttributeName();
+    
+    void setIdAttributeName(boolean idAttributeName);
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java Tue Mar 30 08:17:56 2010
@@ -27,6 +27,9 @@ import java.util.Set;
 public interface Entity
 {
     String getType();
+    
+    boolean isLive();
+    void setLive(boolean live);
 
     String getId();
     void setId(String id);
@@ -59,5 +62,5 @@ public interface Entity
 
     void setAttributes(Set<Attribute> attributes);
 
-    Set<AttributeDef> getAllowedAttributes();
+    Map<String, AttributeDef> getAllowedAttributes();
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java Tue Mar 30 08:17:56 2010
@@ -31,6 +31,8 @@ public class AttributeDefImpl implements
     private boolean required = false;
     private String  requiredDefaultValue;
     private boolean idAttribute;
+    private boolean idAttributeName;
+    private boolean relationOnly;
 
     public AttributeDefImpl(String name)
     {
@@ -127,6 +129,26 @@ public class AttributeDefImpl implements
     {
         this.idAttribute = idAttribute;
     }
+    
+    public void setRelationOnly(boolean relationOnly)
+    {
+        this.relationOnly = relationOnly;
+    }
+    
+    public boolean isRelationOnly()
+    {
+        return relationOnly;
+    }
+    
+    public boolean isIdAttributeName()
+    {
+        return idAttributeName;
+    }
+    
+    public void setIdAttributeName(boolean idAttributeName)
+    {
+        this.idAttributeName = idAttributeName;
+    }
 
     public AttributeDefImpl cfgRequiredDefaultValue(String requiredDefaultValue)
     {
@@ -139,6 +161,12 @@ public class AttributeDefImpl implements
         setIdAttribute(isIdAttribute);
         return this;
     }
+    
+    public AttributeDefImpl cfgRelationOnly(boolean relationOnly)
+    {
+        setRelationOnly(relationOnly);
+        return this;
+    }
 
     @Override
     public int hashCode()

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java Tue Mar 30 08:17:56 2010
@@ -18,7 +18,6 @@ package org.apache.jetspeed.security.map
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -35,16 +34,17 @@ import org.springframework.ldap.core.Dis
 public class EntityImpl implements Entity
 {
     private Map<String, Attribute>  nameToAttributeMap = new HashMap<String, Attribute>();
-    private final Set<AttributeDef> allowedAttributes;
+    private final Map<String, AttributeDef> allowedAttributes;
     private String                  id;
     private String                  internalId;
     private String                  type;
+    private boolean                 live;
 
-    public EntityImpl(String type, String id, Set<AttributeDef> allowedAttributes)
+    public EntityImpl(String type, String id, Map<String, AttributeDef> allowedAttributes)
     {
         this.type = type;
         this.id = id;
-        this.allowedAttributes = Collections.unmodifiableSet(allowedAttributes);
+        this.allowedAttributes = allowedAttributes;
     }
 
     public String getType()
@@ -56,6 +56,16 @@ public class EntityImpl implements Entit
     {
         this.type = type;
     }
+    
+    public boolean isLive()
+    {
+        return live;
+    }
+    
+    public void setLive(boolean live)
+    {
+        this.live = live;
+    }
 
     public Attribute getAttribute(String name)
     {
@@ -68,7 +78,7 @@ public class EntityImpl implements Entit
         
         if (attr == null && create)
         {
-            AttributeDef def = getAttributeDefinition(name);
+            AttributeDef def = allowedAttributes.get(name);
             if (def == null)
             {
                 // TODO: throw proper exception
@@ -88,7 +98,7 @@ public class EntityImpl implements Entit
 
     public Map<String, Attribute> getAttributes()
     {
-        return Collections.unmodifiableMap(nameToAttributeMap);
+        return nameToAttributeMap;
     }
 
     public Map<String, Attribute> getMappedAttributes()
@@ -102,10 +112,10 @@ public class EntityImpl implements Entit
                 mappedAttrs.put(mappedAttrEntry.getValue().getMappedName(), mappedAttrEntry.getValue());
             }
         }
-        return Collections.unmodifiableMap(mappedAttrs);
+        return mappedAttrs;
     }
 
-    public Set<AttributeDef> getAllowedAttributes()
+    public Map<String, AttributeDef> getAllowedAttributes()
     {
         return allowedAttributes;
     }
@@ -120,24 +130,12 @@ public class EntityImpl implements Entit
         this.id = id;
     }
 
-    protected AttributeDef getAttributeDefinition(String name)
-    {
-        for (AttributeDef def : allowedAttributes)
-        {
-            if (def.getName().equals(name))
-            {
-                return def;
-            }
-        }
-        return null;
-    }
-
     public void setAttribute(String name, String value)
     {
         Attribute attr = nameToAttributeMap.get(name);
         if (attr == null)
         {
-            AttributeDef def = getAttributeDefinition(name);
+            AttributeDef def = allowedAttributes.get(name);
             if (def == null)
             {
                 return; // TODO: throw proper exception
@@ -157,7 +155,7 @@ public class EntityImpl implements Entit
         Attribute attr = nameToAttributeMap.get(name);
         if (attr == null)
         {
-            AttributeDef def = getAttributeDefinition(name);
+            AttributeDef def = allowedAttributes.get(name);
             if (def == null)
             {
                 return; // TODO: throw proper exception
@@ -229,7 +227,7 @@ public class EntityImpl implements Entit
                 return false;
             }
         }
-        else if (!id.equals(other.id))
+        else if (!id.equalsIgnoreCase(other.id))
         {
             return false;
         }
@@ -240,7 +238,7 @@ public class EntityImpl implements Entit
                 return false;
             }
         }
-        else if (!internalId.equals(other.internalId))
+        else if (!internalId.equalsIgnoreCase(other.internalId))
         {
             return false;
         }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java Tue Mar 30 08:17:56 2010
@@ -68,7 +68,7 @@ public class JetspeedPrincipalLdapAssoci
             Entity toEntity = relatedFactory.createEntity(to);
             SecurityEntityRelationType relationType = new SecurityEntityRelationTypeImpl(associationName, fromEntity.getType(), toEntity.getType());
             ldapEntityManager.removeRelation(fromEntity, toEntity, relationType);
-            databaseStorageManager.removeAssociation(from, to, associationName);
         }
+        databaseStorageManager.removeAssociation(from, to, associationName);
     }
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java Tue Mar 30 08:17:56 2010
@@ -25,7 +25,7 @@ import org.apache.jetspeed.security.mapp
 import org.apache.jetspeed.test.JetspeedTestCase;
 import org.springframework.core.io.Resource;
 import org.springframework.ldap.core.ContextSource;
-import org.springframework.ldap.core.LdapTemplate;
+import org.springframework.ldap.core.simple.SimpleLdapTemplate;
 import org.springframework.ldap.core.support.LdapContextSource;
 
 /**
@@ -41,19 +41,15 @@ public abstract class AbstractLDAPTest e
 
     public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid",false,false).cfgRequired(true).cfgIdAttribute(true);
 
-    public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
-            "givenName");;
+    public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl("givenName");
 
-    public static final AttributeDefImpl LAST_NAME_DEF = new AttributeDefImpl(
-            "lastname");;
+    public static final AttributeDefImpl LAST_NAME_DEF = new AttributeDefImpl("lastname");
 
-    public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
-            "description");
+    public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl("description");
 
-    public static final AttributeDefImpl UNIQUEMEMBER_ATTR_DEF = new AttributeDefImpl(
-    "uniqueMember",true).cfgRequired(true).cfgRequiredDefaultValue("uid=someDummyValue");
+    public static final AttributeDefImpl UNIQUEMEMBER_ATTR_DEF = new AttributeDefImpl("uniqueMember",true).cfgRequired(true).cfgRequiredDefaultValue("uid=someDummyValue");
 
-    protected LdapTemplate ldapTemplate;
+    protected SimpleLdapTemplate ldapTemplate;
 
     protected ContextSource contextSource;
 
@@ -95,8 +91,7 @@ public abstract class AbstractLDAPTest e
         contextSource.setUserDn("uid=admin,ou=system");
         contextSource.setPassword("secret");
         contextSource.afterPropertiesSet();
-        ldapTemplate = new LdapTemplate();
-        ldapTemplate.setContextSource(contextSource);
+        ldapTemplate = new SimpleLdapTemplate(contextSource);
 
         if (!ldapService.isRunning()) return;
         

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java Tue Mar 30 08:17:56 2010
@@ -19,6 +19,7 @@ package org.apache.jetspeed.security.map
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 import junit.framework.TestCase;
@@ -101,8 +102,8 @@ public class BasicTestCases
     {
         if (debugMode)
         {
-            Set<AttributeDef> defs = ent.getAllowedAttributes();
-            for (AttributeDef attributeDef : defs)
+            Map<String, AttributeDef> defs = ent.getAllowedAttributes();
+            for (AttributeDef attributeDef : defs.values())
             {
                 Attribute attr = ent.getAttribute(attributeDef.getName());
                 if (attr != null)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java Tue Mar 30 08:17:56 2010
@@ -19,9 +19,7 @@ package org.apache.jetspeed.security.map
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl;
 import org.apache.jetspeed.security.mapping.ldap.AbstractLDAPTest;
@@ -43,9 +41,9 @@ import org.springframework.core.io.Resou
 public abstract class AbstractSetup1LDAPTest extends AbstractLDAPTest
 {
 
-    protected Set<AttributeDef> userAttrDefs;
+    protected Map<String, AttributeDef> userAttrDefs;
 
-    protected Set<AttributeDef> roleAttrDefs;
+    protected Map<String, AttributeDef> roleAttrDefs;
 
     protected AttributeBasedRelationDAO hasRoleDAO;
 
@@ -64,24 +62,23 @@ public abstract class AbstractSetup1LDAP
     @Override
     public void internalSetUp() throws Exception
     {
-
-        Set<AttributeDef> basicAttrDefs = new HashSet<AttributeDef>();
-        basicAttrDefs.add(UID_DEF);
-        basicAttrDefs.add(CN_DEF);
+        Map<String, AttributeDef> basicAttrDefs = new HashMap<String, AttributeDef>();
+        basicAttrDefs.put(UID_DEF.getName(), UID_DEF);
+        basicAttrDefs.put(CN_DEF.getName(), CN_DEF);
 
         // setting up user DAO
-        userAttrDefs = new HashSet<AttributeDef>();
-        userAttrDefs.addAll(basicAttrDefs);
-        userAttrDefs.add(GIVEN_NAME_DEF);
-        userAttrDefs.add(SN_DEF);
-        
+        userAttrDefs = new HashMap<String, AttributeDef>();
+        userAttrDefs.putAll(basicAttrDefs);
+        userAttrDefs.put(GIVEN_NAME_DEF.getName(), GIVEN_NAME_DEF);
+        userAttrDefs.put(SN_DEF.getName(), SN_DEF);
+
         userSearchConfig = new LDAPEntityDAOConfiguration();
-        userSearchConfig.setBaseDN("o=sevenSeas");
-        userSearchConfig.setSearchDN("");
+        userSearchConfig.setLdapBase("o=sevenSeas");
+        userSearchConfig.setSearchBase("");
         userSearchConfig
                 .setSearchFilter(new SimpleFilter("(objectClass=person)"));
-        userSearchConfig.setLdapIdAttribute("uid");
-        userSearchConfig.setAttributeDefinitions(userAttrDefs);
+        userSearchConfig.setLdapIdAttribute("cn");
+        userSearchConfig.setAttributeDefinitions(userAttrDefs.values());
         userSearchConfig.setEntityType("user");
         userSearchConfig.setObjectClasses("inetOrgPerson,");
 
@@ -90,18 +87,18 @@ public abstract class AbstractSetup1LDAP
 
         // setting up role DAO
 
-        roleAttrDefs = new HashSet<AttributeDef>();
-        roleAttrDefs.addAll(basicAttrDefs);
-        roleAttrDefs.add(DESCRIPTION_ATTR_DEF);
-        roleAttrDefs.add(UNIQUEMEMBER_ATTR_DEF);
+        roleAttrDefs = new HashMap<String, AttributeDef>();
+        roleAttrDefs.putAll(basicAttrDefs);
+        roleAttrDefs.put(DESCRIPTION_ATTR_DEF.getName(), DESCRIPTION_ATTR_DEF);
+        roleAttrDefs.put(UNIQUEMEMBER_ATTR_DEF.getName(), UNIQUEMEMBER_ATTR_DEF);
 
         LDAPEntityDAOConfiguration roleSearchConfig = new LDAPEntityDAOConfiguration();
-        roleSearchConfig.setBaseDN("o=sevenSeas");
-        roleSearchConfig.setSearchDN("");
+        roleSearchConfig.setLdapBase("o=sevenSeas");
+        roleSearchConfig.setSearchBase("");
         roleSearchConfig.setSearchFilter(new SimpleFilter(
                 "(objectClass=groupOfUniqueNames)"));
         roleSearchConfig.setLdapIdAttribute("cn");
-        roleSearchConfig.setAttributeDefinitions(roleAttrDefs);
+        roleSearchConfig.setAttributeDefinitions(roleAttrDefs.values());
         roleSearchConfig.setEntityType("role");
 
         roleDAO = new SpringLDAPEntityDAO(roleSearchConfig);

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP.java Tue Mar 30 08:17:56 2010
@@ -196,7 +196,7 @@ public class TestLDAP extends AbstractSe
         jsmithCopy.setAttribute(UID_DEF.getName(), "jsmithCopy");
         jsmithCopy.setAttribute(CN_DEF.getName(), "jsmithCopy");
         jsmithCopy.setAttribute(SN_DEF.getName(), "jsmithCopy");
-        jsmithCopy.setInternalId("uid=jsmithCopy, o=sevenSeas");
+        jsmithCopy.setInternalId("cn=jsmithCopy, o=sevenSeas");
         basicTestCases.testFetchSingleEntity(entityManager, jsmithCopy);
     }
     

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java Tue Mar 30 08:17:56 2010
@@ -19,9 +19,7 @@ package org.apache.jetspeed.security.map
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
@@ -44,11 +42,11 @@ import org.apache.jetspeed.security.mapp
 public abstract class AbstractSetup2LDAPTest extends AbstractLDAPTest
 {
 
-    protected Set<AttributeDef> userAttrDefs;
+    protected Map<String, AttributeDef> userAttrDefs;
 
-    protected Set<AttributeDef> roleAttrDefs;
+    protected Map<String, AttributeDef> roleAttrDefs;
 
-    protected Set<AttributeDef> groupAttrDefs;
+    protected Map<String, AttributeDef> groupAttrDefs;
 
     protected AttributeBasedRelationDAO hasRoleDAO;
 
@@ -65,23 +63,22 @@ public abstract class AbstractSetup2LDAP
     @Override
     public void internalSetUp() throws Exception
     {
-
-        Set<AttributeDef> basicAttrDefs = new HashSet<AttributeDef>();
-        basicAttrDefs.add(UID_DEF);
-        basicAttrDefs.add(CN_DEF);
+        Map<String, AttributeDef> basicAttrDefs = new HashMap<String, AttributeDef>();
+        basicAttrDefs.put(UID_DEF.getName(), UID_DEF);
+        basicAttrDefs.put(CN_DEF.getName(), CN_DEF);
 
         // setting up user DAO
-        userAttrDefs = new HashSet<AttributeDef>();
-        userAttrDefs.addAll(basicAttrDefs);
-        userAttrDefs.add(GIVEN_NAME_DEF);
+        userAttrDefs = new HashMap<String, AttributeDef>();
+        userAttrDefs.putAll(basicAttrDefs);
+        userAttrDefs.put(GIVEN_NAME_DEF.getName(), GIVEN_NAME_DEF);
 
         userSearchConfig = new LDAPEntityDAOConfiguration();
-        userSearchConfig.setBaseDN("o=sevenSeas");
-        userSearchConfig.setSearchDN("");
+        userSearchConfig.setLdapBase("o=sevenSeas");
+        userSearchConfig.setSearchBase("");
         userSearchConfig.setSearchFilter(new SimpleFilter(
                 "(objectClass=inetOrgPerson)"));
-        userSearchConfig.setLdapIdAttribute("uid");
-        userSearchConfig.setAttributeDefinitions(userAttrDefs);
+        userSearchConfig.setLdapIdAttribute("cn");
+        userSearchConfig.setAttributeDefinitions(userAttrDefs.values());
         userSearchConfig.setEntityType("user");
         userSearchConfig.setObjectClasses("inetOrgPerson,organizationalPerson,person,top");
 
@@ -90,35 +87,35 @@ public abstract class AbstractSetup2LDAP
 
         // setting up role DAO
 
-        roleAttrDefs = new HashSet<AttributeDef>();
-        roleAttrDefs.addAll(basicAttrDefs);
-        roleAttrDefs.add(DESCRIPTION_ATTR_DEF);
+        roleAttrDefs = new HashMap<String, AttributeDef>();
+        roleAttrDefs.putAll(basicAttrDefs);
+        roleAttrDefs.put(DESCRIPTION_ATTR_DEF.getName(), DESCRIPTION_ATTR_DEF);
 
         LDAPEntityDAOConfiguration roleSearchConfig = new LDAPEntityDAOConfiguration();
-        roleSearchConfig.setBaseDN("o=sevenSeas");
-        roleSearchConfig.setSearchDN("ou=Roles,o=Jetspeed");
+        roleSearchConfig.setLdapBase("o=sevenSeas");
+        roleSearchConfig.setSearchBase("ou=Roles,o=Jetspeed");
         roleSearchConfig.setSearchFilter(new SimpleFilter(
                 "(objectClass=groupOfUniqueNames)"));
         roleSearchConfig.setLdapIdAttribute("cn");
-        roleSearchConfig.setAttributeDefinitions(roleAttrDefs);
+        roleSearchConfig.setAttributeDefinitions(roleAttrDefs.values());
         roleSearchConfig.setEntityType("role");
         roleSearchConfig.setObjectClasses("groupOfUniqueNames,extensibleObject");
 
         SpringLDAPEntityDAO roleDAO = new SpringLDAPEntityDAO(roleSearchConfig);
         roleDAO.setLdapTemplate(ldapTemplate);
 
-        groupAttrDefs = new HashSet<AttributeDef>();
-        groupAttrDefs.addAll(basicAttrDefs);
-        groupAttrDefs.add(DESCRIPTION_ATTR_DEF);
-        groupAttrDefs.add(UNIQUEMEMBER_ATTR_DEF);
+        groupAttrDefs = new HashMap<String, AttributeDef>();
+        groupAttrDefs.putAll(basicAttrDefs);
+        groupAttrDefs.put(DESCRIPTION_ATTR_DEF.getName(), DESCRIPTION_ATTR_DEF);
+        groupAttrDefs.put(UNIQUEMEMBER_ATTR_DEF.getName(), UNIQUEMEMBER_ATTR_DEF);
 
         LDAPEntityDAOConfiguration groupSearchConfig = new LDAPEntityDAOConfiguration();
-        groupSearchConfig.setBaseDN("o=sevenSeas");
-        groupSearchConfig.setSearchDN("ou=Groups,o=Jetspeed");
+        groupSearchConfig.setLdapBase("o=sevenSeas");
+        groupSearchConfig.setSearchBase("ou=Groups,o=Jetspeed");
         groupSearchConfig.setSearchFilter(new SimpleFilter(
                 "(objectClass=groupOfUniqueNames)"));
         groupSearchConfig.setLdapIdAttribute("cn");
-        groupSearchConfig.setAttributeDefinitions(groupAttrDefs);
+        groupSearchConfig.setAttributeDefinitions(groupAttrDefs.values());
         groupSearchConfig.setEntityType("group");
         groupSearchConfig.setObjectClasses("groupOfUniqueNames,extensibleObject");
         
@@ -161,5 +158,4 @@ public abstract class AbstractSetup2LDAP
         // TODO Auto-generated method stub
 
     }
-
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java Tue Mar 30 08:17:56 2010
@@ -134,4 +134,15 @@ public class StubEntityDAO implements En
         
     }
 
+    public void addRelation(String entityId, String relatedEntityId, String attributeName)
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void removeRelation(String EntityId, String relatedEntityId, String attributeName)
+    {
+        // TODO Auto-generated method stub
+        
+    }
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityFactory.java?rev=929034&r1=929033&r2=929034&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityFactory.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityFactory.java Tue Mar 30 08:17:56 2010
@@ -17,7 +17,6 @@
 package org.apache.jetspeed.security.mapping.stubs;
 
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.Map;
 
 import org.apache.jetspeed.security.mapping.model.AttributeDef;
@@ -41,7 +40,7 @@ public class StubEntityFactory
     
     public Entity createEntity(String id, String entityType, String[]... attrKeyValuePairs){
         
-        EntityImpl stubEntity = new EntityImpl("user", id, new HashSet<AttributeDef>(attributeDefs.values()));
+        EntityImpl stubEntity = new EntityImpl("user", id, attributeDefs);
         for (int i = 0; i < attrKeyValuePairs.length; i++)
         {
             AttributeDef def = attributeDefs.get(attrKeyValuePairs[i][0]);



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message