portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1101697 - /portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
Date Wed, 11 May 2011 00:38:44 GMT
Author: ate
Date: Wed May 11 00:38:44 2011
New Revision: 1101697

URL: http://svn.apache.org/viewvc?rev=1101697&view=rev
Log:
JS2-1251: Also support Ldap Entity loading based on a Spring LdapTemplate provided DirContextAdapter

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java

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=1101697&r1=1101696&r2=1101697&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
Wed May 11 00:38:44 2011
@@ -36,6 +36,7 @@ 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.DirContextAdapter;
 import org.springframework.ldap.core.DirContextOperations;
 import org.springframework.ldap.core.DistinguishedName;
 import org.springframework.ldap.core.LdapRdn;
@@ -125,66 +126,76 @@ public class EntityFactoryImpl implement
     
     public Entity loadEntity(Object providerContext)
     {
-        DirContextOperations ctx = (DirContextOperations)((SearchResult)(providerContext)).getObject();
-        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())
+        DirContextOperations ctx = null;
+        
+        if (providerContext instanceof SearchResult)
+        {
+            ctx = (DirContextOperations) ((SearchResult) (providerContext)).getObject();
+        }
+        else if (providerContext instanceof DirContextAdapter)
         {
-            List<String> values = null;
-            values = getStringAttributes(attrs, attrDef.getName(), attrDef.requiresDnDefaultValue());
-            if (values != null)
+            ctx = (DirContextOperations) providerContext;
+        }
+        if (ctx != null)
+        {
+            String entityId = null;
+            String dn = ctx.getNameInNamespace();
+            Set<Attribute> attributes = new HashSet<Attribute>();
+            Attributes attrs = ctx.getAttributes();
+            for (AttributeDef attrDef : searchConfiguration.getEntityAttributeDefinitionsMap().values())
             {
-                Attribute a = new AttributeImpl(attrDef);
-                if (attrDef.isMultiValue())
+                List<String> values = null;
+                values = getStringAttributes(attrs, attrDef.getName(), attrDef.requiresDnDefaultValue());
+                if (values != null)
                 {
-                    // remove the dummy value for required fields when present.
-                    if (attrDef.isRequired())
-                    {
-                        String defaultValue = attrDef.requiresDnDefaultValue() ? dn : attrDef.getRequiredDefaultValue();
-                        values.remove(defaultValue);
-                    }
-                        
-                    if (values.size() != 0)
+                    Attribute a = new AttributeImpl(attrDef);
+                    if (attrDef.isMultiValue())
                     {
-                        a.setValues(values);
+                        // remove the dummy value for required fields when present.
+                        if (attrDef.isRequired())
+                        {
+                            String defaultValue = attrDef.requiresDnDefaultValue() ? dn :
attrDef.getRequiredDefaultValue();
+                            values.remove(defaultValue);
+                        }
+                        if (values.size() != 0)
+                        {
+                            a.setValues(values);
+                        }
+                        else
+                        {
+                            attributes.add(a);
+                        }
                     }
-                        
                     else
                     {
-                        attributes.add(a);
-                    }                        
-                }
-                else
-                {
-                    String value = values.get(0);
-                    if (attrDef.isEntityIdAttribute())
-                    {
-                        entityId = value;
+                        String value = values.get(0);
+                        if (attrDef.isEntityIdAttribute())
+                        {
+                            entityId = value;
+                        }
+                        a.setValue(value);
                     }
-                    a.setValue(value);
+                    attributes.add(a);
                 }
-                attributes.add(a);
-            }
-        }
-        if (entityId == null)
-        {
-            DistinguishedName name = new DistinguishedName(dn);            
-            LdapRdn rdn = name.getLdapRdn(name.size()-1);
-            if (rdn.getKey().equals(searchConfiguration.getLdapIdAttribute()))
-            {
-                entityId = rdn.getValue();
             }
-            else
+            if (entityId == null)
             {
-                // TODO: throw exception???
-                return null;
+                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);
         }
-        entity = internalCreateEntity(entityId, dn, attributes);
-        entity.setLive(true);
         return entity;
     }
 }



---------------------------------------------------------------------
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