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 11:37:04 UTC
svn commit: r700722 - in
/portals/jetspeed-2/portal/branches/security-refactoring:
components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/
components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/lda...
Author: ddam
Date: Wed Oct 1 02:37:03 2008
New Revision: 700722
URL: http://svn.apache.org/viewvc?rev=700722&view=rev
Log:
finished update functionality for LDAP entities. added "required" and "requiredDefaultValue" to attribute definition
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.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/AttributeDef.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.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/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.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/impl/EntityFactoryImpl.java?rev=700722&r1=700721&r2=700722&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.java Wed Oct 1 02:37:03 2008
@@ -101,7 +101,14 @@
{
Collection<String> attrValues = new ArrayList<String>();
attrValues.addAll(Arrays.asList(values));
- a.setValues(attrValues);
+ // remove the dummy value for required fields when present.
+ if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && attrValues.contains(attrDef.getRequiredDefaultValue())){
+ attrValues.remove(attrDef.getRequiredDefaultValue());
+ }
+ if (attrValues.size() != 0){
+ a.setValues(attrValues);
+ attributes.add(a);
+ }
} else
{
if (attrDef.getName().equals(
@@ -110,8 +117,8 @@
entityId = values[0];
}
a.setValue(values[0]);
+ attributes.add(a);
}
- attributes.add(a);
}
}
return internalCreateEntity(entityId, ctx.getNameInNamespace().toString(), attributes);
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=700722&r1=700721&r2=700722&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 02:37:03 2008
@@ -264,9 +264,15 @@
if (attrDef.isMultiValue()){
Collection<String> values = entityAttr.getValues();
if (values != null){
- javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName(), entityAttr.getValues().toArray());
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,namingAttr));
- attrAdded = true;
+ 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();
@@ -281,7 +287,18 @@
// entity attribute not added, so remove it if present in ldap.
Object namingAttrValue = dirCtxOps.getObjectAttribute(attrDef.getName());
if (namingAttrValue != null){
- modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute(attrDef.getName(), namingAttrValue)));
+ BasicAttribute basicAttr = new BasicAttribute(attrDef.getName());
+ if (attrDef.isRequired()){
+ if (attrDef.isMultiValue() && attrDef.getRequiredDefaultValue() != null){
+ basicAttr.add(attrDef.getRequiredDefaultValue());
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,basicAttr));
+ } else {
+ // TODO throw exception
+ break;
+ }
+ } 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/AttributeDef.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/AttributeDef.java?rev=700722&r1=700721&r2=700722&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/AttributeDef.java Wed Oct 1 02:37:03 2008
@@ -30,5 +30,9 @@
boolean isMapped();
String getMappedName();
+
+ boolean isRequired();
+
+ String getRequiredDefaultValue();
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java?rev=700722&r1=700721&r2=700722&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/impl/AttributeDefImpl.java Wed Oct 1 02:37:03 2008
@@ -33,6 +33,10 @@
private boolean mapped=true;
+ private boolean required=false;
+
+ private String requiredDefaultValue;
+
public AttributeDefImpl(String name)
{
super();
@@ -93,6 +97,37 @@
{
this.multiValue = multiValue;
}
+
+ public boolean isRequired()
+ {
+ return required;
+ }
+
+ public void setRequired(boolean required)
+ {
+ this.required = required;
+ }
+
+ public String getRequiredDefaultValue()
+ {
+ return requiredDefaultValue;
+ }
+
+
+ public void setRequiredDefaultValue(String requiredDefaultValue)
+ {
+ this.requiredDefaultValue = requiredDefaultValue;
+ }
+
+ public AttributeDefImpl cfgRequired(boolean required){
+ setRequired(required);
+ return this;
+ }
+
+ public AttributeDefImpl cfgRequiredDefaultValue(String requiredDefaultValue){
+ setRequiredDefaultValue(requiredDefaultValue);
+ return this;
+ }
@Override
public int hashCode()
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=700722&r1=700721&r2=700722&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 02:37:03 2008
@@ -58,6 +58,9 @@
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;
@@ -102,6 +105,7 @@
roleAttrDefs = new HashSet<AttributeDef>();
roleAttrDefs.addAll(basicAttrDefs);
roleAttrDefs.add(DESCRIPTION_ATTR_DEF);
+ roleAttrDefs.add(UNIQUEMEMBER_ATTR_DEF);
LDAPEntityDAOConfiguration roleSearchConfig = new LDAPEntityDAOConfiguration();
roleSearchConfig.setBaseDN("o=sevenSeas");
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=700722&r1=700721&r2=700722&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 02:37:03 2008
@@ -17,6 +17,7 @@
package org.apache.jetspeed.security.mapping.ldap.setup1;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import org.apache.jetspeed.security.mapping.model.Entity;
@@ -40,18 +41,30 @@
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
}
- public void testFetchRolesForUserByRoleAttribute() throws Exception
- {
+ private EntityImpl getInitialRole1(){
EntityImpl role1 = new EntityImpl("role", "Role1", roleAttrDefs);
role1.setInternalId("cn=Role1, o=sevenSeas");
role1.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 1");
role1.setAttribute(CN_DEF.getName(), "Role1");
-
+
+ role1.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), Arrays.asList(new String[]{
+ "cn=OrgUnit2User1,ou=People,ou=OrgUnit2,o=sevenSeas",
+ "cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas",
+ "cn=OrgUnit2User2,ou=People,ou=OrgUnit2,o=sevenSeas"}) );
+ return role1;
+ }
+
+ public void testFetchRolesForUserByRoleAttribute() throws Exception
+ {
+
+ Entity role1 = getInitialRole1();
EntityImpl role3 = new EntityImpl("role", "Role3", roleAttrDefs);
role3.setInternalId("cn=Role3, o=sevenSeas");
role3.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 3");
role3.setAttribute(CN_DEF.getName(), "Role3");
-
+ role3.setAttribute(UNIQUEMEMBER_ATTR_DEF.getName(), Arrays.asList(new String[]{
+ "cn=jsmith,ou=People,ou=OrgUnit3,o=sevenSeas"
+ }));
Collection<Entity> resultSet = new ArrayList<Entity>();
resultSet.add(role1);
resultSet.add(role3);
@@ -59,8 +72,9 @@
"jsmith", resultSet);
}
- public void testUpdateEntity() throws Exception
+ 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");
@@ -69,7 +83,8 @@
sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
- // test attribute modification
+ // 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);
@@ -88,6 +103,36 @@
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
}
+ public void testUpdateMultivaluedEntityAttr() throws Exception
+ {
+ // first assert that the sample user is equal to the corresponding user in LDAP
+ EntityImpl sampleRole = getInitialRole1();
+
+ basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
+
+ // 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);
+
+
+ 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);
+ basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
+
+ // 2. test attribute removal
+ sampleRole = new EntityImpl("role", "Role1", roleAttrDefs);
+ sampleRole.setInternalId("cn=Role1, o=sevenSeas");
+ sampleRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Role 1");
+ sampleRole.setAttribute(CN_DEF.getName(), "Role1");
+
+ entityManager.update(sampleRole);
+
+ basicTestCases.testFetchSingleEntity(entityManager, sampleRole);
+ }
+
@Override
protected void internaltearDown() throws Exception
{
Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml?rev=700722&r1=700721&r2=700722&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml Wed Oct 1 02:37:03 2008
@@ -163,6 +163,8 @@
<constructor-arg type="java.lang.String" index="0" value="uniqueMember" />
<constructor-arg index="1" value="true" />
<constructor-arg index="2" value="false" />
+ <property name="required" value="true" />
+ <property name="requiredDefaultValue" value="uid=foobar" />
</bean>
</set>
</property>
@@ -200,6 +202,8 @@
<constructor-arg type="java.lang.String" index="0" value="uniqueMember" />
<constructor-arg index="1" value="true" />
<constructor-arg index="2" value="false" />
+ <property name="required" value="true" />
+ <property name="requiredDefaultValue" value="uid=foobar" />
</bean>
</set>
</property>
@@ -322,4 +326,4 @@
<value>${ldap.search.scope}</value>
</constructor-arg>
</bean>
-</beans>
\ No newline at end of file
+</beans>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org