Author: ddam
Date: Wed Oct 1 03:55:24 2008
New Revision: 700736
URL:
http://svn.apache.org/viewvc?rev=700736&view=revLog:
make a distinction between updating internal attributes and mapped attributes. Only one category of attributes can be updated at one time.
Added:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java (contents, props changed)
- copied, changed from r700722, portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.java
Removed:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.java
Modified:
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/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
Copied: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java (from r700722, 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/ldap/EntityFactoryImpl.java?p2=portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java&p1=portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/EntityFactoryImpl.java&r1=700722&r2=700736&rev=700736&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/ldap/EntityFactoryImpl.java Wed Oct 1 03:55:24 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jetspeed.security.mapping.impl;
+package org.apache.jetspeed.security.mapping.ldap;
import java.util.ArrayList;
import java.util.Arrays;
@@ -116,8 +116,14 @@
{
entityId = values[0];
}
- a.setValue(values[0]);
- attributes.add(a);
+ if (values[0] !=null){
+ // check if the value is ä¹ot the required default value (a dummy value) If it is, ignore the attribute.
+ if (!(attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && values[0].equals(attrDef.getRequiredDefaultValue()))){
+ a.setValue(values[0]);
+ attributes.add(a);
+ }
+ }
+
}
}
}
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
------------------------------------------------------------------------------
svn:mergeinfo =
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=700736&r1=700735&r2=700736&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 03:55:24 2008
@@ -75,6 +75,8 @@
void update(Entity entity);
+ void update(Entity entity, boolean updateMappedAttributes);
+
void addEntity(Entity entity);
void removeEntity(Entity entity);
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=700736&r1=700735&r2=700736&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 03:55:24 2008
@@ -144,7 +144,7 @@
{
relationAttribute.setValue(attrValue);
}
- fromEntityDAO.update(fromEntity);
+ fromEntityDAO.update(fromEntity,false);
}
private void internalRemoveRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity)
@@ -172,7 +172,7 @@
{
relationAttribute.setValue(null);
}
- fromEntityDAO.update(fromEntity);
+ fromEntityDAO.update(fromEntity,false);
}
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=700736&r1=700735&r2=700736&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 03:55:24 2008
@@ -28,7 +28,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.jetspeed.security.mapping.EntityFactory;
-import org.apache.jetspeed.security.mapping.impl.EntityFactoryImpl;
+import org.apache.jetspeed.security.mapping.ldap.EntityFactoryImpl;
import org.apache.jetspeed.security.mapping.ldap.dao.DefaultEntityContextMapper;
import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
import org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
@@ -164,6 +164,11 @@
public void update(Entity entity)
{
+ update(entity,true);
+ }
+
+ public void update(Entity entity, boolean updateMappedAttributes)
+ {
String internalIdStr = entity.getInternalId();
if (internalIdStr == null){
Entity ldapEntity = getEntity(entity.getId());
@@ -179,7 +184,7 @@
// TODO throw exception
return;
}
- Collection<ModificationItem> modItems = getModItems(entity,dirCtxOps);
+ Collection<ModificationItem> modItems = getModItems(entity,dirCtxOps,updateMappedAttributes);
ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[]{}));
}
@@ -253,11 +258,12 @@
return attrAdded;
}
- protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps){
+ protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, boolean useMappedAttributes){
Collection<ModificationItem> modItems = new ArrayList<ModificationItem>();
for(AttributeDef attrDef : configuration.getAttributeDefinitions()){
- if (!attrDef.getName().equals(configuration.getLdapIdAttribute())){
+
+ if (!attrDef.getName().equals(configuration.getLdapIdAttribute()) && ( (useMappedAttributes && attrDef.isMapped()) || (!useMappedAttributes && !attrDef.isMapped()))){
Attribute entityAttr = entity.getAttribute(attrDef.getName());
boolean attrAdded = false;
if (entityAttr != null){
@@ -289,7 +295,7 @@
if (namingAttrValue != null){
BasicAttribute basicAttr = new BasicAttribute(attrDef.getName());
if (attrDef.isRequired()){
- if (attrDef.isMultiValue() && attrDef.getRequiredDefaultValue() != null){
+ if (attrDef.getRequiredDefaultValue() != null){
basicAttr.add(attrDef.getRequiredDefaultValue());
modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,basicAttr));
} else {
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=700736&r1=700735&r2=700736&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 03:55:24 2008
@@ -45,7 +45,7 @@
public abstract class AbstractSetup1LDAPTest extends AbstractLDAPTest
{
- public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn");
+ public static final AttributeDefImpl CN_DEF = new AttributeDefImpl("cn").cfgRequired(true);
public static final AttributeDefImpl UID_DEF = new AttributeDefImpl("uid");
@@ -87,7 +87,7 @@
userAttrDefs = new HashSet<AttributeDef>();
userAttrDefs.addAll(basicAttrDefs);
userAttrDefs.add(GIVEN_NAME_DEF);
-
+
userSearchConfig = new LDAPEntityDAOConfiguration();
userSearchConfig.setBaseDN("o=sevenSeas");
userSearchConfig.setSearchDN("");
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=700736&r1=700735&r2=700736&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 03:55:24 2008
@@ -101,6 +101,30 @@
entityManager.update(sampleUser);
basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
+
+ // add "lastname" attribute value
+ sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
+ sampleUser
+ .setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
+ sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(LAST_NAME_DEF.getName(), "jsmith");
+
+ entityManager.update(sampleUser);
+
+ basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
+
+ // test attribute removal of required attribute ("lastname") with a required default value set for it
+ sampleUser = new EntityImpl("user", "jsmith", userAttrDefs);
+ sampleUser
+ .setInternalId("cn=jsmith, ou=People, ou=OrgUnit3, o=sevenSeas");
+ sampleUser.setAttribute(CN_DEF.getName(), "jsmith");
+ sampleUser.setAttribute(UID_DEF.getName(), "jsmith");
+
+ entityManager.update(sampleUser);
+
+ basicTestCases.testFetchSingleEntity(entityManager, sampleUser);
+
}
public void testUpdateMultivaluedEntityAttr() throws Exception
---------------------------------------------------------------------
To unsubscribe, e-mail:
jetspeed-dev-unsubscribe@...
For additional commands, e-mail:
jetspeed-dev-help@...