Index: topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoable.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoable.java:1.6 --- /dev/null Thu Dec 20 14:23:57 2007 +++ topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoable.java Thu Dec 20 14:23:51 2007 @@ -0,0 +1,108 @@ +package org.codelutin.topia.taas.event; + +import static org.codelutin.topia.security.util.TopiaSecurityUtil.UPDATE; +import static org.codelutin.topia.taas.TaasUtil.CREATE; +import static org.codelutin.topia.taas.TaasUtil.DELETE; +import static org.codelutin.topia.taas.TaasUtil.LOAD; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.event.TopiaEntitiesEvent; +import org.codelutin.topia.event.TopiaEntityEvent; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.taas.TaasService; +import org.codelutin.topia.taas.entities.TaasAuthorization; +import org.codelutin.topia.taas.entities.TaasPrincipal; +import org.codelutin.topia.taas.entities.TaasUser; + +public class TaasEntityVetoable implements TaasAccessEntity { + + private static Log log = LogFactory.getLog(TaasEntityVetoable.class); + + protected TaasService taasService; + + /** + * Contructeur par defaut + */ + public TaasEntityVetoable(TaasService taasService) { + this.taasService = taasService; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#createEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void create(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + Class clazz; + + if (log.isDebugEnabled()) { + log.debug("[Security] create entity : " + topiaId); + } + taasService.check(entity, CREATE); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#deleteEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void delete(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + + if (log.isDebugEnabled()) { + log.debug("[Security] delete entity : " + topiaId); + } + taasService.check(entity, DELETE); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityLoadListener#loadEntity(org.codelutin.topia.event.TopiaVetoableEntityLoadEvent) + */ + public void load(TopiaEntityEvent event) { +// TopiaEntity entity = event.getEntity(); +// String topiaId = entity.getTopiaId(); +// +// if (log.isDebugEnabled()) { +// log.debug("[Security] load entity : " + topiaId); +// } +// taasService.check(entity, LOAD); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#updateEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void update(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + + if (log.isDebugEnabled()) { + log.debug("[Security] update entity : " + topiaId); + } + taasService.check(entity, UPDATE); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.event.TopiaEntitiesVetoable#load(org.codelutin.topia.event.TopiaEntitiesEvent) + */ + public List load(TopiaEntitiesEvent event) { + if (log.isDebugEnabled()) { + log.debug("[Security] load entities"); + } + + List entities = event.getEntities(); + + if(!entities.isEmpty()) { + E entity = entities.get(0); + if(!(entity instanceof TaasUser || + entity instanceof TaasPrincipal || + entity instanceof TaasAuthorization)) { + taasService.check(entities, LOAD); + } + } + return entities; + } +} Index: topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoableRequestPermission.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoableRequestPermission.java:1.1 --- /dev/null Thu Dec 20 14:23:57 2007 +++ topia-service/src/java/org/codelutin/topia/taas/event/TaasEntityVetoableRequestPermission.java Thu Dec 20 14:23:51 2007 @@ -0,0 +1,96 @@ +package org.codelutin.topia.taas.event; + +import static org.codelutin.topia.security.util.TopiaSecurityUtil.UPDATE; +import static org.codelutin.topia.taas.TaasUtil.CREATE; +import static org.codelutin.topia.taas.TaasUtil.DELETE; +import static org.codelutin.topia.taas.TaasUtil.LOAD; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.event.TopiaEntitiesEvent; +import org.codelutin.topia.event.TopiaEntityEvent; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.taas.TaasService; + +public class TaasEntityVetoableRequestPermission implements TaasAccessEntity { + + private static Log log = LogFactory.getLog(TaasEntityVetoableRequestPermission.class); + + protected TaasService taasService; + + /** + * Contructeur par defaut + */ + public TaasEntityVetoableRequestPermission(TaasService taasService) { + this.taasService = taasService; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#createEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void create(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + Class clazz; + + if (log.isDebugEnabled()) { + log.debug("[Security] create entity : " + topiaId); + } + taasService.checkRequestPermission(entity, CREATE); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#deleteEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void delete(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + + if (log.isDebugEnabled()) { + log.debug("[Security] delete entity : " + topiaId); + } + taasService.checkRequestPermission(entity, DELETE); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityLoadListener#loadEntity(org.codelutin.topia.event.TopiaVetoableEntityLoadEvent) + */ + public void load(TopiaEntityEvent event) { +// TopiaEntity entity = event.getEntity(); +// String topiaId = entity.getTopiaId(); +// +// if (log.isDebugEnabled()) { +// log.debug("[Security] load entity : " + topiaId); +// } +// taasService.checkRequestPermission(entity, LOAD); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.event.TopiaVetoableEntityListener#updateEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) + */ + public void update(TopiaEntityEvent event) { + TopiaEntity entity = event.getEntity(); + String topiaId = entity.getTopiaId(); + + if (log.isDebugEnabled()) { + log.debug("[Security] update entity : " + topiaId); + } + taasService.checkRequestPermission(entity, UPDATE); + } + + /* + * (non-Javadoc) + * @see org.codelutin.topia.event.TopiaEntitiesVetoable#load(org.codelutin.topia.event.TopiaEntitiesEvent) + */ + public List load(TopiaEntitiesEvent event) { + if (log.isDebugEnabled()) { + log.debug("[Security] load entities"); + } + List entities = event.getEntities(); + taasService.checkRequestPermission(entities, LOAD); + return entities; + } +} Index: topia-service/src/java/org/codelutin/topia/taas/event/TaasAccessEntity.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/event/TaasAccessEntity.java:1.1 --- /dev/null Thu Dec 20 14:23:57 2007 +++ topia-service/src/java/org/codelutin/topia/taas/event/TaasAccessEntity.java Thu Dec 20 14:23:51 2007 @@ -0,0 +1,8 @@ +package org.codelutin.topia.taas.event; + +import org.codelutin.topia.event.TopiaEntitiesVetoable; +import org.codelutin.topia.event.TopiaEntityVetoable; + +public interface TaasAccessEntity extends TopiaEntitiesVetoable, TopiaEntityVetoable { + +}