Return-Path: Delivered-To: apmail-portals-jetspeed-dev-archive@www.apache.org Received: (qmail 39612 invoked from network); 12 Sep 2008 18:40:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Sep 2008 18:40:17 -0000 Received: (qmail 71885 invoked by uid 500); 12 Sep 2008 18:40:13 -0000 Delivered-To: apmail-portals-jetspeed-dev-archive@portals.apache.org Received: (qmail 71859 invoked by uid 500); 12 Sep 2008 18:40:13 -0000 Mailing-List: contact jetspeed-dev-help@portals.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@portals.apache.org Received: (qmail 71848 invoked by uid 99); 12 Sep 2008 18:40:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Sep 2008 11:40:12 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Sep 2008 18:39:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 07E142388961; Fri, 12 Sep 2008 11:39:54 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r694772 - 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/impl/ co... Date: Fri, 12 Sep 2008 18:39:52 -0000 To: jetspeed-dev@portals.apache.org From: ddam@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080912183954.07E142388961@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ddam Date: Fri Sep 12 11:39:51 2008 New Revision: 694772 URL: http://svn.apache.org/viewvc?rev=694772&view=rev Log: Make a start with integration the LDAP mapping functionality in the new security framework. The synchronization code is in DefaultJetspeedPrincipalSynchronizer, and is *not* finished yet. Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.java (with props) portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java (with props) portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java (with props) portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java (with props) Modified: 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/dao/DefaultLDAPEntityManager.java portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AbstractRelationDAO.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/model/Attribute.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/Entity.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/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/BasicTestCases.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/ldap/setup2/UserTests.java 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=694772&r1=694771&r2=694772&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 Sep 12 11:39:51 2008 @@ -27,16 +27,22 @@ public interface SecurityEntityManager { + Collection getSupportedEntityTypes(); + + Collection getSupportedEntityRelationTypes(); + + Collection getSupportedEntityRelationTypes(String entityType); + Entity getEntity(String entityType, String entityId); Collection getAllEntities(String entityType); void update(Entity entity); - Collection getRelatedEntities(Entity sourceEntity, - String targetEntityType, String relationType); + Collection getRelatedEntitiesFrom(Entity toEntity, SecurityEntityRelationType relationType); + + Collection getRelatedEntitiesTo(Entity fromEntity, SecurityEntityRelationType relationType); - void addRelatedEntity(Entity entity, Entity relatedEntity, - String relationType); + void addRelatedEntity(Entity entity, Entity relatedEntity, SecurityEntityRelationType relationType); } Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.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/SecurityEntityRelationType.java?rev=694772&view=auto ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.java (added) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.java Fri Sep 12 11:39:51 2008 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.mapping; + +/** + * @author Dennis Dam + * @version $Id$ + */ +public interface SecurityEntityRelationType +{ + String getFromEntityType(); + + String getToEntityType(); + + String getRelationType(); + +} Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SecurityEntityRelationType.java ------------------------------------------------------------------------------ svn:keywords = Id Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.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/SecurityEntityRelationTypeImpl.java?rev=694772&view=auto ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java (added) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java Fri Sep 12 11:39:51 2008 @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.mapping.impl; + +import org.apache.jetspeed.security.mapping.SecurityEntityRelationType; + +/** + * @author Dennis Dam + * @version $Id$ + */ +public class SecurityEntityRelationTypeImpl implements SecurityEntityRelationType + { + + private String sourceEntityType, targetEntityType, relationType; + + public SecurityEntityRelationTypeImpl(String relationType, + String sourceEntityType, String targetEntityType) + { + super(); + this.relationType = relationType; + this.sourceEntityType = sourceEntityType; + this.targetEntityType = targetEntityType; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + + ((relationType == null) ? 0 : relationType.hashCode()); + result = prime + * result + + ((sourceEntityType == null) ? 0 : sourceEntityType + .hashCode()); + result = prime + * result + + ((targetEntityType == null) ? 0 : targetEntityType + .hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + SecurityEntityRelationType other = (SecurityEntityRelationType) obj; + if (relationType == null) + { + if (other.getRelationType() != null) return false; + } else if (!relationType.equals(other.getRelationType())) return false; + if (sourceEntityType == null) + { + if (other.getFromEntityType() != null) return false; + } else if (!sourceEntityType.equals(other.getFromEntityType())) + return false; + if (targetEntityType == null) + { + if (other.getToEntityType() != null) return false; + } else if (!targetEntityType.equals(other.getToEntityType())) + return false; + return true; + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getSourceEntityType() + */ + public String getFromEntityType() + { + return sourceEntityType; + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getTargetEntityType() + */ + public String getToEntityType() + { + return targetEntityType; + } + + /* (non-Javadoc) + * @see org.apache.jetspeed.security.mapping.ldap.dao.Temp#getRelationType() + */ + public String getRelationType() + { + return relationType; + } + + } \ No newline at end of file Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/SecurityEntityRelationTypeImpl.java ------------------------------------------------------------------------------ svn:keywords = Id 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=694772&r1=694771&r2=694772&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 Sep 12 11:39:51 2008 @@ -16,11 +16,15 @@ */ package org.apache.jetspeed.security.mapping.ldap.dao; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.jetspeed.security.mapping.SecurityEntityManager; +import org.apache.jetspeed.security.mapping.SecurityEntityRelationType; +import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl; import org.apache.jetspeed.security.mapping.model.Entity; /** @@ -33,7 +37,31 @@ // entity type DAOs protected Map entityDAOs; - protected Map entityRelationDAOs = new HashMap(); + protected Map entityRelationDAOs = new HashMap(); + + public Collection getSupportedEntityRelationTypes() + { + return Collections.unmodifiableCollection(entityRelationDAOs.keySet()); + } + + public Collection getSupportedEntityTypes() + { + return Collections.unmodifiableCollection(entityDAOs.keySet()); + } + + public Collection getSupportedEntityRelationTypes( + String entityType) + { + Collection supportedRelationTypes=new ArrayList(); + for (SecurityEntityRelationType type : entityRelationDAOs.keySet()) + { + if (type.getFromEntityType().equals(entityType) || type.getToEntityType().equals(entityType)){ + supportedRelationTypes.add(type); + } + + } + return Collections.unmodifiableCollection(supportedRelationTypes); + } private EntityDAO getDAOForEntity(Entity entity) { @@ -44,22 +72,28 @@ private EntityRelationDAO getRelationDAO(String relationType, String fromEntityType, String targetEntityType) { - return entityRelationDAOs.get(new RelationDefinitionKey(relationType, + return entityRelationDAOs.get(new SecurityEntityRelationTypeImpl(relationType, fromEntityType, targetEntityType)); } public void addRelatedEntity(Entity sourceEntity, Entity targetEntity, - String relationType) + SecurityEntityRelationType relationType) { - EntityDAO sourceDao = getDAOForEntity(sourceEntity); - EntityDAO targetDao = getDAOForEntity(targetEntity); - if (sourceDao != null && targetDao != null) + EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType); + if (relationDAO != null) { - EntityRelationDAO relationDAO = getRelationDAO(relationType, - sourceEntity.getType(), targetEntity.getType()); + EntityDAO sourceDAO; + EntityDAO targetDAO; + if (relationType.getFromEntityType().equals(sourceEntity.getType())){ + sourceDAO=entityDAOs.get(sourceEntity.getType()); + targetDAO=entityDAOs.get(relationType.getToEntityType()); + } else { + targetDAO=entityDAOs.get(sourceEntity.getType()); + sourceDAO=entityDAOs.get(relationType.getToEntityType()); + } if (relationDAO != null) { - relationDAO.relate(sourceDao, targetDao, sourceEntity, + relationDAO.relate(sourceDAO, targetDAO, sourceEntity, targetEntity); } } @@ -77,17 +111,31 @@ return dao != null ? dao.getEntity(entityId) : null; } - public Collection getRelatedEntities(Entity sourceEntity, - String targetEntityType, String relationType) + public Collection getRelatedEntitiesTo(Entity fromEntity, + SecurityEntityRelationType relationType) + { + EntityDAO fromDAO=entityDAOs.get(relationType.getFromEntityType()); + EntityDAO toDAO=entityDAOs.get(relationType.getToEntityType()); + EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType); + if (fromDAO != null && toDAO != null && relationDAO != null) + { + return relationDAO.getRelatedEntitiesTo( + fromDAO, toDAO, fromEntity); + } + return null; // todo : throw exception, since combination of entity + // types and relation type is not configured. + } + + public Collection getRelatedEntitiesFrom(Entity toEntity, + SecurityEntityRelationType relationType) { - EntityDAO sourceDAO = getDAOForEntity(sourceEntity); - EntityDAO targetDAO = entityDAOs.get(targetEntityType); - if (sourceDAO != null && targetDAO != null) - { - EntityRelationDAO relationDAO = getRelationDAO(relationType, - sourceEntity.getType(), targetEntityType); - if (relationDAO != null) { return relationDAO.getRelatedEntities( - sourceDAO, targetDAO, sourceEntity); } + EntityDAO fromDAO=entityDAOs.get(relationType.getFromEntityType()); + EntityDAO toDAO=entityDAOs.get(relationType.getToEntityType()); + EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType); + if (fromDAO != null && toDAO != null && relationDAO != null) + { + return relationDAO.getRelatedEntitiesFrom( + fromDAO, toDAO, toEntity); } return null; // todo : throw exception, since combination of entity // types and relation type is not configured. @@ -113,89 +161,8 @@ this.entityRelationDAOs.clear(); for (EntityRelationDAO dao : entityRelationDAOs) { - this.entityRelationDAOs.put(new RelationDefinitionKey(dao - .getRelationType(), dao.getFromEntityType(), dao - .getToEntityType()), dao); - } - } - - private class RelationDefinitionKey - { - - private String sourceEntityType, targetEntityType, relationType; - - public RelationDefinitionKey(String relationType, - String sourceEntityType, String targetEntityType) - { - super(); - this.relationType = relationType; - this.sourceEntityType = sourceEntityType; - this.targetEntityType = targetEntityType; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + getOuterType().hashCode(); - result = prime * result - + ((relationType == null) ? 0 : relationType.hashCode()); - result = prime - * result - + ((sourceEntityType == null) ? 0 : sourceEntityType - .hashCode()); - result = prime - * result - + ((targetEntityType == null) ? 0 : targetEntityType - .hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - RelationDefinitionKey other = (RelationDefinitionKey) obj; - if (!getOuterType().equals(other.getOuterType())) return false; - if (relationType == null) - { - if (other.relationType != null) return false; - } else if (!relationType.equals(other.relationType)) return false; - if (sourceEntityType == null) - { - if (other.sourceEntityType != null) return false; - } else if (!sourceEntityType.equals(other.sourceEntityType)) - return false; - if (targetEntityType == null) - { - if (other.targetEntityType != null) return false; - } else if (!targetEntityType.equals(other.targetEntityType)) - return false; - return true; - } - - public String getSourceEntityType() - { - return sourceEntityType; - } - - public String getTargetEntityType() - { - return targetEntityType; - } - - public String getRelationType() - { - return relationType; - } - - private DefaultLDAPEntityManager getOuterType() - { - return DefaultLDAPEntityManager.this; + this.entityRelationDAOs.put( dao.getRelationType(), dao); } - } + } Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityRelationDAO.java Fri Sep 12 11:39:51 2008 @@ -18,6 +18,7 @@ import java.util.Collection; +import org.apache.jetspeed.security.mapping.SecurityEntityRelationType; import org.apache.jetspeed.security.mapping.model.Entity; /** @@ -27,14 +28,13 @@ public interface EntityRelationDAO { - String getFromEntityType(); + SecurityEntityRelationType getRelationType(); - String getToEntityType(); + Collection getRelatedEntitiesFrom(EntityDAO fromDao, + EntityDAO toDao, Entity toEntity); - String getRelationType(); - - Collection getRelatedEntities(EntityDAO sourceDao, - EntityDAO targetDao, Entity sourceEntity); + Collection getRelatedEntitiesTo(EntityDAO fromDao, + EntityDAO toDao, Entity fromEntity); void relate(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/AbstractRelationDAO.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/AbstractRelationDAO.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AbstractRelationDAO.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AbstractRelationDAO.java Fri Sep 12 11:39:51 2008 @@ -18,6 +18,7 @@ import org.springframework.ldap.core.LdapTemplate; +import org.apache.jetspeed.security.mapping.SecurityEntityRelationType; import org.apache.jetspeed.security.mapping.ldap.dao.EntityRelationDAO; /** @@ -28,39 +29,19 @@ { private LdapTemplate ldapTemplate; - private String relationType, fromEntityType, toEntityType; - - public String getFromEntityType() - { - return fromEntityType; - } - - public String getRelationType() - { - return relationType; - } - - public String getToEntityType() - { - return toEntityType; - } - + private SecurityEntityRelationType relationType; + public void setLdapTemplate(LdapTemplate ldapTemplate) { this.ldapTemplate = ldapTemplate; } - public void setFromEntityType(String fromEntityType) + public SecurityEntityRelationType getRelationType() { - this.fromEntityType = fromEntityType; - } - - public void setToEntityType(String toEntityType) - { - this.toEntityType = toEntityType; + return relationType; } - public void setRelationType(String relationType) + public void setRelationType(SecurityEntityRelationType relationType) { this.relationType = relationType; } 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -51,32 +51,45 @@ private boolean attributeContainsInternalId; // if internal ID ( = DN) is // not used, then the attribute - // contains the ID9(s). + // contains the ID(s). - public Collection getRelatedEntities(EntityDAO sourceDao, - EntityDAO targetDao, Entity fromEntity) + public Collection getRelatedEntitiesFrom(EntityDAO fromDAO, + EntityDAO toDAO, Entity toEntity) { + return internalGetRelatedEntities( toDAO, fromDAO, !useFromEntityAttribute, toEntity); + } + + public Collection getRelatedEntitiesTo(EntityDAO fromDAO, + EntityDAO toDAO, Entity fromEntity) + { + return internalGetRelatedEntities(fromDAO, toDAO, useFromEntityAttribute, fromEntity); + } + + private Collection internalGetRelatedEntities(EntityDAO fromDAO, + EntityDAO toDAO, boolean useFromEntityAttribute, Entity entity) + { + if (useFromEntityAttribute) { - Attribute relationAttrValue = fromEntity + Attribute relationAttrValue = entity .getAttribute(relationAttribute); if (relationAttrValue != null) { Collection values = relationAttrValue.getValues(); if (attributeContainsInternalId) { - return targetDao.getEntitiesByInternalId(values); + return toDAO.getEntitiesByInternalId(values); } else { - return targetDao.getEntitiesById(values); + return toDAO.getEntitiesById(values); } } } else { // can be either the id or the internalId of the from entity String fromEntityUsedIdValue = attributeContainsInternalId ? getInternalId( - fromEntity, sourceDao) - : fromEntity.getId(); + entity, fromDAO) + : entity.getId(); // TODO : throw exception when no ID / internal ID can be found for // the entity if (!StringUtils.isEmpty(fromEntityUsedIdValue)) @@ -85,12 +98,12 @@ // on the member attribute Filter roleMemberAttrFilter = new EqualsFilter( relationAttribute, fromEntityUsedIdValue); - return targetDao.getEntities(roleMemberAttrFilter); + return toDAO.getEntities(roleMemberAttrFilter); } } return null; } - + private String getInternalId(Entity entity, EntityDAO entityDao) { if (StringUtils.isEmpty(entity.getInternalId())) Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Attribute.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/Attribute.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Attribute.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Attribute.java Fri Sep 12 11:39:51 2008 @@ -26,6 +26,8 @@ { String getName(); + + String getMappedName(); String getValue(); 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -26,5 +26,9 @@ String getName(); boolean isMultiValue(); + + boolean isMapped(); + + String getMappedName(); } Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.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/Entity.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/model/Entity.java Fri Sep 12 11:39:51 2008 @@ -17,6 +17,7 @@ package org.apache.jetspeed.security.mapping.model; import java.util.Collection; +import java.util.Map; import java.util.Set; /** @@ -34,6 +35,20 @@ Attribute getAttribute(String name); + /** + * Returns a read-only map of attributes (name to attribute). + * To add attributes, call one of the setAttribute() methods + * @return collection of all attributes of the entity + */ + Map getAttributes(); + + /** + * Returns a read-only map of attributes (mapped name to attribute). + * Each attribute is mapped, i.e. is synchronized with a related Jetspeed principal attribute. + * @return collection of all attributes of the entity + */ + Map getMappedAttributes(); + void setAttribute(String name, String value); void setAttribute(String name, Collection values); 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -27,29 +27,60 @@ private String name; + private String mappedName; + private boolean multiValue; // default is single-valued + private boolean mapped=true; + public AttributeDefImpl(String name) { super(); this.name = name; + this.mappedName=name; // default mapping } public AttributeDefImpl(String name, boolean multiValue) { - super(); - this.name = name; + this(name); this.multiValue=multiValue; } + + public AttributeDefImpl(String name, boolean multiValue, boolean isMapped) + { + this(name,multiValue); + this.mapped=isMapped; + } + public String getName() { return name; } + + public String getMappedName() + { + return mappedName; + } + + public void setMappedName(String mappedName) + { + this.mappedName = mappedName; + } public boolean isMultiValue() { return multiValue; } + + public boolean isMapped() + { + return mapped; + } + + public void setMapped(boolean mapped) + { + this.mapped = mapped; + } public void setMultiValue(boolean multiValue) { 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -57,6 +57,11 @@ return definition.getName(); } + public String getMappedName() + { + return definition.getMappedName(); + } + public Collection getValues() { return getDefinition().isMultiValue() ? values : null; 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -66,6 +66,23 @@ return nameToAttributeMap.get(name); } + public Map getAttributes() + { + return Collections.unmodifiableMap(nameToAttributeMap); + } + + public Map getMappedAttributes() + { + Map mappedAttrs = new HashMap(); + for (Map.Entry mappedAttrEntry : nameToAttributeMap.entrySet()){ + if (mappedAttrEntry.getValue().getDefinition().isMapped()){ + // it is assumed that mapped names are unique + mappedAttrs.put(mappedAttrEntry.getValue().getMappedName(),mappedAttrEntry.getValue()); + } + } + return Collections.unmodifiableMap(mappedAttrs); + } + public Set getAllowedAttributes() { return allowedAttributes; Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java?rev=694772&view=auto ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java (added) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java Fri Sep 12 11:39:51 2008 @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.spi.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.security.AttributeReadOnlyException; +import org.apache.jetspeed.security.AttributeRequiredException; +import org.apache.jetspeed.security.AttributeTypeNotFoundException; +import org.apache.jetspeed.security.AttributesReadOnlyException; +import org.apache.jetspeed.security.JetspeedPrincipal; +import org.apache.jetspeed.security.JetspeedPrincipalManager; +import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider; +import org.apache.jetspeed.security.JetspeedPrincipalType; +import org.apache.jetspeed.security.PrincipalUpdateException; +import org.apache.jetspeed.security.SecurityAttribute; +import org.apache.jetspeed.security.SecurityAttributeType; +import org.apache.jetspeed.security.SecurityAttributes; +import org.apache.jetspeed.security.mapping.SecurityEntityManager; +import org.apache.jetspeed.security.mapping.SecurityEntityRelationType; +import org.apache.jetspeed.security.mapping.model.Attribute; +import org.apache.jetspeed.security.mapping.model.Entity; +import org.apache.jetspeed.security.spi.JetspeedPrincipalSynchronizer; + +/** + * @author Dennis Dam + * @version $Id$ + */ +public class DefaultJetspeedPrincipalSynchronizer implements + JetspeedPrincipalSynchronizer +{ + + private static final Log logger = LogFactory.getLog(DefaultJetspeedPrincipalSynchronizer.class); + + JetspeedPrincipalManagerProvider principalManagerProvider; + + SecurityEntityManager securityEntityManager; + + Collection supportedExternalEntityTypes = Collections.emptyList(); + + Collection supportedExternalEntityRelationTypes = Collections + .emptyList(); + + Map> entityToRelationTypes = Collections + .emptyMap(); + + public void synchronizeAll() + { + + } + + public void synchronizeUserPrincipal(String name) + { + + JetspeedPrincipalManager manager = principalManagerProvider + .getManager(principalManagerProvider + .getPrincipalType(JetspeedPrincipalType.USER_TYPE_NAME)); + if (manager != null) + { + Collection skipTypes = new ArrayList(); + skipTypes.add(JetspeedPrincipalType.USER_TYPE_NAME); + // TODO do not skip user relations which are required! + Collection userRelations = securityEntityManager.getSupportedEntityRelationTypes(JetspeedPrincipalType.USER_TYPE_NAME); + recursiveSynchronizePrincipal(securityEntityManager.getEntity(JetspeedPrincipalType.USER_TYPE_NAME, name), new SynchronizationState(userRelations)); + } + } + + public void recursiveSynchronizePrincipal(Entity entity, SynchronizationState syncState) + { + JetspeedPrincipal upToDatePrincipal=null; + if (entity != null && !syncState.isProcessed(entity)){ + // mark as processed, to avoid nasty loops + syncState.setProcessed(entity); + + Collection notRequiredRelationTypes=new ArrayList(); + for(SecurityEntityRelationType relationTypeForThisPrincipal : entityToRelationTypes.get(entity.getType())){ + String fromType = relationTypeForThisPrincipal.getFromEntityType(); + String toType = relationTypeForThisPrincipal.getToEntityType(); + // check at what side of the relationship this entity represents (from or to) and check whether + // entities on the other side should be synchronized.Entity entity + if (fromType.equals(entity.getType())){ + if (!syncState.isProcessedFrom(relationTypeForThisPrincipal,entity)){ + if (isRequiredRelation(relationTypeForThisPrincipal)){ + syncState.setProcessedFrom(relationTypeForThisPrincipal, entity); + Collection relatedEntities = securityEntityManager.getRelatedEntitiesTo(entity, relationTypeForThisPrincipal); + for (Entity relatedEntity : relatedEntities) + { + // first create/update principal + recursiveSynchronizePrincipal(relatedEntity, syncState); + // .. then update associations + synchronizePrincipalAssocation(relationTypeForThisPrincipal,entity,relatedEntity); + } + } else { + // process relation later: a related principal (related either indirect or direct) might be + // dependent on the currently processed entity. So first update/add the current principal. + notRequiredRelationTypes.add(relationTypeForThisPrincipal); + } + } + + } + // the entity can represent *both* sides of the relationship, so synchronize both ways. + if (toType.equals(entity.getType())){ + if (!syncState.isProcessedTo(relationTypeForThisPrincipal,entity)){ + Collection relatedEntities = securityEntityManager.getRelatedEntitiesTo(entity, relationTypeForThisPrincipal); + for (Entity relatedEntity : relatedEntities) + { + recursiveSynchronizePrincipal(relatedEntity, syncState); + } + } + } + } + + synchronizePrincipalAttributes(entity); + + for(SecurityEntityRelationType relationTypeForThisPrincipal : notRequiredRelationTypes){ + + } + } + } + + private boolean isRequiredRelation(SecurityEntityRelationType relationType){ + return false; // TODO: wait until + } + + protected void synchronizePrincipalAssocation(SecurityEntityRelationType relationType, Entity fromEntity, Entity toEntity){ + JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(fromEntity.getType())); + + // principalManager.getAssociatedTo(principalToName, to, associationName) + } + + protected void synchronizePrincipalAttributes(Entity entity){ + JetspeedPrincipalManager principalManager = principalManagerProvider + .getManager(principalManagerProvider + .getPrincipalType(entity.getType())); + if (principalManager!=null){ + JetspeedPrincipal principal = principalManager.getPrincipal(entity.getId()); + Map mappedEntityAttrs = entity.getMappedAttributes(); + Collection attrsToBeUpdated = new ArrayList(); + if (principal == null){ + // principal does not exist yet, create it using the Jetspeed principal manager + principal = principalManager.newPrincipal(entity.getId(), true); + attrsToBeUpdated.addAll(mappedEntityAttrs.values()); + } else if (!principal.isReadOnly() && principal.isMapped()) { + SecurityAttributes principalAttrs = principal.getSecurityAttributes(); + for (Map.Entry entityAttrEntry : mappedEntityAttrs.entrySet()){ + SecurityAttribute principalAttr = principalAttrs.getAttribute(entityAttrEntry.getKey()); + Attribute entityAttr = entityAttrEntry.getValue(); + if (principalAttr!=null){ + if (entityAttr.getDefinition().isMultiValue()){ + // TODO : multi-valued Principal attrs are not yet supported + } else { + if (!StringUtils.equals(principalAttr.getStringValue(), entityAttr.getValue())){ + attrsToBeUpdated.add(entityAttr); + } + } + } else { + attrsToBeUpdated.add(entityAttr); + } + } + } + + SecurityAttributes principalAttrs = principal.getSecurityAttributes(); + Map securityAttrTypes = principalAttrs.getSecurityAttributeTypes().getAttributeTypeMap(); + + // Step 1. update principal's attributes + for (Attribute addedEntityAttr : attrsToBeUpdated ){ + if (!addedEntityAttr.getDefinition().isMultiValue()){ + SecurityAttribute principalAttr = null; + try + { + SecurityAttributeType securityAttrType = securityAttrTypes.get(addedEntityAttr.getMappedName()); + if (securityAttrType!=null && !securityAttrType.isReadOnly()){ + principalAttr = principalAttrs.getAttribute(addedEntityAttr.getMappedName(),true); + } + principalAttr.setStringValue(addedEntityAttr.getValue()); + } catch (AttributesReadOnlyException e) + { + if (logger.isErrorEnabled()){ + logger.error("Unexpected read-only exception for attribute "+addedEntityAttr.getMappedName()+".",e); + } + } catch (AttributeTypeNotFoundException e) + { + if (logger.isErrorEnabled()){ + logger.error("Unexpected missing type exception for attribute "+addedEntityAttr.getMappedName()+".",e); + } + } + } + } + if (principal.isMapped() && !principal.isReadOnly()){ + boolean updated = (attrsToBeUpdated.size() > 0); + // Step 2, check whether attributes should be removed. + for (Map.Entry principalAttrEntry : principalAttrs.getAttributeMap().entrySet() ){ + // TODO: check whether this attribute is mapped + if (!mappedEntityAttrs.containsKey(principalAttrEntry.getKey())){ + try + { + principalAttrs.removeAttribute(principalAttrEntry.getKey()); + updated=true; + } catch (AttributesReadOnlyException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AttributeReadOnlyException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AttributeRequiredException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + // step 3, update synchronized principal + if (updated){ + try + { + principalManager.updatePrincipal(principal); + } catch (PrincipalUpdateException e) + { + if (logger.isErrorEnabled()){ + logger.error("Could not synchronize principal "+principal.getName()+" of type "+principal.getType().getName(),e); + } + } catch (Exception e) + { + if (logger.isErrorEnabled()){ + logger.error("Unexpected exception trying to update principal during synchronization.",e); + } + } + } + } + + } else { + // TODO throw proper exception + } + + } + + public void synchronizePrincipalsByType(String principalTypeName) + { + + } + + public void setPrincipalManagerProvider( + JetspeedPrincipalManagerProvider principalManagerProvider) + { + this.principalManagerProvider = principalManagerProvider; + } + + public void setSecurityEntityManager( + SecurityEntityManager securityEntityManager) + { + this.securityEntityManager = securityEntityManager; + supportedExternalEntityTypes = securityEntityManager + .getSupportedEntityTypes(); + supportedExternalEntityRelationTypes = securityEntityManager + .getSupportedEntityRelationTypes(); + entityToRelationTypes = new HashMap>(); + for (String entityType : supportedExternalEntityTypes) + { + entityToRelationTypes.put(entityType, securityEntityManager + .getSupportedEntityRelationTypes(entityType)); + } + } + + private class SynchronizationState { + + // entity type to processed entity IDs map + Map> processedEntities=new HashMap>(); + // map from relation type to from entity id + Map> processedEntityRelationsFrom = new HashMap>(); + // map from relation type to "to entity id" + Map> processedEntityRelationsTo = new HashMap>(); + // Relations which are not checked: this can be used when updating a user principal without indirectly updating other users. + Collection skipRelations; + + SynchronizationState(Collection skipRelations){ + this.skipRelations=skipRelations; + } + + public boolean isProcessed(Entity entity){ + Set processedEntitiesByType = processedEntities.get(entity.getType()); + return processedEntitiesByType != null && processedEntitiesByType.contains(entity.getId()); + } + + public void setProcessed(Entity entity){ + Set processedEntitiesByType = processedEntities.get(entity.getType()); + if (processedEntitiesByType==null){ + processedEntitiesByType=new HashSet(); + } + processedEntitiesByType.add(entity.getId()); + } + + public boolean isProcessedFrom(SecurityEntityRelationType relationType, Entity fromEntity){ + if (skipRelations.contains(relationType)){ + return true; // effectively skip the relation by marking it as processed + } + Collection fromIds = processedEntityRelationsFrom.get(relationType); + return fromIds != null && fromIds.contains(fromEntity.getId()); + } + + public boolean isProcessedTo(SecurityEntityRelationType relationType, Entity toEntity){ + if (skipRelations.contains(relationType)){ + return true; // effectively skip the relation by marking it as processed + } + Collection toIds = processedEntityRelationsFrom.get(relationType); + return toIds != null && toIds.contains(toEntity.getId()); + } + + public void setProcessedFrom(SecurityEntityRelationType relationType, Entity fromEntity){ + Collection fromIds=processedEntityRelationsFrom.get(relationType); + if (fromIds==null){ + fromIds=new ArrayList(); + processedEntityRelationsFrom.put(relationType,fromIds); + } + fromIds.add(fromEntity.getId()); + } + + public void setProcessedTo(SecurityEntityRelationType relationType, Entity toEntity){ + Collection toIds=processedEntityRelationsTo.get(relationType); + if (toIds==null){ + toIds=new ArrayList(); + processedEntityRelationsTo.put(relationType,toIds); + } + toIds.add(toEntity.getId()); + } + + } + +} Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.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/BasicTestCases.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/BasicTestCases.java Fri Sep 12 11:39:51 2008 @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.jetspeed.security.mapping.SecurityEntityManager; +import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl; import org.apache.jetspeed.security.mapping.model.Attribute; import org.apache.jetspeed.security.mapping.model.AttributeDef; import org.apache.jetspeed.security.mapping.model.Entity; @@ -61,15 +62,28 @@ TestCase.assertEquals(totalNrOfUsers, entities.size()); } - public void testFetchRelatedEntities(String fromEntityType, + public void testFetchRelatedEntitiesTo(String fromEntityType, String toEntityType, String relationType, String fromEntityId, Collection expectedEntities) throws Exception { - Entity randomUser = entityManager.getEntity(fromEntityType, + Entity randomEntity = entityManager.getEntity(fromEntityType, fromEntityId); - TestCase.assertNotNull(randomUser); - Collection resultEntities = entityManager.getRelatedEntities( - randomUser, toEntityType, relationType); + TestCase.assertNotNull(randomEntity); + Collection resultEntities = entityManager.getRelatedEntitiesTo( + randomEntity, new SecurityEntityRelationTypeImpl(relationType,fromEntityType,toEntityType)); + + basicEntityResultSetChecks(expectedEntities, resultEntities); + } + + public void testFetchRelatedEntitiesFrom(String fromEntityType, + String toEntityType, String relationType, String toEntityId, + Collection expectedEntities) throws Exception + { + Entity randomEntity = entityManager.getEntity(toEntityType, + toEntityId); + TestCase.assertNotNull(randomEntity); + Collection resultEntities = entityManager.getRelatedEntitiesFrom( + randomEntity, new SecurityEntityRelationTypeImpl(relationType,fromEntityType,toEntityType)); basicEntityResultSetChecks(expectedEntities, resultEntities); } @@ -80,8 +94,8 @@ Collection resultEntities) { TestCase.assertNotNull(resultEntities); - Set expectedSet = new HashSet(expectedEntities); - Set resultSet = new HashSet(resultEntities); + Set expectedSet = new HashSet(expectedEntities); + Set resultSet = new HashSet(resultEntities); TestCase.assertEquals(true, expectedSet.equals(resultSet)); } 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -26,6 +26,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl; import org.apache.jetspeed.security.mapping.ldap.AbstractLDAPTest; import org.apache.jetspeed.security.mapping.ldap.dao.DefaultLDAPEntityManager; import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO; @@ -131,9 +132,7 @@ // use attribute on target entity (of "role" type); user IDs are stored // in a multi-valued attribute on roles. hasRoleDAO.setUseFromEntityAttribute(false); - hasRoleDAO.setRelationType("hasRole"); - hasRoleDAO.setFromEntityType("user"); - hasRoleDAO.setToEntityType("role"); + hasRoleDAO.setRelationType(new SecurityEntityRelationTypeImpl("hasRole","user","role")); hasRoleDAO.setAttributeContainsInternalId(true); relationDaos.add(hasRoleDAO); 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -55,7 +55,7 @@ Collection resultSet = new ArrayList(); resultSet.add(role1); resultSet.add(role3); - basicTestCases.testFetchRelatedEntities("user", "role", "hasRole", + basicTestCases.testFetchRelatedEntitiesTo("user", "role", "hasRole", "jsmith", resultSet); } 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=694772&r1=694771&r2=694772&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 Fri Sep 12 11:39:51 2008 @@ -26,6 +26,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.apache.jetspeed.security.mapping.impl.SecurityEntityRelationTypeImpl; import org.apache.jetspeed.security.mapping.ldap.AbstractLDAPTest; import org.apache.jetspeed.security.mapping.ldap.dao.DefaultLDAPEntityManager; import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO; @@ -133,9 +134,7 @@ hasRoleDAO.setLdapTemplate(ldapTemplate); hasRoleDAO.setRelationAttribute("j2-role"); hasRoleDAO.setUseFromEntityAttribute(true); - hasRoleDAO.setRelationType("hasRole"); - hasRoleDAO.setFromEntityType("user"); - hasRoleDAO.setToEntityType("role"); + hasRoleDAO.setRelationType(new SecurityEntityRelationTypeImpl("hasRole","user","role")); hasRoleDAO.setAttributeContainsInternalId(false); relationDaos.add(hasRoleDAO); Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/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/setup2/UserTests.java?rev=694772&r1=694771&r2=694772&view=diff ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java (original) +++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/setup2/UserTests.java Fri Sep 12 11:39:51 2008 @@ -48,13 +48,13 @@ public void testFetchRolesForUserByRoleAttribute() throws Exception { EntityImpl managerRole = new EntityImpl("role", "manager", roleAttrDefs); - managerRole.setInternalId("cn=manager,ou=Roles,ou=rootOrg,o=sevenSeas"); + managerRole.setInternalId("cn=manager, ou=Roles, ou=rootOrg, o=sevenSeas"); managerRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "Manager Role"); managerRole.setAttribute(CN_DEF.getName(), "manager"); managerRole.setAttribute(UID_DEF.getName(), "manager"); - EntityImpl userRole = new EntityImpl("role", "Role3", roleAttrDefs); - userRole.setInternalId("cn=user,ou=Roles,ou=rootOrg,o=sevenSeas"); + EntityImpl userRole = new EntityImpl("role", "user", roleAttrDefs); + userRole.setInternalId("cn=user, ou=Roles, ou=rootOrg, o=sevenSeas"); userRole.setAttribute(DESCRIPTION_ATTR_DEF.getName(), "User Role"); userRole.setAttribute(CN_DEF.getName(), "user"); userRole.setAttribute(UID_DEF.getName(), "user"); @@ -62,7 +62,45 @@ Collection resultSet = new ArrayList(); resultSet.add(managerRole); resultSet.add(userRole); - basicTestCases.testFetchRelatedEntities("user", "role", "hasRole", + + // test fetching roles for a user + basicTestCases.testFetchRelatedEntitiesTo("user", "role", "hasRole", "someManager", resultSet); + + // .. next, test fetching users for a role using the same EntityRelationDAO + Entity user = createUser("someManager", + "cn=someManager, ou=People, ou=rootOrg, o=sevenSeas", + "Some Manager","someManager","someManager",new String[]{"manager","user"}); + Entity jetspeed = createUser("jetspeed", + "cn=jetspeed, ou=People, ou=rootOrg, o=sevenSeas", + "jetspeed","jetspeed","jetspeed",new String[]{"manager"}); + Entity admin = createUser("admin", + "cn=admin, ou=People, ou=rootOrg, o=sevenSeas", + "Admin","admin","admin",new String[]{"admin","manager","user"}); + + + resultSet = new ArrayList(); + resultSet.add(user); + resultSet.add(jetspeed); + resultSet.add(admin); + basicTestCases.testFetchRelatedEntitiesFrom("user", "role", "hasRole", + "manager", resultSet); + } + + private Entity createUser(String id, String internalId, String givenName, String cn, String uid, String[] roles){ + EntityImpl user = new EntityImpl("user", id, userAttrDefs); + user.setInternalId(internalId); + user.setAttribute(GIVEN_NAME_DEF.getName(), givenName); + user.setAttribute(CN_DEF.getName(), cn); + user.setAttribute(UID_DEF.getName(), uid); + Collection roleValues=new ArrayList(); + for (int i = 0; i < roles.length; i++) + { + roleValues.add(roles[i]); + } + user.setAttribute(J2_ROLE_DEF.getName(), roleValues); + return user; + } + } Added: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java?rev=694772&view=auto ============================================================================== --- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java (added) +++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java Fri Sep 12 11:39:51 2008 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.security.spi; + +/** + * @author Dennis Dam + * @version $Id$ + */ +public interface JetspeedPrincipalSynchronizer +{ + + void synchronizeUserPrincipal(String name); + + void synchronizePrincipalsByType(String principalTypeName); + + void synchronizeAll(); + +} Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalSynchronizer.java ------------------------------------------------------------------------------ svn:keywords = Id --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org For additional commands, e-mail: jetspeed-dev-help@portals.apache.org