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 dd...@apache.org on 2008/10/01 17:39:04 UTC
svn commit: r700816 - in
/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src:
main/java/org/apache/jetspeed/security/mapping/ldap/dao/
main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/
main/java/org/apa...
Author: ddam
Date: Wed Oct 1 08:39:04 2008
New Revision: 700816
URL: http://svn.apache.org/viewvc?rev=700816&view=rev
Log:
added support for adding entities to LDAP + testcases
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java Wed Oct 1 08:39:04 2008
@@ -161,7 +161,7 @@
EntityDAO dao = getDAOForEntity(entity);
if (dao != null)
{
- dao.addEntity(entity);
+ dao.add(entity);
}
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityDAO.java Wed Oct 1 08:39:04 2008
@@ -75,17 +75,13 @@
void update(Entity entity);
- void update(Entity entity, boolean updateMappedAttributes);
+ void updateInternalAttributes(Entity entity);
- void addEntity(Entity entity);
+ void add(Entity entity);
- void removeEntity(Entity entity);
+ void remove(Entity entity);
- void update(Entity entity, Entity parentEntity);
-
- void addEntity(Entity entity, Entity parentEntity);
-
- void removeEntity(Entity entity, Entity parentEntity);
+ void add(Entity entity, Entity parentEntity);
EntityFactory getEntityFactory();
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java Wed Oct 1 08:39:04 2008
@@ -144,7 +144,7 @@
{
relationAttribute.setValue(attrValue);
}
- fromEntityDAO.update(fromEntity,false);
+ fromEntityDAO.updateInternalAttributes(fromEntity);
}
private void internalRemoveRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity)
@@ -172,7 +172,7 @@
{
relationAttribute.setValue(null);
}
- fromEntityDAO.update(fromEntity,false);
+ fromEntityDAO.updateInternalAttributes(fromEntity);
}
public void addRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity)
{
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java Wed Oct 1 08:39:04 2008
@@ -20,8 +20,10 @@
import java.util.Collection;
import java.util.Iterator;
+import javax.naming.InvalidNameException;
import javax.naming.Name;
import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
@@ -38,6 +40,7 @@
import org.apache.jetspeed.security.mapping.model.AttributeDef;
import org.apache.jetspeed.security.mapping.model.Entity;
import org.springframework.ldap.core.ContextMapper;
+import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
@@ -51,12 +54,13 @@
*/
public class SpringLDAPEntityDAO implements EntityDAO
{
+ private enum UpdateMode { MAPPED , INTERNAL, ALL };
+
protected LdapTemplate ldapTemplate;
protected LDAPEntityDAOConfiguration configuration;
private ContextMapper contextMapper;
private EntityFactory entityFactory;
-
public SpringLDAPEntityDAO(LDAPEntityDAOConfiguration configuration)
{
super();
@@ -164,10 +168,15 @@
public void update(Entity entity)
{
- update(entity,true);
+ internalUpdate(entity, UpdateMode.MAPPED);
}
- public void update(Entity entity, boolean updateMappedAttributes)
+ public void updateInternalAttributes(Entity entity)
+ {
+ internalUpdate(entity, UpdateMode.INTERNAL);
+ }
+
+ private void internalUpdate(Entity entity, UpdateMode umode)
{
String internalIdStr = entity.getInternalId();
if (internalIdStr == null){
@@ -184,30 +193,81 @@
// TODO throw exception
return;
}
- Collection<ModificationItem> modItems = getModItems(entity,dirCtxOps,updateMappedAttributes);
+ Collection<ModificationItem> modItems = getModItems(entity,dirCtxOps,umode);
ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[]{}));
}
-
- public void addEntity(Entity entity)
+
+ public void add(Entity entity)
{
- }
+ if (entityExists(entity)){
+ // TODO throw exception
+ return;
+ }
+ DistinguishedName dn = new DistinguishedName();
+ if (configuration.getSearchDN() != null && configuration.getSearchDN().length() > 0){
+ try{
+ dn.add(configuration.getSearchDN());
+ } catch (InvalidNameException inex){
+ // TODO throw exception
+ dn = null;
+ }
+ }
- public void removeEntity(Entity entity)
- {
- }
+ DirContextAdapter context = new DirContextAdapter();
-
- public void addEntity(Entity entity, Entity parentEntity)
- {
+ if (dn != null){
+ dn.add(configuration.getLdapIdAttribute(), entity.getId());
+ BasicAttributes basicAttrs = new BasicAttributes();
+ for (AttributeDef attrDef : configuration.getAttributeDefinitions()){
+ Attribute entityAttr = entity.getAttribute(attrDef.getName());
+ BasicAttribute basicAttr = null;
+ if (entityAttr != null){
+ 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(entityAttr.getValue());
+ }
+ } else {
+ if (attrDef.isIdAttribute()){
+ basicAttr = new BasicAttribute(attrDef.getName());
+ basicAttr.add(entity.getId());
+ } else if (attrDef.isRequired()){
+ String requiredValue = attrDef.getRequiredDefaultValue();
+ if (requiredValue != null && requiredValue.length() > 0){
+ basicAttr = new BasicAttribute(attrDef.getName());
+ basicAttr.add(attrDef.getRequiredDefaultValue());
+ }
+ } else {
+ // TODO missing required attribute value, throw exception
+ return;
+ }
+ }
+
+ if (basicAttr != null){
+ context.setAttribute(basicAttr);
+ }
+ }
+ BasicAttribute attr = new BasicAttribute("objectClass",configuration.getObjectClass());
+ context.setAttribute(attr);
+
+ ldapTemplate.bind(dn, context, null);
+ }
}
- public void removeEntity(Entity entity, Entity parentEntity)
+ public void remove(Entity entity)
{
-
}
- public void update(Entity entity, Entity parentEntity)
+
+ public void add(Entity entity, Entity parentEntity)
{
}
@@ -237,6 +297,10 @@
this.contextMapper = contextMapper;
}
+ protected boolean entityExists(Entity entity){
+ return getEntity(entity.getId()) != null;
+ }
+
protected boolean setNamingAttribute(Attribute entityAttr, DirContextOperations dirCtxOps){
boolean attrAdded = false;
if (entityAttr != null){
@@ -258,52 +322,54 @@
return attrAdded;
}
- protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, boolean useMappedAttributes){
+ protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, UpdateMode umode){
Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
for(AttributeDef attrDef : configuration.getAttributeDefinitions()){
- if (!attrDef.getName().equals(configuration.getLdapIdAttribute()) && ( (useMappedAttributes && attrDef.isMapped()) || (!useMappedAttributes && !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);
+ 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;
}
- }
- } 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){
- basicAttr.add(attrDef.getRequiredDefaultValue());
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,basicAttr));
+ }
+ }
+ 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){
+ basicAttr.add(attrDef.getRequiredDefaultValue());
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,basicAttr));
+ } else {
+ // TODO throw exception
+ break;
+ }
} else {
- // TODO throw exception
- break;
+ modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE,basicAttr));
}
- } else {
- modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE,basicAttr));
}
}
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeImpl.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeImpl.java Wed Oct 1 08:39:04 2008
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import org.apache.jetspeed.security.mapping.model.Attribute;
import org.apache.jetspeed.security.mapping.model.AttributeDef;
@@ -114,4 +115,24 @@
return definition;
}
+ public String toString(){
+ StringBuffer sb = new StringBuffer();
+ sb.append(getName());
+ sb.append("=");
+ if (getDefinition().isMultiValue()){
+ Collection<String> values = getValues();
+ if (values != null){
+ Iterator<String> valIter = values.iterator();
+ while (valIter.hasNext()){
+ sb.append(values.getClass());
+ if (valIter.hasNext()){
+ sb.append(",");
+ }
+ }
+ }
+ } else {
+ sb.append(getValue());
+ }
+ return sb.toString();
+ }
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/EntityImpl.java Wed Oct 1 08:39:04 2008
@@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -42,7 +43,7 @@
private String internalId;
private String type;
-
+
public EntityImpl(String type, String id,
Set<AttributeDef> allowedAttributes)
{
@@ -199,5 +200,25 @@
} else if (!type.equals(other.type)) return false;
return true;
}
+
+ public String toString(){
+ StringBuffer sb = new StringBuffer();
+ sb.append("Entity of type '");
+ sb.append(getType());
+ sb.append("'\nid=");
+ sb.append(getId());
+ sb.append("\ninternalId=");
+ sb.append(getInternalId());
+ sb.append("\nAmount of attributes: ");
+ sb.append(nameToAttributeMap.values().size());
+ sb.append("\n");
+ for (Attribute attr : nameToAttributeMap.values())
+ {
+ sb.append("attribute: ");
+ sb.append(attr.toString());
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java Wed Oct 1 08:39:04 2008
@@ -38,6 +38,7 @@
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.apache.jetspeed.security.mapping.model.impl.AttributeDefImpl;
/**
* @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
@@ -45,6 +46,27 @@
*/
public abstract class AbstractLDAPTest extends TestCase
{
+
+ public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn",false,false).cfgRequired(true).cfgIdAttribute(true);
+
+ public static final AttributeDefImpl SN_DEF = new AttributeDefImpl("sn",false,false).cfgRequired(true).cfgIdAttribute(true);
+
+ public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid",false,false).cfgRequired(true).cfgIdAttribute(true);
+
+ public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
+ "givenName");;
+
+ public static final AttributeDefImpl LAST_NAME_DEF = new AttributeDefImpl(
+ "lastname");;
+
+ public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
+ "description");
+
+ public static final AttributeDefImpl UNIQUEMEMBER_ATTR_DEF = new AttributeDefImpl(
+ "uniqueMember",true).cfgRequired(true).cfgRequiredDefaultValue("uid=someDummyValue");
+
+ public static final AttributeDefImpl J2_ROLE_DEF = new AttributeDefImpl(
+ "j2-role",true); // multi-valued attribute
protected LdapTemplate ldapTemplate;
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/AbstractSetup1LDAPTest.java Wed Oct 1 08:39:04 2008
@@ -45,28 +45,14 @@
public abstract class AbstractSetup1LDAPTest extends AbstractLDAPTest
{
- public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn").cfgRequired(true);
-
- public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid");
-
- public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
- "givenName");;
-
- public static final AttributeDefImpl LAST_NAME_DEF = new AttributeDefImpl(
- "lastname");;
-
- public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
- "description");
-
- public static final AttributeDefImpl UNIQUEMEMBER_ATTR_DEF = new AttributeDefImpl(
- "uniqueMember",true).cfgRequired(true).cfgRequiredDefaultValue("uid=someDummyValue");
-
protected Set<AttributeDef> userAttrDefs;
protected Set<AttributeDef> roleAttrDefs;
protected AttributeBasedRelationDAO hasRoleDAO;
+ protected SpringLDAPEntityDAO userDAO;
+
public Resource[] initializationData()
{
final ClassPathResource ldapPersonInfo = new ClassPathResource(
@@ -87,6 +73,7 @@
userAttrDefs = new HashSet<AttributeDef>();
userAttrDefs.addAll(basicAttrDefs);
userAttrDefs.add(GIVEN_NAME_DEF);
+ userAttrDefs.add(SN_DEF);
userSearchConfig = new LDAPEntityDAOConfiguration();
userSearchConfig.setBaseDN("o=sevenSeas");
@@ -96,8 +83,9 @@
userSearchConfig.setLdapIdAttribute("uid");
userSearchConfig.setAttributeDefinitions(userAttrDefs);
userSearchConfig.setEntityType("user");
+ userSearchConfig.setObjectClass("inetOrgPerson");
- SpringLDAPEntityDAO userDAO = new SpringLDAPEntityDAO(userSearchConfig);
+ userDAO = new SpringLDAPEntityDAO(userSearchConfig);
userDAO.setLdapTemplate(ldapTemplate);
// setting up role DAO
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup1/UserTests.java Wed Oct 1 08:39:04 2008
@@ -38,6 +38,8 @@
sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(SN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
}
@@ -54,6 +56,26 @@
return role1;
}
+ private EntityImpl getDefaultJoeSmith(){
+ // first assert that the sample user is equal to the corresponding user in LDAP
+ EntityImpl sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
+ sampleUser
+ .setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
+ sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
+ sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(SN_DEF.getName(), "jsmith");
+ return sampleUser;
+ }
+
+ private EntityImpl getDefaultJoeSmithOnlyMappedAttrs(){
+ // first assert that the sample user is equal to the corresponding user in LDAP
+ EntityImpl sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
+ sampleUser.setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
+ sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
+ return sampleUser;
+ }
+
public void testFetchRolesForUserByRoleAttribute() throws Exception
{
@@ -75,18 +97,13 @@
public void testUpdateSingleValuedEntityAttr() throws Exception
{
// first assert that the sample user is equal to the corresponding user in LDAP
- EntityImpl sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
- sampleUser
- .setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
- sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
- sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
- sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ EntityImpl sampleUser = getDefaultJoeSmith();
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
// next, try some identity transformation checks to assert that updating works
// 1. test attribute modification
sampleUser.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith modified");
- entityManager.update(sampleUser);
+ entityManager.updateEntity(sampleUser);
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
@@ -97,8 +114,9 @@
.setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(SN_DEF.getName(), "jsmith");
- entityManager.update(sampleUser);
+ entityManager.updateEntity(sampleUser);
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
@@ -108,9 +126,10 @@
.setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(SN_DEF.getName(), "jsmith");
sampleUser.setAttribute(LAST_NAME_DEF.getName(), "jsmith");
- entityManager.update(sampleUser);
+ entityManager.updateEntity(sampleUser);
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
@@ -119,9 +138,10 @@
sampleUser
.setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(SN_DEF.getName(), "jsmith");
sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
- entityManager.update(sampleUser);
+ entityManager.updateEntity(sampleUser);
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
@@ -137,13 +157,13 @@
// next, try some identity transformation checks to assert that updating works
// 1. test attribute modification
sampleRole.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), Arrays.asList(new String[]{"cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas"}) );
- entityManager.update(sampleRole);
+ entityManager.updateEntity(sampleRole);
basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
sampleRole.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), Arrays.asList(new String[]{"cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas","cn=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas"}) );
- entityManager.update(sampleRole);
+ entityManager.updateEntity(sampleRole);
basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
// 2. test attribute removal
@@ -152,11 +172,41 @@
sampleRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 1");
sampleRole.setAttribute(CN_DEF.getName(), "Role1");
- entityManager.update(sampleRole);
+ // note: we call the user DAO directly, because updating internal
+ // attributes is only meant to be used internally, e.g. from within an EntityRelationDAO
+ entityManager.updateEntity(sampleRole);
basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
}
+ public void testAddEntity() throws Exception {
+ EntityImpl jsmithCopy = getDefaultJoeSmithOnlyMappedAttrs();
+ jsmithCopy.setId("jsmithCopy");
+
+ entityManager.addEntity(jsmithCopy);
+
+ jsmithCopy.setAttribute(UID_DEF.getName(), "jsmithCopy");
+ jsmithCopy.setAttribute(CN_DEF.getName(), "jsmithCopy");
+ jsmithCopy.setAttribute(SN_DEF.getName(), "jsmithCopy");
+ jsmithCopy.setInternalId("uid=jsmithCopy, o=sevenSeas");
+ basicTestCases.testFetchSingleEntity(entityManager, jsmithCopy);
+ }
+
+ public void testUpdateInternalAttrs() throws Exception {
+ EntityImpl jsmith = getDefaultJoeSmith();
+ jsmith.setAttribute(SN_DEF.getName(), "whatever");
+ jsmith.setAttribute(GIVEN_NAME_DEF.getName(), "foobar");
+
+ // note: we call the user DAO directly, because updating internal
+ // attributes is only meant to be used internally, e.g. from within an EntityRelationDAO
+ userDAO.updateInternalAttributes(jsmith);
+
+ // reset given name to value in ldap, givenName should be unmodified
+ // the (internal) sn attribute is modified in LDAP
+ jsmith.setAttribute(GIVEN_NAME_DEF.getName(), "Joe Smith");
+ basicTestCases.testFetchSingleEntity(entityManager, jsmith);
+ }
+
@Override
protected void internaltearDown() throws Exception
{
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/AbstractSetup2LDAPTest.java Wed Oct 1 08:39:04 2008
@@ -45,20 +45,6 @@
public abstract class AbstractSetup2LDAPTest extends AbstractLDAPTest
{
- public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn");
-
- public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid");
-
- public static final AttributeDefImpl GIVEN_NAME_DEF = new AttributeDefImpl(
- "givenName");;
-
- public static final AttributeDefImpl J2_ROLE_DEF = new AttributeDefImpl(
- "j2-role",true); // multi-valued attribute
-
- public static final AttributeDefImpl DESCRIPTION_ATTR_DEF = new AttributeDefImpl(
- "description");
-
-
protected Set<AttributeDef> userAttrDefs;
protected Set<AttributeDef> roleAttrDefs;
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java?rev=700816&r1=700815&r2=700816&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/stubs/StubEntityDAO.java Wed Oct 1 08:39:04 2008
@@ -105,4 +105,10 @@
}
+ public void updateInternalAttributes(Entity entity)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org