You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2010/03/31 15:38:35 UTC
svn commit: r929535 [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/impl/
components/jetspeed-...
Author: ate
Date: Wed Mar 31 13:38:34 2010
New Revision: 929535
URL: http://svn.apache.org/viewvc?rev=929535&view=rev
Log:
JS2-1136: Cleanup and strengthening the Security Entity/LDAP mapping
- more optimalization of (amount of) LDAP access operations
- relationship modifications are now directly and only executed using ModificationItems, no more entity "loading" involved
- more bugs fixed
- still todo:
- searching relationships without need to load (intermediate) entities
- paging support and callback based of processing large amount of "entities"
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/TestLDAP1.java (contents, props changed)
- copied, changed from r929034, 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/TestLDAP2.java (contents, props changed)
- copied, changed from r929033, portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/TestLDAP.java
Removed:
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityFilterFactory.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/TestLDAP.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/SecurityEntityManager.java
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.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/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/EntityRelationDAO.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/AttributeDef.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/spi/JetspeedSecuritySynchronizer.java
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedSecuritySynchronizer.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/setup1/AbstractSetup1LDAPTest.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/StubEntityRelationDAO.java
portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/spi/TestDefaultJetspeedSynchronizer.java
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityException.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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -18,7 +18,6 @@ package org.apache.jetspeed.security.map
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>
@@ -33,5 +32,5 @@ public interface EntityFactory
Entity createEntity(JetspeedPrincipal principal);
- Entity createEntity(DirContextOperations ctx);
+ Entity loadEntity(Object providerContext);
}
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java?rev=929535&r1=929534&r2=929535&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java Wed Mar 31 13:38:34 2010
@@ -17,6 +17,7 @@
package org.apache.jetspeed.security.mapping;
import java.util.Collection;
+import java.util.Set;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.model.Entity;
@@ -28,15 +29,17 @@ import org.apache.jetspeed.security.mapp
*/
public interface SecurityEntityManager
{
- Collection<String> getSupportedEntityTypes();
+ Set<String> getSupportedEntityTypes();
- Collection<SecurityEntityRelationType> getSupportedEntityRelationTypes();
+ Set<SecurityEntityRelationType> getSupportedEntityRelationTypes();
- Collection<SecurityEntityRelationType> getSupportedEntityRelationTypes(String entityType);
+ Set<SecurityEntityRelationType> getSupportedEntityRelationTypes(String entityType);
- Entity getEntity(String entityType, String entityId);
+ SecurityEntityRelationType getSupportedEntityRelationType(String relationType, String fromEntityType, String toEntityType);
+
+ Entity getEntity(String entityType, String entityId) throws SecurityException;
- Collection<Entity> getAllEntities(String entityType);
+ Collection<Entity> getAllEntities(String entityType) throws SecurityException;
void addEntity(Entity entity) throws SecurityException;
@@ -46,13 +49,13 @@ public interface SecurityEntityManager
void updateEntity(Entity entity) throws SecurityException;
- void addRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException;
+ void addRelation(String fromEntityId, String toEntityId, SecurityEntityRelationType relationType) throws SecurityException;
+
+ void removeRelation(String fromEntityId, String toEntityId, SecurityEntityRelationType relationType) throws SecurityException;
+
+ Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity, SecurityEntityRelationType relationType) throws SecurityException;
- void removeRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException;
-
- Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity, SecurityEntityRelationType relationType);
-
- Collection<Entity> getRelatedEntitiesTo(Entity toEntity, SecurityEntityRelationType relationType);
+ Collection<Entity> getRelatedEntitiesTo(Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException;
EntityFactory getEntityFactory(String entityType);
}
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java?rev=929535&r1=929534&r2=929535&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java Wed Mar 31 13:38:34 2010
@@ -24,101 +24,51 @@ import org.apache.jetspeed.security.mapp
*/
public class SecurityEntityRelationTypeImpl implements SecurityEntityRelationType
{
- private String sourceEntityType, targetEntityType, relationType;
+ private final String fromEntityType;
+ private final String toEntityType;
+ private final String relationType;
+ private final int hashCode;
+ public SecurityEntityRelationTypeImpl(SecurityEntityRelationType src)
+ {
+ this(src.getFromEntityType(), src.getToEntityType(), src.getFromEntityType());
+ }
+
public SecurityEntityRelationTypeImpl(String relationType, String sourceEntityType, String targetEntityType)
{
- super();
this.relationType = relationType;
- this.sourceEntityType = sourceEntityType;
- this.targetEntityType = targetEntityType;
+ this.fromEntityType = sourceEntityType;
+ this.toEntityType = targetEntityType;
+ this.hashCode = relationType.hashCode() + sourceEntityType.hashCode() + targetEntityType.hashCode();
}
@Override
public int hashCode()
{
- final int prime = 31;
- int result = 1;
- result = prime * result + ((relationType == null) ? 0 : relationType.hashCode());
- result = prime * result + ((sourceEntityType == null) ? 0 : sourceEntityType.hashCode());
- result = prime * result + ((targetEntityType == null) ? 0 : targetEntityType.hashCode());
- return result;
+ return hashCode;
}
@Override
- public boolean equals(Object obj)
+ public boolean equals(Object o)
{
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- SecurityEntityRelationType other = (SecurityEntityRelationType) obj;
- if (relationType == null)
- {
- if (other.getRelationType() != null)
- {
- return false;
- }
- }
- else if (!relationType.equals(other.getRelationType()))
- {
- return false;
- }
- if (sourceEntityType == null)
- {
- if (other.getFromEntityType() != null)
- {
- return false;
- }
- }
- else if (!sourceEntityType.equals(other.getFromEntityType()))
- {
- return false;
- }
- if (targetEntityType == null)
- {
- if (other.getToEntityType() != null)
- {
- return false;
- }
- }
- else if (!targetEntityType.equals(other.getToEntityType()))
+ if (o != null && o instanceof SecurityEntityRelationTypeImpl)
{
- return false;
+ SecurityEntityRelationTypeImpl other = (SecurityEntityRelationTypeImpl)o;
+ return other.relationType.equals(relationType) && other.fromEntityType.equals(fromEntityType) && other.toEntityType.equals(toEntityType);
}
- return true;
+ return false;
}
- /*
- * (non-Javadoc)
- * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getSourceEntityType()
- */
public String getFromEntityType()
{
- return sourceEntityType;
+ return fromEntityType;
}
- /*
- * (non-Javadoc)
- * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getTargetEntityType()
- */
public String getToEntityType()
{
- return targetEntityType;
+ return toEntityType;
}
- /*
- * (non-Javadoc)
- * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getRelationType()
- */
public String getRelationType()
{
return relationType;
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=929535&r1=929534&r2=929535&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 Mar 31 13:38:34 2010
@@ -29,7 +29,6 @@ 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;
@@ -75,13 +74,16 @@ public class EntityFactoryImpl implement
SecurityAttributes sas = principal.getSecurityAttributes();
for (AttributeDef attrDef : searchConfiguration.getEntityAttributeDefinitionsMap().values())
{
- SecurityAttribute sa = sas.getAttribute(attrDef.getMappedName());
- if (sa != null)
+ if (attrDef.isMapped())
{
- // currently only single-valued attributes are supported
- AttributeImpl attr = new AttributeImpl(attrDef);
- attr.setValue(sa.getStringValue());
- ldapAttrValues.add(attr);
+ SecurityAttribute sa = sas.getAttribute(attrDef.getMappedName());
+ if (sa != null)
+ {
+ // currently only single-valued attributes are supported
+ AttributeImpl attr = new AttributeImpl(attrDef);
+ attr.setValue(sa.getStringValue());
+ ldapAttrValues.add(attr);
+ }
}
}
return internalCreateEntity(principal.getName(), null, ldapAttrValues);
@@ -113,8 +115,9 @@ public class EntityFactoryImpl implement
return attributes;
}
- public Entity createEntity(DirContextOperations ctx)
+ public Entity loadEntity(Object providerContext)
{
+ DirContextOperations ctx = (DirContextOperations)providerContext;
String entityId = null;
Entity entity = null;
String dn = ctx.getNameInNamespace();
@@ -129,19 +132,11 @@ public class EntityFactoryImpl implement
Attribute a = new AttributeImpl(attrDef);
if (attrDef.isMultiValue())
{
-
// remove the dummy value for required fields when present.
- if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null)
+ if (attrDef.isRequired())
{
- String defaultValue = attrDef.getRequiredDefaultValue();
- if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(defaultValue))
- {
- defaultValue = dn;
- }
- if (values.contains(defaultValue))
- {
- values.remove(attrDef.getRequiredDefaultValue());
- }
+ String defaultValue = attrDef.requiresDnDefaultValue() ? dn : attrDef.getRequiredDefaultValue();
+ values.remove(defaultValue);
}
if (values.size() != 0)
@@ -157,7 +152,7 @@ public class EntityFactoryImpl implement
else
{
String value = values.get(0);
- if (attrDef.isIdAttributeName())
+ if (attrDef.isEntityIdAttribute())
{
entityId = value;
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -43,6 +43,6 @@ public class DefaultEntityContextMapper
@Override
protected Entity doMapFromContext(DirContextOperations ctx)
{
- return entityFactory.createEntity(ctx);
+ return entityFactory.loadEntity(ctx);
}
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -16,15 +16,17 @@
*/
package org.apache.jetspeed.security.mapping.ldap.dao;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.EntityFactory;
import org.apache.jetspeed.security.mapping.SecurityEntityManager;
+import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl;
import org.apache.jetspeed.security.mapping.model.Entity;
import org.apache.jetspeed.security.mapping.model.SecurityEntityRelationType;
@@ -35,30 +37,68 @@ import org.apache.jetspeed.security.mapp
public class DefaultLDAPEntityManager implements SecurityEntityManager
{
// entity type DAOs
- protected Map<String, EntityDAO> entityDAOs = new HashMap<String, EntityDAO>();
- protected Map<SecurityEntityRelationType, EntityRelationDAO> entityRelationDAOs = new HashMap<SecurityEntityRelationType, EntityRelationDAO>();
+ private Map<String, EntityDAO> entityDAOs = new HashMap<String, EntityDAO>();
+ private Map<SecurityEntityRelationType, EntityRelationDAO> entityRelationDAOs = new HashMap<SecurityEntityRelationType, EntityRelationDAO>();
+ private Map<String, Set<SecurityEntityRelationType>> entityRelationTypes = new HashMap<String, Set<SecurityEntityRelationType>>();
+
+ public DefaultLDAPEntityManager(List<EntityDAO> entityDAOs, List<EntityRelationDAO> entityRelationDAOs)
+ {
+ for (EntityDAO entityDAO: entityDAOs)
+ {
+ this.entityDAOs.put(entityDAO.getEntityType(), entityDAO);
+ }
+ if (entityRelationDAOs != null)
+ {
+ for (EntityRelationDAO entityRelationDAO: entityRelationDAOs)
+ {
+ SecurityEntityRelationType relationType = entityRelationDAO.getRelationType();
+ if (this.entityDAOs.get(relationType.getFromEntityType()) == null || this.entityDAOs.get(relationType.getToEntityType()) == null)
+ {
+ throw new IllegalArgumentException("Missing EntityDAO for EntityRelationDAO fromEntityType: "+relationType.getFromEntityType() +
+ " and/or toEntityType: "+relationType.getToEntityType());
+ }
+ this.entityRelationDAOs.put(new SecurityEntityRelationTypeImpl(relationType.getRelationType(), relationType.getFromEntityType(), relationType.getToEntityType()),
+ entityRelationDAO);
+ }
+ }
+ for (SecurityEntityRelationType relationType : this.entityRelationDAOs.keySet())
+ {
+ Set<SecurityEntityRelationType> relationTypes = entityRelationTypes.get(relationType.getFromEntityType());
+ if (relationTypes == null)
+ {
+ relationTypes = new HashSet<SecurityEntityRelationType>();
+ entityRelationTypes.put(relationType.getFromEntityType(), relationTypes);
+ }
+ relationTypes.add(relationType);
+ relationTypes = entityRelationTypes.get(relationType.getToEntityType());
+ if (relationTypes == null)
+ {
+ relationTypes = new HashSet<SecurityEntityRelationType>();
+ entityRelationTypes.put(relationType.getFromEntityType(), relationTypes);
+ }
+ relationTypes.add(relationType);
+ }
+ }
+
+ public SecurityEntityRelationType getSupportedEntityRelationType(String relationType, String fromEntityType, String toEntityType)
+ {
+ SecurityEntityRelationType key = new SecurityEntityRelationTypeImpl(relationType, fromEntityType, toEntityType);
+ return entityRelationDAOs.containsKey(key) ? key : null;
+ }
- public Collection<SecurityEntityRelationType> getSupportedEntityRelationTypes()
+ public Set<SecurityEntityRelationType> getSupportedEntityRelationTypes()
{
- return Collections.unmodifiableCollection(entityRelationDAOs.keySet());
+ return entityRelationDAOs.keySet();
}
- public Collection<String> getSupportedEntityTypes()
+ public Set<String> getSupportedEntityTypes()
{
- return Collections.unmodifiableCollection(entityDAOs.keySet());
+ return entityRelationTypes.keySet();
}
- public Collection<SecurityEntityRelationType> getSupportedEntityRelationTypes(String entityType)
+ public Set<SecurityEntityRelationType> getSupportedEntityRelationTypes(String entityType)
{
- Collection<SecurityEntityRelationType> supportedRelationTypes = new ArrayList<SecurityEntityRelationType>();
- for (SecurityEntityRelationType type : entityRelationDAOs.keySet())
- {
- if (type.getFromEntityType().equals(entityType) || type.getToEntityType().equals(entityType))
- {
- supportedRelationTypes.add(type);
- }
- }
- return Collections.unmodifiableCollection(supportedRelationTypes);
+ return entityRelationTypes.get(entityType);
}
private EntityDAO getDAOForEntity(Entity entity)
@@ -66,69 +106,39 @@ public class DefaultLDAPEntityManager im
return entityDAOs.get(entity.getType());
}
- public void addRelation(Entity sourceEntity, Entity targetEntity, SecurityEntityRelationType relationType) throws SecurityException
+ public void addRelation(String fromEntityId, String toEntityId, SecurityEntityRelationType relationType) throws SecurityException
{
- EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
- if (relationDAO != null)
+ EntityRelationDAO dao = entityRelationDAOs.get(relationType instanceof SecurityEntityRelationTypeImpl ? relationType : new SecurityEntityRelationTypeImpl(relationType));
+ if (dao != null)
{
- EntityDAO sourceDAO;
- EntityDAO targetDAO;
- if (relationType.getFromEntityType().equals(sourceEntity.getType()))
- {
- sourceDAO = entityDAOs.get(sourceEntity.getType());
- targetDAO = entityDAOs.get(relationType.getToEntityType());
- }
- else
- {
- targetDAO = entityDAOs.get(sourceEntity.getType());
- sourceDAO = entityDAOs.get(relationType.getToEntityType());
- }
- if (sourceDAO != null && targetDAO != null && sourceDAO.getEntityType().equals(sourceEntity) && targetDAO.getEntityType().equals(targetEntity.getType()))
- {
- relationDAO.addRelation(sourceDAO, targetDAO, sourceEntity, targetEntity);
- }
+ dao.addRelation(entityDAOs.get(relationType.getFromEntityType()), entityDAOs.get(relationType.getToEntityType()), fromEntityId, toEntityId);
}
}
-
- public void removeRelation(Entity entity, Entity relatedEntity, SecurityEntityRelationType relationType) throws SecurityException
+
+ public void removeRelation(String fromEntityId, String toEntityId, SecurityEntityRelationType relationType) throws SecurityException
{
- EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
- if (relationDAO != null)
+ EntityRelationDAO dao = entityRelationDAOs.get(relationType instanceof SecurityEntityRelationTypeImpl ? relationType : new SecurityEntityRelationTypeImpl(relationType));
+ if (dao != null)
{
- EntityDAO sourceDAO;
- EntityDAO targetDAO;
- if (relationType.getFromEntityType().equals(entity.getType()))
- {
- sourceDAO = entityDAOs.get(entity.getType());
- targetDAO = entityDAOs.get(relationType.getToEntityType());
- }
- else
- {
- targetDAO = entityDAOs.get(entity.getType());
- sourceDAO = entityDAOs.get(relationType.getToEntityType());
- }
- if (sourceDAO != null && targetDAO != null && sourceDAO.getEntityType().equals(entity) && targetDAO.getEntityType().equals(relatedEntity.getType()))
- {
- relationDAO.removeRelation(sourceDAO, targetDAO, entity, relatedEntity);
- }
+ dao.removeRelation(entityDAOs.get(relationType.getFromEntityType()), entityDAOs.get(relationType.getToEntityType()), fromEntityId, toEntityId);
}
}
-
- public Collection<Entity> getAllEntities(String entityType)
+
+ public Collection<Entity> getAllEntities(String entityType) throws SecurityException
{
EntityDAO dao = entityDAOs.get(entityType);
return dao != null ? dao.getAllEntities() : null;
}
- public Entity getEntity(String entityType, String entityId)
+ public Entity getEntity(String entityType, String entityId) throws SecurityException
{
EntityDAO dao = entityDAOs.get(entityType);
return dao != null ? dao.getEntity(entityId) : null;
}
- public Collection<Entity> getRelatedEntitiesTo(Entity toEntity, SecurityEntityRelationType relationType)
+ public Collection<Entity> getRelatedEntitiesTo(Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException
{
- EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
+ EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType instanceof SecurityEntityRelationTypeImpl ? relationType : new SecurityEntityRelationTypeImpl(relationType));
if (relationDAO != null)
{
EntityDAO fromDAO = entityDAOs.get(relationType.getFromEntityType());
@@ -142,9 +152,9 @@ public class DefaultLDAPEntityManager im
// types and relation type is not configured.
}
- public Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity, SecurityEntityRelationType relationType)
+ public Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity, SecurityEntityRelationType relationType) throws SecurityException
{
- EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
+ EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType instanceof SecurityEntityRelationTypeImpl ? relationType : new SecurityEntityRelationTypeImpl(relationType));
if (relationDAO != null)
{
EntityDAO fromDAO = entityDAOs.get(relationType.getFromEntityType());
@@ -204,21 +214,6 @@ public class DefaultLDAPEntityManager im
}
}
- public void setEntityDAOs(Map<String, EntityDAO> entityDAOs)
- {
- this.entityDAOs.clear();
- this.entityDAOs.putAll(entityDAOs);
- }
-
- public void setEntityRelationDAOs(Collection<EntityRelationDAO> entityRelationDAOs)
- {
- this.entityRelationDAOs.clear();
- for (EntityRelationDAO dao : entityRelationDAOs)
- {
- this.entityRelationDAOs.put(dao.getRelationType(), dao);
- }
- }
-
public EntityFactory getEntityFactory(String entityType)
{
EntityDAO dao = entityDAOs.get(entityType);
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -41,7 +41,7 @@ public interface EntityDAO
* IDs
* @return found entities
*/
- Collection<Entity> getEntitiesById(Collection<String> entityIds);
+ Collection<Entity> getEntitiesById(Collection<String> entityIds) throws SecurityException;
/**
* Fetch entity by providing an *internal* entity ID.
@@ -49,7 +49,7 @@ public interface EntityDAO
* @param internalId
* @return found entity
*/
- Entity getEntityByInternalId(String internalId);
+ Entity getEntityByInternalId(String internalId) throws SecurityException;
/**
* Fetch entities by providing a list of specific *internal* entity IDs.
@@ -58,7 +58,7 @@ public interface EntityDAO
* entity IDs
* @return found entities
*/
- Collection<Entity> getEntitiesByInternalId(Collection<String> entityIds);
+ Collection<Entity> getEntitiesByInternalId(Collection<String> entityIds) throws SecurityException;
/**
* Method for applying a specific filter on the complete entity set returned by the DAO. The result would be the same as applying the specific filter to the
@@ -68,7 +68,7 @@ public interface EntityDAO
* a specific filter to narrow the returned entity set
* @return found entities
*/
- Collection<Entity> getEntities(Filter filter);
+ Collection<Entity> getEntities(Filter filter) throws SecurityException;
/**
* Same as getEntities(Filter filter), except that this method only returns entities which are children of the given parent entity.
@@ -77,7 +77,7 @@ public interface EntityDAO
* @param filter
* @return
*/
- Collection<Entity> getEntities(Entity parentEntity, Filter filter);
+ Collection<Entity> getEntities(Entity parentEntity, Filter filter) throws SecurityException;
/**
* Fetch a single entity by ID.
@@ -85,33 +85,44 @@ public interface EntityDAO
* @param entityId
* @return the entity
*/
- Entity getEntity(String entityId);
+ Entity getEntity(String entityId) throws SecurityException;
/**
+ * Fetch a entity internalId by ID
+ *
+ * @param entityId
+ * @param required if true and entity not found SecurityException.PRINCIPAL_DOES_NOT_EXIST will be thrown
+ * @return the entity internalId
+ */
+ String getInternalId(String entityId, boolean required) throws SecurityException;
+
+ /**
* Returns the parent entity of the given entity, if there is any.
*
* @param filter
* a specific filter to narrow the returned entity set
* @return found entities
*/
- Entity getParentEntity(Entity childEntity);
+ Entity getParentEntity(Entity childEntity) throws SecurityException;
/**
* Fetch all entities
*
* @return found entities
*/
- Collection<Entity> getAllEntities();
+ Collection<Entity> getAllEntities() throws SecurityException;
void update(Entity entity) throws SecurityException;
- void updateInternalAttributes(Entity entity) throws SecurityException;
-
void add(Entity entity) throws SecurityException;
void remove(Entity entity) throws SecurityException;
void add(Entity entity, Entity parentEntity) throws SecurityException;
+ void addRelation(String entityId, String relatedEntityInternalId, String attributeName) throws SecurityException;
+
+ void removeRelation(String EntityId, String relatedEntityInternalId, String attributeName) throws SecurityException;
+
EntityFactory getEntityFactory();
}
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.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/EntityRelationDAO.java?rev=929535&r1=929534&r2=929535&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java Wed Mar 31 13:38:34 2010
@@ -30,11 +30,11 @@ public interface EntityRelationDAO
{
SecurityEntityRelationType getRelationType();
- Collection<Entity> getRelatedEntitiesFrom(EntityDAO fromDao, EntityDAO toDao, Entity fromEntity);
+ Collection<Entity> getRelatedEntitiesFrom(EntityDAO fromDao, EntityDAO toDao, Entity fromEntity) throws SecurityException;
- Collection<Entity> getRelatedEntitiesTo(EntityDAO fromDao, EntityDAO toDao, Entity toEntity);
+ Collection<Entity> getRelatedEntitiesTo(EntityDAO fromDao, EntityDAO toDao, Entity toEntity) throws SecurityException;
- void addRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity) throws SecurityException;
+ void addRelation(EntityDAO sourceDao, EntityDAO targetDao, String sourceEntityId, String targetEntityId) throws SecurityException;
- void removeRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity) throws SecurityException;
+ void removeRelation(EntityDAO sourceDao, EntityDAO targetDao, String sourceEntityId, String targetEntityId) throws SecurityException;
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -55,7 +55,7 @@ public class LDAPEntityDAOConfiguration
{
throw new RuntimeException("Unsupported ldapIdAttribute Attribute definition: multi-value, optional and/or relationOnly attribute");
}
- def.setIdAttributeName(true);
+ def.setEntityIdAttribute(true);
idAttributeNameFound = true;
break;
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -22,8 +22,8 @@ import org.apache.commons.lang.StringUti
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
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;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.filter.Filter;
@@ -45,17 +45,17 @@ public class AttributeBasedRelationDAO e
// not used, then the attribute
// contains the ID(s).
- public Collection<Entity> getRelatedEntitiesFrom(EntityDAO fromDAO, EntityDAO toDAO, Entity fromEntity)
+ public Collection<Entity> getRelatedEntitiesFrom(EntityDAO fromDAO, EntityDAO toDAO, Entity fromEntity) throws SecurityException
{
return internalGetRelatedEntities(fromDAO, toDAO, useFromEntityAttribute, fromEntity);
}
- public Collection<Entity> getRelatedEntitiesTo(EntityDAO fromDAO, EntityDAO toDAO, Entity toEntity)
+ public Collection<Entity> getRelatedEntitiesTo(EntityDAO fromDAO, EntityDAO toDAO, Entity toEntity) throws SecurityException
{
return internalGetRelatedEntities(toDAO, fromDAO, !useFromEntityAttribute, toEntity);
}
- private Collection<Entity> internalGetRelatedEntities(EntityDAO fromDAO, EntityDAO toDAO, boolean useFromEntityAttribute, Entity entity)
+ private Collection<Entity> internalGetRelatedEntities(EntityDAO fromDAO, EntityDAO toDAO, boolean useFromEntityAttribute, Entity entity) throws SecurityException
{
if (useFromEntityAttribute)
{
@@ -63,17 +63,11 @@ public class AttributeBasedRelationDAO e
if (relationAttrValue != null)
{
Collection<String> values = relationAttrValue.getValues();
- if (relationAttrValue.getDefinition().isRequired())
+ AttributeDef attrDef = relationAttrValue.getDefinition();
+ if (attrDef.isMultiValue() && attrDef.isRequired())
{
- String defaultValue = relationAttrValue.getDefinition().getRequiredDefaultValue();
- if (defaultValue != null)
- {
- if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(defaultValue))
- {
- defaultValue = entity.getInternalId();
- }
- values.remove(defaultValue);
- }
+ String defaultValue = attrDef.requiresDnDefaultValue() ? entity.getInternalId() : attrDef.getRequiredDefaultValue();
+ values.remove(defaultValue);
}
if (attributeContainsInternalId)
{
@@ -102,7 +96,7 @@ public class AttributeBasedRelationDAO e
return null;
}
- private String getInternalId(Entity entity, EntityDAO entityDao)
+ private String getInternalId(Entity entity, EntityDAO entityDao) throws SecurityException
{
if (StringUtils.isEmpty(entity.getInternalId()))
{
@@ -128,122 +122,36 @@ public class AttributeBasedRelationDAO e
this.attributeContainsInternalId = attributeContainsInternalId;
}
- private Entity getLiveEntity(EntityDAO dao, Entity transientEntity) throws SecurityException
+ public void addRelation(EntityDAO sourceDao, EntityDAO targetDao, String sourceEntityId, String targetEntityId) throws SecurityException
{
- Entity liveEntity = dao.getEntity(transientEntity.getId());
- if (liveEntity == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(transientEntity.getType(), transientEntity.getId()));
- }
- if (liveEntity.getInternalId() == null)
- {
- throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getLiveEntity", "Internal ID not found"));
- }
- return liveEntity;
- }
-
- private void internalAddRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity) throws SecurityException
- {
- fromEntity = getLiveEntity(fromEntityDAO, fromEntity);
- toEntity = getLiveEntity(toEntityDAO, toEntity);
- String attrValue = null;
- if (attributeContainsInternalId)
- {
- attrValue = toEntity.getInternalId();
+ if (useFromEntityAttribute)
+ {
+ sourceDao.addRelation(sourceEntityId, targetDao.getInternalId(targetEntityId, true), relationAttribute);
}
else
{
- attrValue = toEntity.getId();
- }
- Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute, true);
- if (relationAttribute.getDefinition().isMultiValue())
- {
- if (!relationAttribute.getValues().contains(attrValue))
- {
- relationAttribute.getValues().add(attrValue);
- fromEntityDAO.updateInternalAttributes(fromEntity);
- }
- }
- else if (!attrValue.equals(relationAttribute.getValue()))
- {
- relationAttribute.setValue(attrValue);
- fromEntityDAO.updateInternalAttributes(fromEntity);
+ targetDao.addRelation(targetEntityId, sourceDao.getInternalId(sourceEntityId, true), relationAttribute);
}
}
- private void internalRemoveRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity) throws SecurityException
+ public void removeRelation(EntityDAO sourceDao, EntityDAO targetDao, String sourceEntityId, String targetEntityId) throws SecurityException
{
- fromEntity = fromEntityDAO.getEntity(fromEntity.getId());
- if (fromEntity != null)
+ if (useFromEntityAttribute)
{
- Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute);
- if (relationAttribute != null)
+ String internalEntityId = targetDao.getInternalId(targetEntityId, false);
+ if (internalEntityId != null)
{
- toEntity = toEntityDAO.getEntity(toEntity.getId());
- if (toEntity != null)
- {
- String attrValue = null;
- if (attributeContainsInternalId)
- {
- attrValue = toEntity.getInternalId();
- }
- else
- {
- attrValue = toEntity.getId();
- }
- if (relationAttribute.getDefinition().isMultiValue())
- {
- // 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(attrValue);
- }
- }
- else
- {
- relationAttribute.setValue(null);
- }
- fromEntityDAO.updateInternalAttributes(fromEntity);
- }
+ sourceDao.removeRelation(sourceEntityId, internalEntityId, relationAttribute);
}
}
- }
-
- public void addRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity) throws SecurityException
- {
- if (useFromEntityAttribute)
- {
- internalAddRelation(sourceDao, targetDao, sourceEntity, targetEntity);
- }
else
{
- internalAddRelation(targetDao, sourceDao, targetEntity, sourceEntity);
+ String internalEntityId = sourceDao.getInternalId(sourceEntityId, false);
+ if (internalEntityId != null)
+ {
+ targetDao.removeRelation(targetEntityId, internalEntityId, relationAttribute);
+ }
}
}
- public void removeRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity) throws SecurityException
- {
- if (useFromEntityAttribute)
- {
- internalRemoveRelation(sourceDao, targetDao, sourceEntity, targetEntity);
- }
- else
- {
- internalRemoveRelation(targetDao, sourceDao, targetEntity, sourceEntity);
- }
- }
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -22,7 +22,6 @@ import java.util.Iterator;
import java.util.List;
import javax.naming.Binding;
-import javax.naming.Name;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
@@ -42,8 +41,11 @@ import org.apache.jetspeed.security.mapp
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.AttributeInUseException;
import org.springframework.ldap.NameAlreadyBoundException;
import org.springframework.ldap.NameNotFoundException;
+import org.springframework.ldap.NamingException;
+import org.springframework.ldap.SchemaViolationException;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.DirContextProcessor;
import org.springframework.ldap.core.DistinguishedName;
@@ -60,13 +62,6 @@ import org.springframework.ldap.filter.O
*/
public class SpringLDAPEntityDAO implements EntityDAO
{
- public static final String DN_REFERENCE_MARKER = "#dn";
-
- protected enum UpdateMode
- {
- MAPPED, INTERNAL, ALL
- };
-
private static final DirContextProcessor nullDirContextProcessor = new DirContextProcessor()
{
public void postProcess(DirContext ctx) throws javax.naming.NamingException{}
@@ -119,7 +114,7 @@ public class SpringLDAPEntityDAO impleme
this.ldapTemplate = (LdapTemplate)simpleLdapTemplate.getLdapOperations();
}
- public Collection<Entity> getEntities(Filter filter)
+ public Collection<Entity> getEntities(Filter filter) throws SecurityException
{
String filterStr = createSearchFilter(filter);
Collection<Entity> results = null;
@@ -131,6 +126,10 @@ public class SpringLDAPEntityDAO impleme
getSearchControls(SearchControls.SUBTREE_SCOPE, true,configuration.getEntityAttributeNames()),
getContextMapper(), nullDirContextProcessor);
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntities", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -138,7 +137,7 @@ public class SpringLDAPEntityDAO impleme
return results;
}
- public Collection<Entity> getEntities(Entity parent, Filter filter)
+ public Collection<Entity> getEntities(Entity parent, Filter filter) throws SecurityException
{
String filterStr = createSearchFilter(filter);
Collection<Entity> results = null;
@@ -153,6 +152,10 @@ public class SpringLDAPEntityDAO impleme
getSearchControls(SearchControls.ONELEVEL_SCOPE, true,configuration.getEntityAttributeNames()),
getContextMapper(), nullDirContextProcessor);
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntities", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -161,12 +164,12 @@ public class SpringLDAPEntityDAO impleme
return results;
}
- public Collection<Entity> getAllEntities()
+ public Collection<Entity> getAllEntities() throws SecurityException
{
return getEntities(null);
}
- public Entity getEntity(String entityId)
+ public Entity getEntity(String entityId) throws SecurityException
{
Collection<Entity> entities = getEntities(new EqualsFilter(configuration.getLdapIdAttribute(), entityId));
if (entities != null && entities.size() == 1)
@@ -176,7 +179,7 @@ public class SpringLDAPEntityDAO impleme
return null;
}
- public Collection<Entity> getEntitiesById(Collection<String> entityIds)
+ public Collection<Entity> getEntitiesById(Collection<String> entityIds) throws SecurityException
{
OrFilter filter = new OrFilter();
String idAttr = configuration.getLdapIdAttribute();
@@ -187,7 +190,7 @@ public class SpringLDAPEntityDAO impleme
return getEntities(filter);
}
- public Entity getEntityByInternalId(String internalId)
+ public Entity getEntityByInternalId(String internalId) throws SecurityException
{
Entity resultEntity = null;
DistinguishedName principalDN = getRelativeDN(internalId);
@@ -205,6 +208,10 @@ public class SpringLDAPEntityDAO impleme
resultEntity = result.get(0);
}
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityByInternalId", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -213,7 +220,7 @@ public class SpringLDAPEntityDAO impleme
return resultEntity;
}
- public Collection<Entity> getEntitiesByInternalId(Collection<String> internalIds)
+ public Collection<Entity> getEntitiesByInternalId(Collection<String> internalIds) throws SecurityException
{
final Collection<Entity> resultSet = new ArrayList<Entity>();
for (Iterator<String> iterator = internalIds.iterator(); iterator.hasNext();)
@@ -227,20 +234,25 @@ public class SpringLDAPEntityDAO impleme
return resultSet;
}
- public Entity getParentEntity(Entity childEntity)
+ public Entity getParentEntity(Entity childEntity) throws SecurityException
{
DistinguishedName parentDN = new DistinguishedName(childEntity.getInternalId());
parentDN.removeLast();
return getEntityByInternalId(parentDN.encode());
}
- protected String getInternalId(Entity entity)
+ protected String getInternalId(Entity entity, boolean required) throws SecurityException
{
if (entity.getInternalId() != null)
{
return entity.getInternalId();
}
- String filterStr = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entity.getId()));
+ return getInternalId(entity.getId(), required);
+ }
+
+ public String getInternalId(String entityId, boolean required) throws SecurityException
+ {
+ String filterStr = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entityId));
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try
{
@@ -249,28 +261,44 @@ public class SpringLDAPEntityDAO impleme
ldapTemplate.search(configuration.getSearchDN(), filterStr, getSearchControls(SearchControls.SUBTREE_SCOPE, false, new String[0]), handler);
if (handler.getList().isEmpty() || handler.getList().size() != 1)
{
+ if (required)
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(configuration.getEntityType(), entityId));
+ }
return null;
}
return ((Binding)handler.getList().get(0)).getNameInNamespace();
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getInternalId", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
- public DirContextOperations getEntityContext(Entity entity, boolean withAttributes)
+ protected DirContextOperations getEntityContext(Entity entity, boolean withAttributes) throws SecurityException
{
if (entity.getInternalId() != null)
{
- return getEntityContext(entity.getInternalId(), withAttributes);
+ return getEntityContextByInternalId(entity.getInternalId(), withAttributes);
}
+ else
+ {
+ return getEntityContextById(entity.getId(), withAttributes);
+ }
+ }
+
+ protected DirContextOperations getEntityContextById(String entityId, boolean withAttributes) throws SecurityException
+ {
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
- ldapTemplate.search(configuration.getSearchDN(), createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entity.getId())),
+ ldapTemplate.search(configuration.getSearchDN(), createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(), entityId)),
getSearchControls(SearchControls.SUBTREE_SCOPE, true, withAttributes ? configuration.getEntityAttributeNames() : new String[0]),
handler);
if (!handler.getList().isEmpty() && handler.getList().size() == 1)
@@ -278,6 +306,10 @@ public class SpringLDAPEntityDAO impleme
return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
}
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityContext", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -285,7 +317,7 @@ public class SpringLDAPEntityDAO impleme
return null;
}
- public DirContextOperations getEntityContext(String internalId, boolean withAttributes)
+ protected DirContextOperations getEntityContextByInternalId(String internalId, boolean withAttributes) throws SecurityException
{
DistinguishedName principalDN = getRelativeDN(internalId);
if (configuration.getSearchDN().size() == 0 || principalDN.endsWith(configuration.getSearchDN()))
@@ -303,6 +335,10 @@ public class SpringLDAPEntityDAO impleme
return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
}
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityContext", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -329,66 +365,67 @@ public class SpringLDAPEntityDAO impleme
internalAdd(entity, new DistinguishedName(configuration.getSearchDN()));
}
- public void internalAdd(Entity entity, DistinguishedName dn) throws SecurityException
+ protected void internalAdd(Entity entity, DistinguishedName dn) throws SecurityException
{
- Attributes attributes = new BasicAttributes();
if (dn != null)
{
dn.add(configuration.getLdapIdAttribute(), entity.getId());
- String fullDN = null;
+ String internalId = getFullDN(dn).encode();
+ Attributes attributes = new BasicAttributes();
+
+ BasicAttribute basicAttr = new BasicAttribute("objectClass");
+ for (String objClass : configuration.getObjectClassesArray())
+ {
+ basicAttr.add(objClass);
+ }
+ attributes.put(basicAttr);
+
for (AttributeDef attrDef : configuration.getAttributeDefinitionsMap().values())
{
- Attribute entityAttr = attrDef.isRelationOnly() ? null : entity.getAttribute(attrDef.getName());
- BasicAttribute basicAttr = null;
- if (entityAttr != null)
+ basicAttr = null;
+ if (attrDef.isIdAttribute())
{
- if (attrDef.isMultiValue())
- {
- Collection<String> entityAttrValues = entityAttr.getValues();
- if (entityAttrValues != null && entityAttrValues.size() > 0)
- {
- basicAttr = new BasicAttribute(attrDef.getName());
- for (String val : entityAttrValues)
- {
- basicAttr.add(val);
- }
- }
- }
- else
+ basicAttr = new BasicAttribute(attrDef.getName());
+ basicAttr.add(entity.getId());
+ }
+ else if (attrDef.isRelationOnly() || !attrDef.isMapped())
+ {
+ if (attrDef.isMultiValue() && attrDef.isRequired())
{
basicAttr = new BasicAttribute(attrDef.getName());
- basicAttr.add(entityAttr.getValue());
+ basicAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
}
}
- else
+ else if (attrDef.isMapped())
{
- if (attrDef.isIdAttribute())
+ if (attrDef.isMultiValue() && attrDef.isRequired())
{
basicAttr = new BasicAttribute(attrDef.getName());
- basicAttr.add(entity.getId());
+ basicAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
}
- else if (attrDef.isRequired())
+
+ Attribute entityAttr = entity.getAttribute(attrDef.getName());
+ if (entityAttr != null)
{
- String requiredValue = attrDef.getRequiredDefaultValue();
- if (requiredValue != null && requiredValue.length() > 0)
+ if (attrDef.isMultiValue())
{
- basicAttr = new BasicAttribute(attrDef.getName());
- if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(requiredValue))
+ Collection<String> entityAttrValues = entityAttr.getValues();
+ if (entityAttrValues != null && entityAttrValues.size() > 0)
{
- if (fullDN == null)
+ if (basicAttr == null)
{
- fullDN = getFullDN(dn).encode();
+ basicAttr = new BasicAttribute(attrDef.getName());
+ }
+ for (String val : entityAttrValues)
+ {
+ basicAttr.add(val);
}
- basicAttr.add(fullDN);
- }
- else
- {
- basicAttr.add(requiredValue);
}
}
- else
+ else if (entityAttr.getValue() != null)
{
- // missing required attribute value, LDAP will/should throw exception
+ basicAttr = new BasicAttribute(attrDef.getName());
+ basicAttr.add(entityAttr.getValue());
}
}
}
@@ -397,12 +434,6 @@ public class SpringLDAPEntityDAO impleme
attributes.put(basicAttr);
}
}
- BasicAttribute attr = new BasicAttribute("objectClass");
- for (String objClass : configuration.getObjectClassesArray())
- {
- attr.add(objClass);
- }
- attributes.put(attr);
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try
{
@@ -411,8 +442,13 @@ public class SpringLDAPEntityDAO impleme
}
catch (NameAlreadyBoundException e)
{
+ // TODO: synchronize entity before throwing exception
throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "add", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
@@ -422,31 +458,66 @@ public class SpringLDAPEntityDAO impleme
public void update(Entity entity) throws SecurityException
{
- 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)
+ String internalId = getInternalId(entity, true);
+
+ Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
+ for (AttributeDef attrDef : configuration.getEntityAttributeDefinitionsMap().values())
{
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(entity.getType(), entity.getId()));
+ if (attrDef.isMapped() && !attrDef.isIdAttribute() && !attrDef.isEntityIdAttribute())
+ {
+ Attribute entityAttr = entity.getAttribute(attrDef.getName());
+ BasicAttribute namingAttr = new BasicAttribute(attrDef.getName());
+ boolean attrAdded = false;
+ if (entityAttr != null)
+ {
+ if (attrDef.isMultiValue())
+ {
+ if (attrDef.isRequired())
+ {
+ // ensure defaultValue or dnDefaultValue is always present
+ namingAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
+ attrAdded = true;
+ }
+ Collection<String> values = entityAttr.getValues();
+ if (values != null && values.size() > 0)
+ {
+ for (String val : values)
+ {
+ namingAttr.add(val);
+ }
+ attrAdded = true;
+ }
+ }
+ else
+ {
+ String value = entityAttr.getValue();
+ if (value != null)
+ {
+ namingAttr.add(value);
+ attrAdded = true;
+ }
+ }
+ }
+ if (!attrAdded && attrDef.isMultiValue() && attrDef.isRequired())
+ {
+ // ensure defaultValue or dnDefaultValue is always present
+ namingAttr.add(attrDef.requiresDnDefaultValue() ? internalId : attrDef.getRequiredDefaultValue());
+ }
+ // always use REPLACE_ATTRIBUTE even to remove an (empty) attribute
+ // as using REMOVE_ATTRIBUTE *might* throw NoSuchAttributeException (depends on server implementation)
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
+ }
}
- 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.modifyAttributes(dn, modItems.toArray(new ModificationItem[] {}));
+ ldapTemplate.modifyAttributes(getRelativeDN(internalId), modItems.toArray(new ModificationItem[] {}));
+ }
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "update", e.getMessage()), e);
}
finally
{
@@ -456,7 +527,7 @@ public class SpringLDAPEntityDAO impleme
public void remove(Entity entity) throws SecurityException
{
- String internalId = getInternalId(entity);
+ String internalId = getInternalId(entity, false);
if (internalId == null)
{
// not found
@@ -472,20 +543,101 @@ public class SpringLDAPEntityDAO impleme
{
// ignore
}
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "remove", e.getMessage()), e);
+ }
finally
{
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
- public void addRelation(String entityId, String relatedEntityId, String attributeName)
+ public void addRelation(String entityId, String relatedEntityInternalId, String attributeName) throws SecurityException
{
- // TODO
+ AttributeDef attrDef = configuration.getAttributeDef(attributeName);
+ if (attrDef == null)
+ {
+ throw new SecurityException(SecurityException.ENTITY_ATTRIBUTE_UNDEFINED.createScoped(configuration.getEntityType(), attributeName));
+ }
+ DirContextOperations dirCtxOps = getEntityContextById(entityId, false);
+ if (dirCtxOps == null)
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(configuration.getEntityType(), entityId));
+ }
+ ModificationItem[] modItems = new ModificationItem[1];
+ modItems[0] = new ModificationItem(attrDef.isMultiValue() ? DirContext.ADD_ATTRIBUTE : DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(attributeName));
+ modItems[0].getAttribute().add(relatedEntityInternalId);
+
+ ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ ldapTemplate.modifyAttributes(getRelativeDN(dirCtxOps.getNameInNamespace()), modItems);
+ }
+ catch (AttributeInUseException e)
+ {
+ // relation already defined, ignore
+ }
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "addRelation", e.getMessage()), e);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(currentClassLoader);
+ }
}
- public void removeRelation(String EntityId, String relatedEntityId, String attributeName)
+ public void removeRelation(String entityId, String relatedEntityInternalId, String attributeName) throws SecurityException
{
- // TODO
+ AttributeDef attrDef = configuration.getAttributeDef(attributeName);
+ if (attrDef == null)
+ {
+ throw new SecurityException(SecurityException.ENTITY_ATTRIBUTE_UNDEFINED.createScoped(configuration.getEntityType(), attributeName));
+ }
+ DirContextOperations dirCtxOps = getEntityContextById(entityId, false);
+ if (dirCtxOps == null)
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(configuration.getEntityType(), entityId));
+ }
+ ModificationItem[] modItems = new ModificationItem[1];
+ modItems[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(attributeName));
+ if (attrDef.isMultiValue())
+ {
+ modItems[0].getAttribute().add(relatedEntityInternalId);
+ }
+
+ ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ try
+ {
+ ldapTemplate.modifyAttributes(getRelativeDN(dirCtxOps.getNameInNamespace()), modItems);
+ }
+ catch (SchemaViolationException e)
+ {
+ // required multi-value attribute removal?
+ if (!(attrDef.isMultiValue() && attrDef.isRequired()))
+ {
+ throw e;
+ }
+ // replace with required default or dn
+ modItems[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(attributeName));
+ modItems[0].getAttribute().add(attrDef.requiresDnDefaultValue() ? dirCtxOps.getNameInNamespace() : attrDef.getRequiredDefaultValue());
+ // try again
+ ldapTemplate.modifyAttributes(getRelativeDN(dirCtxOps.getNameInNamespace()), modItems);
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "removeRelation", e.getMessage()), e);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(currentClassLoader);
+ }
}
protected SearchControls getSearchControls(int searchScope, boolean returningObjFlag, String[] attrs)
@@ -497,85 +649,6 @@ public class SpringLDAPEntityDAO impleme
return controls;
}
- protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, UpdateMode umode)
- {
- Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
- for (AttributeDef attrDef : configuration.getEntityAttributeDefinitionsMap().values())
- {
- if (!attrDef.getName().equals(configuration.getLdapIdAttribute()))
- {
- if (umode == UpdateMode.ALL || (umode == UpdateMode.MAPPED && attrDef.isMapped()) || (umode == UpdateMode.INTERNAL && !attrDef.isMapped()))
- {
- Attribute entityAttr = entity.getAttribute(attrDef.getName());
- boolean attrAdded = false;
- if (entityAttr != null)
- {
- if (attrDef.isMultiValue())
- {
- Collection<String> values = entityAttr.getValues();
- if (values != null)
- {
- javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName());
- if (values.size() > 0)
- {
- for (String val : values)
- {
- namingAttr.add(val);
- }
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
- attrAdded = true;
- }
- }
- }
- else
- {
- String value = entityAttr.getValue();
- if (value != null)
- {
- javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName(), entityAttr.getValue());
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
- attrAdded = true;
- }
- }
- }
- if (!attrAdded)
- {
- // entity attribute not added, so remove it if present
- // in ldap.
- Object namingAttrValue = dirCtxOps.getObjectAttribute(attrDef.getName());
- if (namingAttrValue != null)
- {
- BasicAttribute basicAttr = new BasicAttribute(attrDef.getName());
- if (attrDef.isRequired())
- {
- if (attrDef.getRequiredDefaultValue() != null)
- {
- String defaultValue = attrDef.getRequiredDefaultValue();
- if (SpringLDAPEntityDAO.DN_REFERENCE_MARKER.equals(defaultValue))
- {
- defaultValue = entity.getInternalId();
- }
- basicAttr.add(defaultValue);
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, basicAttr));
- }
- else
- {
- // TODO throw exception
- break;
- }
- }
- else
- {
- modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, basicAttr));
- }
- }
- }
- }
- }
- }
- return modItems;
- }
-
protected DistinguishedName getRelativeDN(String fullDN)
{
DistinguishedName principalDN = new DistinguishedName(fullDN);
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -33,12 +33,14 @@ public interface AttributeDef
boolean isRequired();
String getRequiredDefaultValue();
+
+ boolean requiresDnDefaultValue();
boolean isIdAttribute();
boolean isRelationOnly();
- boolean isIdAttributeName();
+ boolean isEntityIdAttribute();
- void setIdAttributeName(boolean idAttributeName);
+ void setEntityIdAttribute(boolean idAttributeName);
}
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=929535&r1=929534&r2=929535&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 Wed Mar 31 13:38:34 2010
@@ -31,12 +31,12 @@ public class AttributeDefImpl implements
private boolean required = false;
private String requiredDefaultValue;
private boolean idAttribute;
- private boolean idAttributeName;
+ private boolean entityIdAttribute;
private boolean relationOnly;
+ private Boolean dnDefaultValue;
public AttributeDefImpl(String name)
{
- super();
this.name = name;
this.mappedName = name; // default mapping
}
@@ -111,9 +111,18 @@ public class AttributeDefImpl implements
public void setRequiredDefaultValue(String requiredDefaultValue)
{
- this.requiredDefaultValue = requiredDefaultValue;
+ this.requiredDefaultValue = (requiredDefaultValue != null && requiredDefaultValue.length() == 0) ? null : requiredDefaultValue;
}
-
+
+ public boolean requiresDnDefaultValue()
+ {
+ if (dnDefaultValue == null)
+ {
+ dnDefaultValue = isMultiValue() && isRequired() && getRequiredDefaultValue() == null ? Boolean.TRUE : Boolean.FALSE;
+ }
+ return dnDefaultValue.booleanValue();
+ }
+
public AttributeDefImpl cfgRequired(boolean required)
{
setRequired(required);
@@ -140,14 +149,14 @@ public class AttributeDefImpl implements
return relationOnly;
}
- public boolean isIdAttributeName()
+ public boolean isEntityIdAttribute()
{
- return idAttributeName;
+ return entityIdAttribute;
}
- public void setIdAttributeName(boolean idAttributeName)
+ public void setEntityIdAttribute(boolean entityIdAttribute)
{
- this.idAttributeName = idAttributeName;
+ this.entityIdAttribute = entityIdAttribute;
}
public AttributeDefImpl cfgRequiredDefaultValue(String requiredDefaultValue)
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/JetspeedSecuritySynchronizer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/JetspeedSecuritySynchronizer.java?rev=929535&r1=929534&r2=929535&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/JetspeedSecuritySynchronizer.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/JetspeedSecuritySynchronizer.java Wed Mar 31 13:38:34 2010
@@ -16,6 +16,8 @@
*/
package org.apache.jetspeed.security.spi;
+import org.apache.jetspeed.security.SecurityException;
+
/**
* @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
* @version $Id$
@@ -27,7 +29,7 @@ public interface JetspeedSecuritySynchro
* Synchronizes the user principal with the specified name.
* @param name
*/
- void synchronizeUserPrincipal(String name, boolean recursive);
+ void synchronizeUserPrincipal(String name, boolean recursive) throws SecurityException;
/**
* Synchronize all principals of a certain type.
@@ -35,11 +37,11 @@ public interface JetspeedSecuritySynchro
* @param recursive if true, all nested principals associated to this principal will be synchronized. If false, only the direct (first level) associated
* principals will be synchronized.
*/
- void synchronizePrincipalsByType(String principalTypeName, boolean recursive);
+ void synchronizePrincipalsByType(String principalTypeName, boolean recursive) throws SecurityException;
/**
* Synchronizes all principals.
*/
- void synchronizeAll();
+ void synchronizeAll() throws SecurityException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org