Author: ate
Date: Fri Mar 26 17:43:27 2010
New Revision: 927984
URL: http://svn.apache.org/viewvc?rev=927984&view=rev
Log:
JS2-1136: Cleanup and strengthening the Security Entity/LDAP mapping
Removed:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/util/
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/DefaultLDAPEntityManager.java
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.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/AttributeBasedRelationDAO.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/Entity.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/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/TestLDAP.java
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -27,6 +27,11 @@ import org.apache.jetspeed.security.mapp
*/
public interface EntityFactory
{
+ /**
+ * @return the Entity type
+ */
+ String getEntityType();
+
Entity createEntity(JetspeedPrincipal principal);
Entity createEntity(DirContext 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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -17,9 +17,8 @@
package org.apache.jetspeed.security.mapping.ldap;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.naming.NamingException;
@@ -31,6 +30,7 @@ import org.apache.jetspeed.security.Secu
import org.apache.jetspeed.security.SecurityAttributes;
import org.apache.jetspeed.security.mapping.EntityFactory;
import
org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
+import org.apache.jetspeed.security.mapping.ldap.dao.impl.SpringLDAPEntityDAO;
import org.apache.jetspeed.security.mapping.model.Attribute;
import org.apache.jetspeed.security.mapping.model.AttributeDef;
import org.apache.jetspeed.security.mapping.model.Entity;
@@ -50,6 +50,11 @@ public class EntityFactoryImpl implement
{
this.searchConfiguration = searchConfiguration;
}
+
+ public String getEntityType()
+ {
+ return searchConfiguration.getEntityType();
+ }
protected EntityImpl internalCreateEntity(String entityId, String
internalId, Set<Attribute> attributes)
{
@@ -59,7 +64,6 @@ public class EntityFactoryImpl implement
{
entity.setInternalId(internalId);
}
- entity.setType(searchConfiguration.getEntityType());
return entity;
}
@@ -81,99 +85,91 @@ public class EntityFactoryImpl implement
return internalCreateEntity(principal.getName(), null, ldapAttrValues);
}
- public String[] getStringAttributes(Attributes originalAttrs, String name)
+ protected List<String> getStringAttributes(Attributes originalAttrs,
String name)
{
- String[] attributes;
+ ArrayList<String> attributes = null;
javax.naming.directory.Attribute attribute = originalAttrs.get(name);
- if (attribute != null && attribute.size() > 0)
+ if (attribute != null)
{
- attributes = new String[attribute.size()];
- for (int i = 0; i < attribute.size(); i++)
+ int size = attribute.size();
+ if (size > 0)
{
- try
+ attributes = new ArrayList<String>(size);
+ for (int i = 0; i < size; i++)
{
- attributes[i] = (String) attribute.get(i);
- }
- catch (NamingException e)
- {
- throw LdapUtils.convertLdapException(e);
+ try
+ {
+ attributes.add((String) attribute.get(i));
+ }
+ catch (NamingException e)
+ {
+ throw LdapUtils.convertLdapException(e);
+ }
}
}
}
- else
- {
- return null;
- }
return attributes;
}
-
+
public Entity createEntity(DirContext ctx)
{
- String entityId = null;
- Entity entity = null;
- Set<Attribute> attributes = new HashSet<Attribute>();
- for (AttributeDef attrDef :
searchConfiguration.getAttributeDefinitions())
+ try
{
- String[] values = null;
- try
- {
- values = getStringAttributes(ctx.getAttributes(""),
attrDef.getName());
- }
- catch (NamingException e)
+ 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())
{
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if (values != null && values.length > 0)
- {
- Attribute a = new AttributeImpl(attrDef);
- if (attrDef.isMultiValue())
+ List<String> values = null;
+ values = getStringAttributes(attrs, attrDef.getName());
+ if (values != null)
{
- Collection<String> attrValues = new ArrayList<String>();
- attrValues.addAll(Arrays.asList(values));
- // remove the dummy value for required fields when present.
- if (attrDef.isRequired() &&
attrDef.getRequiredDefaultValue() != null &&
attrValues.contains(attrDef.getRequiredDefaultValue()))
- {
- attrValues.remove(attrDef.getRequiredDefaultValue());
- }
- if (attrValues.size() != 0)
+ Attribute a = new AttributeImpl(attrDef);
+ if (attrDef.isMultiValue())
{
- a.setValues(attrValues);
- attributes.add(a);
+ // 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))
+ {
+ defaultValue = dn;
+ }
+ if (values.contains(defaultValue))
+ {
+
values.remove(attrDef.getRequiredDefaultValue());
+ }
+ }
+ if (values.size() != 0)
+ {
+ a.setValues(values);
+ }
+ else
+ {
+ attributes.add(a);
+ }
}
else
{
- attributes.add(a);
- }
- }
- else
- {
- if
(attrDef.getName().equals(searchConfiguration.getLdapIdAttribute()))
- {
- entityId = values[0];
- }
- if (values[0] != null)
- {
- // check if the value is not the required default
value (a dummy value) If it is, ignore the attribute.
- if (!(attrDef.isRequired() &&
attrDef.getRequiredDefaultValue() != null &&
values[0].equals(attrDef.getRequiredDefaultValue())))
+ String value = values.get(0);
+ // TODO: make this a boolean flag check
+ if
(attrDef.getName().equals(searchConfiguration.getLdapIdAttribute()))
{
- a.setValue(values[0]);
- attributes.add(a);
+ entityId = value;
}
+ a.setValue(value);
}
+ attributes.add(a);
}
}
- }
- try
- {
- entity = internalCreateEntity(entityId, ctx.getNameInNamespace(),
attributes);
+ entity = internalCreateEntity(entityId, dn, attributes);
+ return entity;
}
catch (NamingException e)
{
- entity = null;
- // TODO Auto-generated catch block
- e.printStackTrace();
+ throw LdapUtils.convertLdapException(e);
}
- return entity;
}
}
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.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/DefaultLDAPEntityManager.java?rev=927984&r1=927983&r2=927984&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java
Fri Mar 26 17:43:27 2010
@@ -35,7 +35,7 @@ import org.apache.jetspeed.security.mapp
public class DefaultLDAPEntityManager implements SecurityEntityManager
{
// entity type DAOs
- protected Map<String, EntityDAO> entityDAOs;
+ protected Map<String, EntityDAO> entityDAOs =
new HashMap<String, EntityDAO>();
protected Map<SecurityEntityRelationType, EntityRelationDAO>
entityRelationDAOs = new HashMap<SecurityEntityRelationType,
EntityRelationDAO>();
public Collection<SecurityEntityRelationType>
getSupportedEntityRelationTypes()
@@ -63,7 +63,7 @@ public class DefaultLDAPEntityManager im
private EntityDAO getDAOForEntity(Entity entity)
{
- return entity.getType() != null ? entityDAOs.get(entity.getType()) :
null;
+ return entityDAOs.get(entity.getType());
}
public void addRelation(Entity sourceEntity, Entity targetEntity,
SecurityEntityRelationType relationType) throws SecurityException
@@ -76,14 +76,14 @@ public class DefaultLDAPEntityManager im
if
(relationType.getFromEntityType().equals(sourceEntity.getType()))
{
sourceDAO = entityDAOs.get(sourceEntity.getType());
- targetDAO = entityDAOs.get(relationType.getToEntityType());
+ targetDAO = entityDAOs.get(relationType.getToEntityType());
}
else
{
targetDAO = entityDAOs.get(sourceEntity.getType());
sourceDAO = entityDAOs.get(relationType.getToEntityType());
}
- if (relationDAO != null)
+ if (sourceDAO != null && targetDAO != null &&
sourceDAO.getEntityType().equals(sourceEntity) &&
targetDAO.getEntityType().equals(targetEntity.getType()))
{
relationDAO.addRelation(sourceDAO, targetDAO, sourceEntity,
targetEntity);
}
@@ -107,7 +107,7 @@ public class DefaultLDAPEntityManager im
targetDAO = entityDAOs.get(entity.getType());
sourceDAO = entityDAOs.get(relationType.getToEntityType());
}
- if (relationDAO != null)
+ if (sourceDAO != null && targetDAO != null &&
sourceDAO.getEntityType().equals(entity) &&
targetDAO.getEntityType().equals(relatedEntity.getType()))
{
relationDAO.removeRelation(sourceDAO, targetDAO, entity,
relatedEntity);
}
@@ -128,12 +128,15 @@ public class DefaultLDAPEntityManager im
public Collection<Entity> getRelatedEntitiesTo(Entity toEntity,
SecurityEntityRelationType relationType)
{
- EntityDAO fromDAO = entityDAOs.get(relationType.getFromEntityType());
- EntityDAO toDAO = entityDAOs.get(relationType.getToEntityType());
EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
- if (fromDAO != null && toDAO != null && relationDAO != null)
+ if (relationDAO != null)
{
- return relationDAO.getRelatedEntitiesTo(fromDAO, toDAO, toEntity);
+ EntityDAO fromDAO =
entityDAOs.get(relationType.getFromEntityType());
+ EntityDAO toDAO = entityDAOs.get(relationType.getToEntityType());
+ if (fromDAO != null && toDAO != null &&
toDAO.getEntityType().equals(toEntity.getType()))
+ {
+ return relationDAO.getRelatedEntitiesTo(fromDAO, toDAO,
toEntity);
+ }
}
return null; // todo : throw exception, since combination of entity
// types and relation type is not configured.
@@ -141,12 +144,15 @@ public class DefaultLDAPEntityManager im
public Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity,
SecurityEntityRelationType relationType)
{
- EntityDAO fromDAO = entityDAOs.get(relationType.getFromEntityType());
- EntityDAO toDAO = entityDAOs.get(relationType.getToEntityType());
EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
- if (fromDAO != null && toDAO != null && relationDAO != null)
+ if (relationDAO != null)
{
- return relationDAO.getRelatedEntitiesFrom(fromDAO, toDAO,
fromEntity);
+ EntityDAO fromDAO =
entityDAOs.get(relationType.getFromEntityType());
+ EntityDAO toDAO = entityDAOs.get(relationType.getToEntityType());
+ if (fromDAO != null && toDAO != null &&
fromDAO.getEntityType().equals(fromEntity.getType()))
+ {
+ return relationDAO.getRelatedEntitiesFrom(fromDAO, toDAO,
fromEntity);
+ }
}
return null; // todo : throw exception, since combination of entity
// types and relation type is not configured.
@@ -182,8 +188,9 @@ public class DefaultLDAPEntityManager im
public void addEntity(Entity entity, Entity parentEntity) throws
SecurityException
{
EntityDAO parentEntityDao = getDAOForEntity(parentEntity);
+ EntityDAO dao = getDAOForEntity(entity);
Entity liveParentEntity = null;
- if (parentEntityDao != null)
+ if (parentEntityDao != null && dao != null)
{
// fetch "live" entity from LDAP to
// 1) check whether entity exists and
@@ -193,17 +200,14 @@ public class DefaultLDAPEntityManager im
{
throw new
SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(parentEntity.getType(),
parentEntity.getId()));
}
- EntityDAO dao = getDAOForEntity(entity);
- if (dao != null)
- {
- dao.add(entity, liveParentEntity);
- }
+ dao.add(entity, liveParentEntity);
}
}
public void setEntityDAOs(Map<String, EntityDAO> entityDAOs)
{
- this.entityDAOs = entityDAOs;
+ this.entityDAOs.clear();
+ this.entityDAOs.putAll(entityDAOs);
}
public void setEntityRelationDAOs(Collection<EntityRelationDAO>
entityRelationDAOs)
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.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/EntityDAO.java?rev=927984&r1=927983&r2=927984&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java
Fri Mar 26 17:43:27 2010
@@ -30,6 +30,11 @@ import org.springframework.ldap.filter.F
public interface EntityDAO
{
/**
+ * @return the Entity type
+ */
+ String getEntityType();
+
+ /**
* Fetch entities by providing a list of specific entity IDs.
*
* @param entity
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -35,6 +35,7 @@ public class LDAPEntityDAOConfiguration
private Set<AttributeDef> attributeDefinitions;
private String entityType;
private String[] objectClassesArr;
+ private String[] attributeNames;
public void initialize() throws JetspeedException
{
@@ -98,6 +99,17 @@ public class LDAPEntityDAOConfiguration
public void setAttributeDefinitions(Set<AttributeDef> attributeDefinitions)
{
this.attributeDefinitions = attributeDefinitions;
+ attributeNames = new String[attributeDefinitions.size()];
+ int i = 0;
+ for (AttributeDef def : attributeDefinitions)
+ {
+ attributeNames[i++] = def.getName();
+ }
+ }
+
+ public String[] getAttributeNames()
+ {
+ return attributeNames;
}
public String getLdapIdAttribute()
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.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/AttributeBasedRelationDAO.java?rev=927984&r1=927983&r2=927984&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java
Fri Mar 26 17:43:27 2010
@@ -17,7 +17,6 @@
package org.apache.jetspeed.security.mapping.ldap.dao.impl;
import java.util.Collection;
-import java.util.Iterator;
import org.apache.commons.lang.StringUtils;
import org.apache.jetspeed.security.SecurityException;
@@ -110,12 +109,8 @@ public class AttributeBasedRelationDAO e
// apparently internalId is not stored in the DB => fetch it from
// LDAP store
entity = entityDao.getEntity(entity.getId());
- return entity.getInternalId();
- }
- else
- {
- return entity.getInternalId();
}
+ return entity.getInternalId();
}
public void setRelationAttribute(String relationAttribute)
@@ -161,72 +156,70 @@ public class AttributeBasedRelationDAO e
attrValue = toEntity.getId();
}
Attribute relationAttribute =
fromEntity.getAttribute(this.relationAttribute, true);
- if (relationAttribute.getValues().contains(attrValue))
- {
- throw new
SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_ALREADY_EXISTS.createScoped(fromEntity.getType(),
fromEntity.getId(),
-
relationAttribute, toEntity.getId()));
- }
if (relationAttribute.getDefinition().isMultiValue())
{
- relationAttribute.getValues().add(attrValue);
+ if (!relationAttribute.getValues().contains(attrValue))
+ {
+ relationAttribute.getValues().add(attrValue);
+ fromEntityDAO.updateInternalAttributes(fromEntity);
+ }
}
- else
+ else if (!attrValue.equals(relationAttribute.getValue()))
{
relationAttribute.setValue(attrValue);
+ fromEntityDAO.updateInternalAttributes(fromEntity);
}
- fromEntityDAO.updateInternalAttributes(fromEntity);
}
private void internalRemoveRelation(EntityDAO fromEntityDAO, EntityDAO
toEntityDAO, Entity fromEntity, Entity toEntity) throws SecurityException
{
fromEntity = fromEntityDAO.getEntity(fromEntity.getId());
- Attribute relationAttribute =
fromEntity.getAttribute(this.relationAttribute);
- if (relationAttribute != null)
+ if (fromEntity != null)
{
- toEntity = toEntityDAO.getEntity(toEntity.getId());
- String attrValue = null;
- if (attributeContainsInternalId)
- {
- if (toEntity.getInternalId() == null)
- {
- // internal ID (ldap DN) is not present, refetch the
entity from LDAP to get the DN
- toEntity = toEntityDAO.getEntity(toEntity.getId());
- }
- attrValue = toEntity.getInternalId();
- }
- else
- {
- attrValue = toEntity.getId();
- }
- if (relationAttribute.getDefinition().isMultiValue())
+ Attribute relationAttribute =
fromEntity.getAttribute(this.relationAttribute);
+ if (relationAttribute != null)
{
- DistinguishedName attrib = new DistinguishedName(attrValue);
- if (attributeContainsInternalId)
+ toEntity = toEntityDAO.getEntity(toEntity.getId());
+ if (toEntity != null)
{
- boolean found = false;
- String attribValue = null;
- Iterator<String> iterator =
relationAttribute.getValues().iterator();
- while (iterator.hasNext() && !found)
+ String attrValue = null;
+ if (attributeContainsInternalId)
+ {
+ attrValue = toEntity.getInternalId();
+ }
+ else
+ {
+ attrValue = toEntity.getId();
+ }
+ if (relationAttribute.getDefinition().isMultiValue())
{
- attribValue = iterator.next();
- DistinguishedName ldapAttr = new
DistinguishedName(attribValue);
- if (ldapAttr.equals(attrib))
+ // TODO: should all membership attributes in all
operations use DistinguishedName comparisions or is doing "plain text"
comparisions good enough?
+ DistinguishedName attrib = new
DistinguishedName(attrValue);
+ if (attributeContainsInternalId)
+ {
+ String attribValue = null;
+ for (String name : relationAttribute.getValues())
+ {
+ DistinguishedName ldapAttr = new
DistinguishedName(attribValue);
+ if (ldapAttr.equals(attrib))
+ {
+ relationAttribute.getValues().remove(name);
+ break;
+ }
+ }
+ }
+ else
{
- relationAttribute.getValues().remove(attribValue);
- found = true;
+ relationAttribute.getValues().remove(attrValue);
}
}
- }
- else
- {
- relationAttribute.getValues().remove(attrValue);
+ else
+ {
+ relationAttribute.setValue(null);
+ }
+ fromEntityDAO.updateInternalAttributes(fromEntity);
}
}
- else
- {
- relationAttribute.setValue(null);
- }
- fromEntityDAO.updateInternalAttributes(fromEntity);
}
}
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -90,6 +90,11 @@ public class SpringLDAPEntityDAO impleme
{
return contextMapper;
}
+
+ public String getEntityType()
+ {
+ return entityFactory.getEntityType();
+ }
public EntityFactory getEntityFactory()
{
@@ -114,10 +119,7 @@ public class SpringLDAPEntityDAO impleme
{
return entities.iterator().next();
}
- else
- {
- return null;
- }
+ return null;
}
public Collection<Entity> getEntitiesById(Collection<String> entityIds)
@@ -128,16 +130,12 @@ public class SpringLDAPEntityDAO impleme
{
idFilter.or(new EqualsFilter(idAttr, id));
}
- Filter combinedFilter = null;
+ Filter filter = idFilter;
if (configuration.getSearchFilter() != null)
{
- combinedFilter = SearchUtil.andFilters(idFilter,
configuration.getSearchFilter());
- }
- else
- {
- combinedFilter = idFilter;
+ filter = SearchUtil.andFilters(idFilter,
configuration.getSearchFilter());
}
- return getEntities(combinedFilter);
+ return getEntities(filter);
}
public Collection<Entity> getEntitiesByInternalId(Collection<String>
internalIds)
@@ -162,7 +160,7 @@ public class SpringLDAPEntityDAO impleme
String searchDNStr = searchDN.toCompactString();
if (relativeDN.equals(searchDNStr) || relativeDN.endsWith(searchDNStr))
{
- internalId = principalDN.toCompactString();
+ internalId = relativeDN;
ClassLoader currentClassLoader =
Thread.currentThread().getContextClassLoader();
try
{
@@ -252,9 +250,7 @@ public class SpringLDAPEntityDAO impleme
try
{
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- String parentId = parent.getInternalId();
- DistinguishedName parentDN = getRelativeDN(parentId);
- results = ldapTemplate.search(parentDN.encode(), filterStr,
SearchControls.ONELEVEL_SCOPE, getContextMapper());
+ results =
ldapTemplate.search(getRelativeDN(parent.getInternalId()), filterStr,
SearchControls.ONELEVEL_SCOPE, getContextMapper());
}
finally
{
@@ -280,6 +276,7 @@ public class SpringLDAPEntityDAO impleme
throw new
SecurityException(SecurityException.PRINCIPAL_UPDATE_FAILURE.createScoped(entity.getType(),
entity.getId()));
}
internalId = ldapEntity.getInternalId();
+ entity.setInternalId(internalId);
}
Name dn = getRelativeDN(internalId);
DirContextOperations dirCtxOps = null;
@@ -394,12 +391,10 @@ public class SpringLDAPEntityDAO impleme
basicAttr.add(requiredValue);
}
}
- }
- else
- {
- // TODO missing required attribute value, throw
- // exception
- // return;
+ else
+ {
+ // missing required attribute value, LDAP
will/should throw exception
+ }
}
}
if (basicAttr != null)
@@ -433,7 +428,6 @@ public class SpringLDAPEntityDAO impleme
// 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;
- //throw new
SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(entity.getType(),
entity.getId()));
}
String internalIdStr = entity.getInternalId();
if (internalIdStr == null)
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -29,8 +29,10 @@ public interface Entity
String getType();
String getId();
+ void setId(String id);
String getInternalId();
+ void setInternalId(String internalId);
Attribute getAttribute(String name);
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -23,10 +23,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import org.apache.jetspeed.security.mapping.ldap.util.DnUtils;
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.DistinguishedName;
/**
* @author <a href="mailto:[email protected]">Dennis Dam</a>
@@ -189,7 +189,7 @@ public class EntityImpl implements Entit
{
if (internalId != null)
{
- internalId = DnUtils.encodeDn(internalId);
+ internalId = new DistinguishedName(internalId).toCompactString();
}
this.internalId = internalId;
}
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/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/setup2/TestLDAP.java?rev=927984&r1=927983&r2=927984&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/TestLDAP.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/TestLDAP.java
Fri Mar 26 17:43:27 2010
@@ -21,7 +21,6 @@ import java.util.Collection;
import junit.framework.Test;
-import org.apache.jetspeed.security.mapping.ldap.util.DnUtils;
import org.apache.jetspeed.security.mapping.model.Entity;
import org.apache.jetspeed.security.mapping.model.impl.EntityImpl;
@@ -52,7 +51,7 @@ public class TestLDAP extends AbstractSe
financeRole.setInternalId("cn=Finance, ou=Roles, o=Jetspeed,
o=sevenSeas");
financeRole.setAttribute(CN_DEF.getName(), "Finance");
Collection<String> members = new ArrayList<String>();
-
members.add(DnUtils.encodeDn("cn=David,o=Peoples,o=SanFrancisco,o=Jetspeed,o=sevenSeas"));
+
members.add("cn=David,o=Peoples,o=SanFrancisco,o=Jetspeed,o=sevenSeas");
financeRole.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), members);
return financeRole;
}
@@ -62,9 +61,9 @@ public class TestLDAP extends AbstractSe
usersRole.setInternalId("cn=Users, ou=Roles, o=Jetspeed, o=sevenSeas");
usersRole.setAttribute(CN_DEF.getName(), "Users");
Collection<String> members = new ArrayList<String>();
-
members.add(DnUtils.encodeDn("cn=David,o=Peoples,o=SanFrancisco,o=Jetspeed,o=sevenSeas"));
-
members.add(DnUtils.encodeDn("cn=Paul,o=People,o=Amsterdam,o=Jetspeed,o=sevenSeas"));
-
members.add(DnUtils.encodeDn("cn=Thomas,o=Peoples,o=Amsterdam,o=Jetspeed,o=sevenSeas"));
+
members.add("cn=David,o=Peoples,o=SanFrancisco,o=Jetspeed,o=sevenSeas");
+ members.add("cn=Paul,o=People,o=Amsterdam,o=Jetspeed,o=sevenSeas");
+ members.add("cn=Thomas,o=Peoples,o=Amsterdam,o=Jetspeed,o=sevenSeas");
usersRole.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), members);
return usersRole;
}
@@ -103,8 +102,7 @@ public class TestLDAP extends AbstractSe
Entity liveNestedGroup = entityManager.getEntity("group",
nestedGroup.getId());
assertNotNull(liveNestedGroup);
- String newDn = DnUtils.encodeDnUsingSeparator(",",
marketingGroup.getInternalId(), "cn="+liveNestedGroup.getId());
-
assertEquals("cn=nestedGroup1,cn=Marketing,ou=Groups,o=Jetspeed,o=sevenSeas",
newDn);
+
assertEquals("cn=nestedGroup1,cn=Marketing,ou=Groups,o=Jetspeed,o=sevenSeas",
liveNestedGroup.getInternalId());
}
private Entity createUser(String id, String internalId, String givenName,
String cn, String uid, String[] roles){
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=927984&r1=927983&r2=927984&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
Fri Mar 26 17:43:27 2010
@@ -33,6 +33,11 @@ public class StubEntityDAO implements En
private Map<String,Entity> entities = new HashMap<String,Entity>();
+ public String getEntityType()
+ {
+ return null;
+ }
+
public Collection<Entity> getEntities(Entity parentEntity, Filter filter)
{
// TODO Auto-generated method stub
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]