Index: topia-security/src/java/org/codelutin/topia/security/listener/VetoableEntityListener.java diff -u topia-security/src/java/org/codelutin/topia/security/listener/VetoableEntityListener.java:1.4 topia-security/src/java/org/codelutin/topia/security/listener/VetoableEntityListener.java:1.5 --- topia-security/src/java/org/codelutin/topia/security/listener/VetoableEntityListener.java:1.4 Tue Oct 3 14:55:23 2006 +++ topia-security/src/java/org/codelutin/topia/security/listener/VetoableEntityListener.java Thu Oct 5 07:49:44 2006 @@ -24,9 +24,9 @@ * Created: 10 févr. 2006 * * @author Arnaud Thimel -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * -* Mise a jour: $Date: 2006/10/03 14:55:23 $ +* Mise a jour: $Date: 2006/10/05 07:49:44 $ * par : $Author: ruchaud $ */ @@ -37,13 +37,9 @@ import static org.codelutin.topia.security.util.TopiaSecurityUtil.LOAD; import static org.codelutin.topia.security.util.TopiaSecurityUtil.checkPermission; -import java.security.AccessController; -import java.security.Principal; import java.util.Arrays; import java.util.List; -import javax.security.auth.Subject; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.topia.TopiaException; @@ -62,6 +58,12 @@ TopiaVetoableEntityLoadListener { private static Log log = LogFactory.getLog(VetoableEntityListener.class); + + private TopiaSecurityManagerImpl securityManager; + + public VetoableEntityListener(TopiaSecurityManagerImpl securityManager) { + this.securityManager = securityManager; + } /* (non-Javadoc) * @see org.codelutin.topia.event.TopiaVetoableEntityListener#createEntity(org.codelutin.topia.event.TopiaVetoableEntityEvent) @@ -96,7 +98,8 @@ * @see org.codelutin.topia.event.TopiaVetoableEntityLoadListener#loadEntity(org.codelutin.topia.event.TopiaVetoableEntityLoadEvent) */ public boolean loadEntity(TopiaVetoableEntityLoadEvent event) { - boolean check = true; + boolean authorized = true; + String topiaId = (String)event.getId(); Class[] interfaces = event.getEntityClass().getInterfaces(); List asList = Arrays.asList(interfaces); @@ -106,35 +109,20 @@ } /* Vérification dans le cache */ - Subject subject = Subject.getSubject(AccessController.getContext()); - if (subject != null) { - boolean modified = false; - - for (Principal principal : subject.getPrincipals()) { - Object object = TopiaSecurityManagerImpl.cachingLOAD.get(event.getId(), principal.getName()); - - if(object != null) { - modified = true; - } - } - - if(modified) { - return true; - } + boolean contain = securityManager.containEntitiesLoadingCache(topiaId); + if(contain) { + return true; } try { checkPermission((String)event.getId(), LOAD); } catch (TopiaException te) { - check = false; + authorized = false; } + /* Mise en cache */ - if (subject != null) { - for (Principal principal : subject.getPrincipals()) { - TopiaSecurityManagerImpl.cachingLOAD.put(check, event.getId(), principal.getName()); - } - } + securityManager.putEntitiesLoadingCache(topiaId, authorized); } return true; Index: topia-security/src/java/org/codelutin/topia/security/listener/PropertyReadListener.java diff -u topia-security/src/java/org/codelutin/topia/security/listener/PropertyReadListener.java:1.2 topia-security/src/java/org/codelutin/topia/security/listener/PropertyReadListener.java:1.3 --- topia-security/src/java/org/codelutin/topia/security/listener/PropertyReadListener.java:1.2 Fri Sep 29 15:50:07 2006 +++ topia-security/src/java/org/codelutin/topia/security/listener/PropertyReadListener.java Thu Oct 5 07:49:44 2006 @@ -26,10 +26,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; -import java.security.AccessController; -import java.security.Principal; - -import javax.security.auth.Subject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,6 +43,12 @@ private static Log log = LogFactory.getLog(PropertyReadListener.class); + private TopiaSecurityManagerImpl securityManager; + + public PropertyReadListener(TopiaSecurityManagerImpl securityManager) { + this.securityManager = securityManager; + } + /* * (non-Javadoc) * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent) @@ -56,36 +58,22 @@ TopiaEntityAbstract entity = (TopiaEntityAbstract) source; /* Vérification dans le cache */ - Subject subject = Subject.getSubject(AccessController.getContext()); - if (subject != null) { - boolean check = false; - boolean modified = false; - - for (Principal principal : subject.getPrincipals()) { - Object object = TopiaSecurityManagerImpl.cachingLOAD.get(entity.getTopiaId(), principal.getName()); - - if(object != null) { - check |= (Boolean) object; - modified = true; - } + Boolean authorized = securityManager.getEntitiesLoadingCache(entity.getTopiaId()); + if(authorized != null) { + if(!authorized) { + throw new SecurityException("Access denied to Read entity " + entity + " on " + event.getPropertyName()); } - - if(modified) { - if(!check) { - throw new SecurityException("Access denied to Read entity " + entity + " on " + event.getPropertyName()); + } else { // Sinon + try { + checkPermission(entity.getTopiaId(), LOAD); + } catch (TopiaException te) { + if (log.isWarnEnabled()) { + log.warn("[Security] Read denied to : " + entity.getTopiaId(), te); } - return; + throw new SecurityException("Access denied to Read entity " + entity + " on " + event.getPropertyName(), te); } } - try { - checkPermission(entity.getTopiaId(), LOAD); - } catch (TopiaException te) { - if (log.isWarnEnabled()) { - log.warn("[Security] Read denied to : " + entity.getTopiaId(), te); - } - throw new SecurityException("Access denied to Read entity " + entity + " on " + event.getPropertyName(), te); - } } }