Index: topia-service/src/java/org/codelutin/topia/taas/interceptor/TaasAccessInterceptorRequestPermission.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/interceptor/TaasAccessInterceptorRequestPermission.java:1.1 --- /dev/null Tue Dec 18 11:27:49 2007 +++ topia-service/src/java/org/codelutin/topia/taas/interceptor/TaasAccessInterceptorRequestPermission.java Tue Dec 18 11:27:42 2007 @@ -0,0 +1,135 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* TopiaSecurityVetoableListener.java +* +* Created: 10 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2007-12-18 11:27:42 $ +* par : $Author: ruchaud $ +*/ + +package org.codelutin.topia.taas.interceptor; + +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 static org.codelutin.topia.taas.TaasUtil.UPDATE; + +import java.io.Serializable; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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; +import org.hibernate.CallbackException; +import org.hibernate.EmptyInterceptor; +import org.hibernate.type.Type; + +/** + * Permet d'attacher les événements de sécurité à la session + * + * @author julien + * + */ +public class TaasAccessInterceptorRequestPermission extends EmptyInterceptor { + + private static final long serialVersionUID = 1L; + private static Log log = LogFactory.getLog(TaasAccessInterceptorRequestPermission.class); + + protected TaasService taasService; + + /** + * Contructeur par défaut + * @param taasService + */ + public TaasAccessInterceptorRequestPermission(TaasService taasService) { + super(); + this.taasService = taasService; + } + + /* + * (non-Javadoc) + * @see org.hibernate.EmptyInterceptor#onLoad(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) + */ + public boolean onLoad(Object entity, + Serializable id, + Object[] state, + String[] propertyNames, + Type[] types) + throws CallbackException { + if(!(entity instanceof TaasUser || + entity instanceof TaasPrincipal || + entity instanceof TaasAuthorization)) { + taasService.checkRequestPermission((TopiaEntity) entity, LOAD); + } + return super.onLoad(entity, id, state, propertyNames, types); + } + + /* + * (non-Javadoc) + * @see org.hibernate.EmptyInterceptor#onFlushDirty(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) + */ + public boolean onFlushDirty(Object entity, + Serializable id, + Object[] currentState, + Object[] previousState, + String[] propertyNames, + Type[] types) + throws CallbackException { + taasService.checkRequestPermission((TopiaEntity) entity, UPDATE); + return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types); + } + + /* + * (non-Javadoc) + * @see org.hibernate.EmptyInterceptor#onSave(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) + */ + public boolean onSave(Object entity, + Serializable id, + Object[] state, + String[] propertyNames, + Type[] types) + throws CallbackException { + taasService.checkRequestPermission((TopiaEntity) entity, CREATE); + return super.onSave(entity, id, state, propertyNames, types); + } + + /* + * (non-Javadoc) + * @see org.hibernate.EmptyInterceptor#onDelete(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) + */ + public void onDelete(Object entity, + Serializable id, + Object[] state, + String[] propertyNames, + Type[] types) + throws CallbackException { + taasService.checkRequestPermission((TopiaEntity) entity, DELETE); + super.onDelete(entity, id, state, propertyNames, types); + } +}