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 vk...@apache.org on 2008/10/03 19:05:48 UTC
svn commit: r701446 - in
/portals/jetspeed-2/portal/branches/security-refactoring:
components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/
components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/
co...
Author: vkumar
Date: Fri Oct 3 10:05:47 2008
New Revision: 701446
URL: http://svn.apache.org/viewvc?rev=701446&view=rev
Log:
Few corrections replication code.
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java
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/SpringLDAPEntityDAO.java
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.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/EntityFactory.java?rev=701446&r1=701445&r2=701446&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/EntityFactory.java Fri Oct 3 10:05:47 2008
@@ -16,6 +16,9 @@
*/
package org.apache.jetspeed.security.mapping;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
import org.apache.jetspeed.security.JetspeedPrincipal;
import org.apache.jetspeed.security.mapping.model.Entity;
import org.springframework.ldap.core.DirContextOperations;
@@ -31,6 +34,6 @@
Entity createEntity(JetspeedPrincipal principal);
- Entity createEntity(DirContextOperations ctx);
+ Entity createEntity(DirContext ctx);
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.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/SecurityEntityManager.java?rev=701446&r1=701445&r2=701446&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityManager.java Fri Oct 3 10:05:47 2008
@@ -18,6 +18,7 @@
import java.util.Collection;
+import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.model.Entity;
/**
@@ -37,15 +38,15 @@
Collection<Entity> getAllEntities(String entityType);
- void addEntity(Entity entity);
+ void addEntity(Entity entity) throws SecurityException;
- void removeEntity(Entity entity);
+ void removeEntity(Entity entity) throws SecurityException;
- void updateEntity(Entity entity);
+ void updateEntity(Entity entity) throws SecurityException;
- void addRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType);
+ void addRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException;
- void removeRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType);
+ void removeRelation(Entity fromEntity, Entity toEntity, SecurityEntityRelationType relationType) throws SecurityException;
Collection<Entity> getRelatedEntitiesFrom(Entity fromEntity, SecurityEntityRelationType relationType);
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/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?rev=701446&r1=701445&r2=701446&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/EntityFactoryImpl.java Fri Oct 3 10:05:47 2008
@@ -22,6 +22,11 @@
import java.util.HashSet;
import java.util.Set;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
import org.apache.jetspeed.security.JetspeedPrincipal;
import org.apache.jetspeed.security.SecurityAttribute;
import org.apache.jetspeed.security.SecurityAttributes;
@@ -33,67 +38,93 @@
import org.apache.jetspeed.security.mapping.model.impl.AttributeImpl;
import org.apache.jetspeed.security.mapping.model.impl.EntityImpl;
import org.springframework.ldap.core.DirContextOperations;
-
+import org.springframework.ldap.support.LdapUtils;
/**
* @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
* @version $Id$
*/
-
public class EntityFactoryImpl implements EntityFactory
{
-
LDAPEntityDAOConfiguration searchConfiguration;
- public EntityFactoryImpl(
- LDAPEntityDAOConfiguration searchConfiguration)
+ public EntityFactoryImpl(LDAPEntityDAOConfiguration searchConfiguration)
{
this.searchConfiguration = searchConfiguration;
}
- private EntityImpl internalCreateEntity(String entityId, String internalId, Set<Attribute> attributes){
- if (entityId != null)
- {
- EntityImpl entity = new EntityImpl(searchConfiguration
- .getEntityType(), entityId, searchConfiguration
- .getAttributeDefinitions());
- entity.setAttributes(attributes);
- if (internalId != null){
- entity.setInternalId(internalId);
- }
- entity.setType(searchConfiguration.getEntityType());
- return entity;
- } else
+ private EntityImpl internalCreateEntity(String entityId, String internalId, Set<Attribute> attributes)
+ {
+ EntityImpl entity = new EntityImpl(searchConfiguration.getEntityType(), entityId, searchConfiguration.getAttributeDefinitions());
+ entity.setAttributes(attributes);
+ if (internalId != null)
{
- return null;
+ entity.setInternalId(internalId);
}
+ entity.setType(searchConfiguration.getEntityType());
+ return entity;
}
-
+
public Entity createEntity(JetspeedPrincipal principal)
{
Set<Attribute> ldapAttrValues = new HashSet<Attribute>();
SecurityAttributes sas = principal.getSecurityAttributes();
- for (AttributeDef attrDef : searchConfiguration
- .getAttributeDefinitions())
+ for (AttributeDef attrDef : searchConfiguration.getAttributeDefinitions())
{
SecurityAttribute sa = sas.getAttribute(attrDef.getMappedName());
- if (sa!=null){
+ if (sa != null)
+ {
// currently only single-valued attributes are supported
ldapAttrValues.add(new AttributeImpl(attrDef));
}
}
- return internalCreateEntity(principal.getName(),null,ldapAttrValues);
+ return internalCreateEntity(principal.getName(), null, ldapAttrValues);
}
- public Entity createEntity(DirContextOperations ctx)
+ public String[] getStringAttributes(Attributes originalAttrs, String name)
+ {
+ String[] attributes;
+ javax.naming.directory.Attribute attribute = originalAttrs.get(name);
+ if (attribute != null && attribute.size() > 0)
+ {
+ attributes = new String[attribute.size()];
+ for (int i = 0; i < attribute.size(); i++)
+ {
+ try
+ {
+ attributes[i] = (String) attribute.get(i);
+ }
+ catch (NamingException e)
+ {
+ throw LdapUtils.convertLdapException(e);
+ }
+ }
+ }
+ else
+ {
+ return null;
+ }
+ return attributes;
+ }
+
+ public Entity createEntity(DirContext ctx)
{
String entityId = null;
+ Entity entity = null;
Set<Attribute> attributes = new HashSet<Attribute>();
- for (AttributeDef attrDef : searchConfiguration
- .getAttributeDefinitions())
+ for (AttributeDef attrDef : searchConfiguration.getAttributeDefinitions())
{
-
- String[] values = ctx.getStringAttributes(attrDef.getName());
+ String[] values = null;
+ try
+ {
+
+ values = getStringAttributes(ctx.getAttributes(""), attrDef.getName());
+ }
+ catch (NamingException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
if (values != null && values.length > 0)
{
Attribute a = new AttributeImpl(attrDef);
@@ -101,33 +132,45 @@
{
Collection<String> attrValues = new ArrayList<String>();
attrValues.addAll(Arrays.asList(values));
- // remove the dummy value for required fields when present.
- if (attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && attrValues.contains(attrDef.getRequiredDefaultValue())){
+ // 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){
+ if (attrValues.size() != 0)
+ {
a.setValues(attrValues);
attributes.add(a);
}
- } else
+ }
+ else
{
- if (attrDef.getName().equals(
- searchConfiguration.getLdapIdAttribute()))
+ if (attrDef.getName().equals(searchConfiguration.getLdapIdAttribute()))
{
entityId = values[0];
}
- 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()))){
+ if (values[0] != null)
+ {
+ // check if the value is not the required default value (a dummy value) If it is, ignore the attribute.
+ if (!(attrDef.isRequired() && attrDef.getRequiredDefaultValue() != null && values[0].equals(attrDef.getRequiredDefaultValue())))
+ {
a.setValue(values[0]);
attributes.add(a);
- }
+ }
}
-
}
}
}
- return internalCreateEntity(entityId, ctx.getNameInNamespace().toString(), attributes);
+ try
+ {
+ entity = internalCreateEntity(entityId, ctx.getNameInNamespace(), attributes);
+ }
+ catch (NamingException e)
+ {
+ entity = null;
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return entity;
}
-
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/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/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java?rev=701446&r1=701445&r2=701446&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java Fri Oct 3 10:05:47 2008
@@ -16,27 +16,31 @@
*/
package org.apache.jetspeed.security.mapping.ldap.dao;
+import javax.naming.directory.DirContext;
+
import org.apache.jetspeed.security.mapping.EntityFactory;
-import org.springframework.ldap.core.DirContextOperations;
-import org.springframework.ldap.core.support.AbstractContextMapper;
+import org.springframework.ldap.core.ContextMapper;
/**
* @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
* @version $Id$
*/
-public class DefaultEntityContextMapper extends AbstractContextMapper
+public class DefaultEntityContextMapper implements ContextMapper
{
EntityFactory entityFactory;
+
+
public DefaultEntityContextMapper(EntityFactory entityFactory)
{
this.entityFactory = entityFactory;
}
- public Object doMapFromContext(DirContextOperations ctx)
+ public Object mapFromContext(Object ctx)
{
- return entityFactory.createEntity(ctx);
+ DirContext context = (DirContext)ctx;
+ return entityFactory.createEntity(context);
}
}
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=701446&r1=701445&r2=701446&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 Fri Oct 3 10:05:47 2008
@@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Map;
+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.SecurityEntityRelationType;
@@ -138,7 +139,7 @@
// types and relation type is not configured.
}
- public void updateEntity(Entity entity)
+ public void updateEntity(Entity entity) throws SecurityException
{
EntityDAO dao = getDAOForEntity(entity);
if (dao != null)
@@ -147,16 +148,16 @@
}
}
- public void removeEntity(Entity entity)
+ public void removeEntity(Entity entity) throws SecurityException
{
EntityDAO dao = getDAOForEntity(entity);
if (dao != null)
{
- dao.update(entity);
+ dao.remove(entity);
}
}
- public void addEntity(Entity entity)
+ public void addEntity(Entity entity) throws SecurityException
{
EntityDAO dao = getDAOForEntity(entity);
if (dao != null)
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=701446&r1=701445&r2=701446&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 Fri Oct 3 10:05:47 2008
@@ -18,6 +18,7 @@
import java.util.Collection;
+import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.EntityFactory;
import org.apache.jetspeed.security.mapping.model.Entity;
import org.springframework.ldap.filter.Filter;
@@ -73,15 +74,15 @@
*/
Collection<Entity> getAllEntities();
- void update(Entity entity);
+ void update(Entity entity) throws SecurityException;
- void updateInternalAttributes(Entity entity);
+ void updateInternalAttributes(Entity entity) throws SecurityException ;
- void add(Entity entity);
+ void add(Entity entity) throws SecurityException;
- void remove(Entity entity);
+ void remove(Entity entity) throws SecurityException;
- void add(Entity entity, Entity parentEntity);
+ void add(Entity entity, Entity parentEntity) throws SecurityException;
EntityFactory getEntityFactory();
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=701446&r1=701445&r2=701446&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 Fri Oct 3 10:05:47 2008
@@ -23,12 +23,12 @@
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;
import org.apache.commons.lang.StringUtils;
+import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.mapping.EntityFactory;
import org.apache.jetspeed.security.mapping.ldap.EntityFactoryImpl;
import org.apache.jetspeed.security.mapping.ldap.dao.DefaultEntityContextMapper;
@@ -54,8 +54,11 @@
*/
public class SpringLDAPEntityDAO implements EntityDAO
{
- private enum UpdateMode { MAPPED , INTERNAL, ALL };
-
+ private enum UpdateMode
+ {
+ MAPPED, INTERNAL, ALL
+ };
+
protected LdapTemplate ldapTemplate;
protected LDAPEntityDAOConfiguration configuration;
private ContextMapper contextMapper;
@@ -74,6 +77,31 @@
this.ldapTemplate = ldapTemplate;
}
+ public LDAPEntityDAOConfiguration getConfiguration()
+ {
+ return configuration;
+ }
+
+ public ContextMapper getContextMapper()
+ {
+ return contextMapper;
+ }
+
+ public EntityFactory getEntityFactory()
+ {
+ return entityFactory;
+ }
+
+ public void setLdapTemplate(LdapTemplate ldapTemplate)
+ {
+ this.ldapTemplate = ldapTemplate;
+ }
+
+ public void setContextMapper(ContextMapper contextMapper)
+ {
+ this.contextMapper = contextMapper;
+ }
+
public Entity getEntity(String entityId)
{
Filter idFilter = createFilterForIdSearch(entityId);
@@ -115,7 +143,7 @@
{
String internalId = (String) iterator.next();
DistinguishedName principalDN = getRelativeDN(internalId);
- internalId = principalDN.toString();
+ internalId = principalDN.toString();
Entity resultEntity = (Entity) ldapTemplate.lookup(internalId, getContextMapper());
if (resultEntity != null)
{
@@ -124,16 +152,19 @@
}
return resultSet;
}
-
- protected DistinguishedName getRelativeDN(String fullDN){
+
+ protected DistinguishedName getRelativeDN(String fullDN)
+ {
DistinguishedName principalDN = new DistinguishedName(fullDN);
- if (configuration.getBaseDN() != null && configuration.getBaseDN().length() > 0){
+ if (configuration.getBaseDN() != null && configuration.getBaseDN().length() > 0)
+ {
principalDN.removeFirst(new DistinguishedName(configuration.getBaseDN()));
}
return principalDN;
}
- protected String createSearchFilter(Filter filter){
+ protected String createSearchFilter(Filter filter)
+ {
if (configuration.getSearchFilter() != null)
{
if (filter == null)
@@ -152,7 +183,7 @@
}
return filterStr;
}
-
+
@SuppressWarnings("unchecked")
public Collection<Entity> getEntities(Filter filter)
{
@@ -166,209 +197,238 @@
return getEntities(new SimpleFilter(finalFilter));
}
- public void update(Entity entity)
+ private void internalUpdate(Entity entity, UpdateMode umode) throws SecurityException
{
- internalUpdate(entity, UpdateMode.MAPPED);
+ Name dn = getRelativeDN(entity.getInternalId());
+ DirContextOperations dirCtxOps = ldapTemplate.lookupContext(dn);
+ if (dirCtxOps == null)
+ {
+ throw new SecurityException(SecurityException.UNEXPECTED);
+ }
+ Collection<ModificationItem> modItems = getModItems(entity, dirCtxOps, umode);
+ ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[] {}));
}
-
- public void updateInternalAttributes(Entity entity)
+
+ public void add(Entity entity, Entity parentEntity) throws SecurityException
{
- internalUpdate(entity, UpdateMode.INTERNAL);
+ // TODO need to be implemented
}
- private void internalUpdate(Entity entity, UpdateMode umode)
+ public void add(Entity entity) throws SecurityException
{
- String internalIdStr = entity.getInternalId();
- if (internalIdStr == null){
- Entity ldapEntity = getEntity(entity.getId());
- if (ldapEntity == null || ldapEntity.getInternalId() == null){
- // TODO throw exception
- return;
- }
- internalIdStr = entity.getInternalId();
- }
- Name dn=getRelativeDN(internalIdStr);
- DirContextOperations dirCtxOps = ldapTemplate.lookupContext(dn);
- if (dirCtxOps == null){
- // TODO throw exception
- return;
- }
- Collection<ModificationItem> modItems = getModItems(entity,dirCtxOps,umode);
- ldapTemplate.modifyAttributes(dn, modItems.toArray(new ModificationItem[]{}));
- }
-
- public void add(Entity entity)
- {
- if (entityExists(entity)){
- // TODO throw exception
- return;
+ if (entityExists(entity))
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
}
DistinguishedName dn = new DistinguishedName();
- if (configuration.getSearchDN() != null && configuration.getSearchDN().length() > 0){
- try{
+ if (configuration.getSearchDN() != null && configuration.getSearchDN().length() > 0)
+ {
+ try
+ {
dn.add(configuration.getSearchDN());
- } catch (InvalidNameException inex){
+ }
+ catch (InvalidNameException inex)
+ {
// TODO throw exception
dn = null;
}
}
-
DirContextAdapter context = new DirContextAdapter();
-
- if (dn != null){
+ if (dn != null)
+ {
dn.add(configuration.getLdapIdAttribute(), entity.getId());
- BasicAttributes basicAttrs = new BasicAttributes();
- for (AttributeDef attrDef : configuration.getAttributeDefinitions()){
+ for (AttributeDef attrDef : configuration.getAttributeDefinitions())
+ {
Attribute entityAttr = entity.getAttribute(attrDef.getName());
BasicAttribute basicAttr = null;
- if (entityAttr != null){
- if (attrDef.isMultiValue()){
+ if (entityAttr != null)
+ {
+ if (attrDef.isMultiValue())
+ {
Collection<String> entityAttrValues = entityAttr.getValues();
- if (entityAttrValues != null && entityAttrValues.size() > 0){
+ if (entityAttrValues != null && entityAttrValues.size() > 0)
+ {
basicAttr = new BasicAttribute(attrDef.getName());
- for (String val : entityAttrValues){
+ for (String val : entityAttrValues)
+ {
basicAttr.add(val);
}
- }
- } else {
+ }
+ }
+ else
+ {
basicAttr = new BasicAttribute(attrDef.getName());
basicAttr.add(entityAttr.getValue());
}
- } else {
- if (attrDef.isIdAttribute()){
+ }
+ else
+ {
+ if (attrDef.isIdAttribute())
+ {
basicAttr = new BasicAttribute(attrDef.getName());
basicAttr.add(entity.getId());
- } else if (attrDef.isRequired()){
+ }
+ else if (attrDef.isRequired())
+ {
String requiredValue = attrDef.getRequiredDefaultValue();
- if (requiredValue != null && requiredValue.length() > 0){
+ if (requiredValue != null && requiredValue.length() > 0)
+ {
basicAttr = new BasicAttribute(attrDef.getName());
basicAttr.add(attrDef.getRequiredDefaultValue());
}
- } else {
+ }
+ else
+ {
// TODO missing required attribute value, throw exception
- return;
+ // return;
}
}
-
- if (basicAttr != null){
+ if (basicAttr != null)
+ {
context.setAttribute(basicAttr);
}
}
- BasicAttribute attr = new BasicAttribute("objectClass",configuration.getObjectClass());
+ BasicAttribute attr = new BasicAttribute("objectClass", configuration.getObjectClass());
context.setAttribute(attr);
-
ldapTemplate.bind(dn, context, null);
}
-
- }
-
- public void remove(Entity entity)
- {
- }
-
-
- public void add(Entity entity, Entity parentEntity)
- {
-
}
- public LDAPEntityDAOConfiguration getConfiguration()
+ public void remove(Entity entity) throws SecurityException
{
- return configuration;
+ if (!entityExists(entity))
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
+ }
+ String internalIdStr = entity.getInternalId();
+ if (internalIdStr == null)
+ {
+ Entity ldapEntity = getEntity(entity.getId());
+ if (ldapEntity == null || ldapEntity.getInternalId() == null)
+ {
+ // TODO throw exception
+ return;
+ }
+ else
+ {
+ internalIdStr = ldapEntity.getInternalId();
+ }
+ }
+ ldapTemplate.unbind(getRelativeDN(internalIdStr));
}
- public ContextMapper getContextMapper()
+ public void update(Entity entity) throws SecurityException
{
- return contextMapper;
+ Entity ldapEntity = getEntity(entity.getId());
+ if (ldapEntity == null)
+ {
+ throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(entity.getType(), entity.getId()));
+ }
+ internalUpdate(ldapEntity, UpdateMode.MAPPED);
}
- public EntityFactory getEntityFactory()
+ public void updateInternalAttributes(Entity entity) throws SecurityException
{
- return entityFactory;
+ internalUpdate(entity, UpdateMode.INTERNAL);
}
- public void setLdapTemplate(LdapTemplate ldapTemplate)
+ protected boolean entityExists(Entity entity)
{
- this.ldapTemplate = ldapTemplate;
+ return getEntity(entity.getId()) != null;
}
- public void setContextMapper(ContextMapper contextMapper)
+ protected boolean setNamingAttribute(Attribute entityAttr, DirContextOperations dirCtxOps)
{
- 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){
+ if (entityAttr != null)
+ {
AttributeDef attrDef = entityAttr.getDefinition();
- if (attrDef.isMultiValue()){
+ if (attrDef.isMultiValue())
+ {
Collection<String> values = entityAttr.getValues();
- if (values != null){
- dirCtxOps.setAttributeValues(attrDef.getName(),values.toArray());
+ if (values != null)
+ {
+ dirCtxOps.setAttributeValues(attrDef.getName(), values.toArray());
attrAdded = true;
}
- } else {
+ }
+ else
+ {
String value = entityAttr.getValue();
- if (value != null){
- dirCtxOps.setAttributeValue(attrDef.getName(),value);
+ if (value != null)
+ {
+ dirCtxOps.setAttributeValue(attrDef.getName(), value);
attrAdded = true;
}
- }
- }
+ }
+ }
return attrAdded;
}
-
- protected Collection<ModificationItem> getModItems(Entity entity, DirContextOperations dirCtxOps, UpdateMode umode){
+
+ 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())){
- if (umode == UpdateMode.ALL || (umode == UpdateMode.MAPPED && attrDef.isMapped()) || (umode == UpdateMode.INTERNAL && !attrDef.isMapped())){
+ for (AttributeDef attrDef : configuration.getAttributeDefinitions())
+ {
+ 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()){
+ if (entityAttr != null)
+ {
+ if (attrDef.isMultiValue())
+ {
Collection<String> values = entityAttr.getValues();
- if (values != null){
+ if (values != null)
+ {
javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName());
- if (values.size() > 0){
+ if (values.size() > 0)
+ {
for (String val : values)
- {
+ {
namingAttr.add(val);
}
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,namingAttr));
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
attrAdded = true;
}
}
- } else {
+ }
+ else
+ {
String value = entityAttr.getValue();
- if (value != null){
+ if (value != null)
+ {
javax.naming.directory.Attribute namingAttr = new BasicAttribute(entityAttr.getName(), entityAttr.getValue());
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,namingAttr));
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, namingAttr));
attrAdded = true;
}
- }
- }
- if (!attrAdded){
+ }
+ }
+ if (!attrAdded)
+ {
// entity attribute not added, so remove it if present in ldap.
Object namingAttrValue = dirCtxOps.getObjectAttribute(attrDef.getName());
- if (namingAttrValue != null){
+ if (namingAttrValue != null)
+ {
BasicAttribute basicAttr = new BasicAttribute(attrDef.getName());
- if (attrDef.isRequired()){
- if (attrDef.getRequiredDefaultValue() != null){
+ if (attrDef.isRequired())
+ {
+ if (attrDef.getRequiredDefaultValue() != null)
+ {
basicAttr.add(attrDef.getRequiredDefaultValue());
- modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,basicAttr));
- } else {
+ modItems.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, basicAttr));
+ }
+ else
+ {
// TODO throw exception
break;
}
- } else {
- modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE,basicAttr));
+ }
+ else
+ {
+ modItems.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, basicAttr));
}
}
}
@@ -377,11 +437,9 @@
}
return modItems;
}
-
+
protected Filter createFilterForIdSearch(String entityId)
{
return SearchUtil.constructMatchingFieldsFilter(configuration.getSearchFilter(), new String[] { configuration.getLdapIdAttribute(), entityId });
}
-
-
}
Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties?rev=701446&r1=701445&r2=701446&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties Fri Oct 3 10:05:47 2008
@@ -217,7 +217,7 @@
#-------------------------------------------------------------------------
#defaults for LDAP
ldap.url = ldap://localhost:389
-ldap.base =o=sevenSea
+ldap.base =o=sevenSeas
ldap.userDn = cn=admin,o=sevenSeas
ldap.password =secret
ldap.context.factory=com.sun.jndi.ldap.LdapCtxFactory
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org