Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Security Inserting Acls: ConcurrentModificationException
    primarykey
    data
    text
    <p>I'm trying to get spring acl working. You can see below how I try to insert new entries into the MutableAcl. It works, as long as I only add one at a time. But if I try to add multiple permissions (eg READ, WRITE), then I get a ConcurrentModificationException, see stack trace below). So it seems that there is a concurrency problem, so far I've been unable to determine how to prevent it. For testing purposes I added a Thread.sleep(1000); below the mutableAclService.updateAcl(acl); call and voila, suddenly I could add multiple permissions, so it's clearly a problem regarding the MutableAclService or my use of it. Any ideas?</p> <p>Greetings, Nanoquack.</p> <p>Code for inserting an ACL: @Autowired private MutableAclService mutableAclService;</p> <pre><code>public void addPermission(Object entity, Serializable identifier, Sid recipient, Permission permission) { MutableAcl acl; ObjectIdentity oid = new ObjectIdentityImpl(entity.getClass(), identifier); try { acl = (MutableAcl) mutableAclService.readAclById(oid); } catch (NotFoundException e) { acl = (MutableAcl) mutableAclService.createAcl(oid); } acl.insertAce(acl.getEntries().size(), permission, recipient, true); mutableAclService.updateAcl(acl); log.debug("Added permission. Entity: " + entity + " Recipient: " + recipient + " Permission: " + permission); } </code></pre> <p>Stack Trace when trying to insert multiple ACLs:</p> <pre><code>25565 [acl%0043ache.data] ERROR net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of org.springframework.security.acls.domain.ObjectIdentityImpl[Type: com.coderunner.caliope.module.caliope.model.Page; Identifier: 0] failed: net.sf.ehcache.CacheException: Failed to serialize element due to ConcurrentModificationException. This is frequently the result of inappropriately sharing thread unsafe object (eg. ArrayList, HashMap, etc) between threads at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:401) at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:381) at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:473) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1067) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1051) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Caused by: java.util.ConcurrentModificationException at java.util.ArrayList.writeObject(ArrayList.java:713) at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1541) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1506) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1541) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:439) Hibernate: delete from acl_entry where acl_object_identity=? at net.sf.ehcache.Element.writeObject(Element.java:851) at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97) at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:399) ... 11 more </code></pre> <p>Spring ACL Configuration: ROLE_ADMINISTRATOR </p> <pre><code> &lt;bean id="aclService" class="org.springframework.security.acls.jdbc.JdbcMutableAclService"&gt; &lt;constructor-arg ref="dataSource" /&gt; &lt;constructor-arg ref="lookupStrategy" /&gt; &lt;constructor-arg ref="aclCache" /&gt; &lt;property name="classIdentityQuery" value="SELECT @@IDENTITY" /&gt; &lt;property name="sidIdentityQuery" value="SELECT @@IDENTITY" /&gt; &lt;/bean&gt; &lt;bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler"&gt; &lt;property name="permissionEvaluator" ref="permissionEvaluator" /&gt; &lt;property name="permissionCacheOptimizer"&gt; &lt;bean class="org.springframework.security.acls.AclPermissionCacheOptimizer"&gt; &lt;constructor-arg ref="aclService" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="permissionEvaluator" class="org.springframework.security.acls.AclPermissionEvaluator"&gt; &lt;constructor-arg ref="aclService" /&gt; &lt;/bean&gt; &lt;bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" /&gt; &lt;bean id="aclCache" class="org.springframework.security.acls.domain.EhCacheBasedAclCache"&gt; &lt;constructor-arg&gt; &lt;bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt; &lt;property name="cacheManager"&gt; &lt;bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" /&gt; &lt;/property&gt; &lt;property name="cacheName" value="aclCache" /&gt; &lt;/bean&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload