Commit 4971a015 authored by Matija Obreza's avatar Matija Obreza

Removed ehcache, using hazelcast

parent a901dbec
...@@ -360,11 +360,6 @@ ...@@ -360,11 +360,6 @@
</dependency> </dependency>
<!--Other dependencies --> <!--Other dependencies -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency> <dependency>
<groupId>net.sf.oval</groupId> <groupId>net.sf.oval</groupId>
...@@ -458,6 +453,21 @@ ...@@ -458,6 +453,21 @@
<artifactId>velocity</artifactId> <artifactId>velocity</artifactId>
<version>1.7</version> <version>1.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-cloud</artifactId>
<version>3.1.5</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package org.genesys2.server.cache;
import java.io.Serializable;
import org.springframework.cache.Cache;
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
import org.springframework.security.acls.domain.AclImpl;
import org.springframework.security.acls.model.AclCache;
import org.springframework.security.acls.model.MutableAcl;
import org.springframework.security.acls.model.ObjectIdentity;
import org.springframework.security.acls.model.PermissionGrantingStrategy;
import org.springframework.security.util.FieldUtils;
import org.springframework.util.Assert;
public class HazelcastAclCache implements AclCache {
// ~ Instance fields
// ================================================================================================
private PermissionGrantingStrategy permissionGrantingStrategy;
private AclAuthorizationStrategy aclAuthorizationStrategy;
private Cache cache;
// ~ Constructors
// ===================================================================================================
public HazelcastAclCache(Cache cache, PermissionGrantingStrategy permissionGrantingStrategy, AclAuthorizationStrategy aclAuthorizationStrategy) {
Assert.notNull(cache, "Cache required");
Assert.notNull(permissionGrantingStrategy, "PermissionGrantingStrategy required");
Assert.notNull(aclAuthorizationStrategy, "AclAuthorizationStrategy required");
this.cache = cache;
this.permissionGrantingStrategy = permissionGrantingStrategy;
this.aclAuthorizationStrategy = aclAuthorizationStrategy;
}
// ~ Methods
// ========================================================================================================
public void evictFromCache(Serializable pk) {
Assert.notNull(pk, "Primary key (identifier) required");
MutableAcl acl = getFromCache(pk);
if (acl != null) {
cache.evict(acl.getId());
cache.evict(acl.getObjectIdentity());
}
}
public void evictFromCache(ObjectIdentity objectIdentity) {
Assert.notNull(objectIdentity, "ObjectIdentity required");
MutableAcl acl = getFromCache(objectIdentity);
if (acl != null) {
cache.evict(acl.getId());
cache.evict(acl.getObjectIdentity());
}
}
public MutableAcl getFromCache(ObjectIdentity objectIdentity) {
Assert.notNull(objectIdentity, "ObjectIdentity required");
MutableAcl element = null;
try {
element = (MutableAcl) cache.get(objectIdentity);
} catch (Throwable ignored) {
}
if (element == null) {
return null;
}
return initializeTransientFields(element);
}
public MutableAcl getFromCache(Serializable pk) {
Assert.notNull(pk, "Primary key (identifier) required");
MutableAcl element = null;
try {
element = (MutableAcl) cache.get(pk);
} catch (Throwable ignored) {
}
if (element == null) {
return null;
}
return initializeTransientFields(element);
}
public void putInCache(MutableAcl acl) {
Assert.notNull(acl, "Acl required");
Assert.notNull(acl.getObjectIdentity(), "ObjectIdentity required");
Assert.notNull(acl.getId(), "ID required");
if (this.aclAuthorizationStrategy == null) {
if (acl instanceof AclImpl) {
this.aclAuthorizationStrategy = (AclAuthorizationStrategy) FieldUtils.getProtectedFieldValue("aclAuthorizationStrategy", acl);
this.permissionGrantingStrategy = (PermissionGrantingStrategy) FieldUtils.getProtectedFieldValue("permissionGrantingStrategy", acl);
}
}
if ((acl.getParentAcl() != null) && (acl.getParentAcl() instanceof MutableAcl)) {
putInCache((MutableAcl) acl.getParentAcl());
}
cache.put(acl.getObjectIdentity(), acl);
cache.put(acl.getId(), acl);
}
private MutableAcl initializeTransientFields(MutableAcl value) {
if (value instanceof AclImpl) {
FieldUtils.setProtectedFieldValue("aclAuthorizationStrategy", value, this.aclAuthorizationStrategy);
FieldUtils.setProtectedFieldValue("permissionGrantingStrategy", value, this.permissionGrantingStrategy);
}
if (value.getParentAcl() != null) {
initializeTransientFields((MutableAcl) value.getParentAcl());
}
return value;
}
public void clearCache() {
cache.clear();
}
}
...@@ -20,8 +20,6 @@ import java.util.HashMap; ...@@ -20,8 +20,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.ehcache.CacheManager;
import org.genesys2.server.aspect.AsAdminAspect; import org.genesys2.server.aspect.AsAdminAspect;
import org.genesys2.server.model.AclAwareModel; import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.acl.AclClass; import org.genesys2.server.model.acl.AclClass;
...@@ -39,6 +37,7 @@ import org.genesys2.spring.SecurityContextUtil; ...@@ -39,6 +37,7 @@ import org.genesys2.spring.SecurityContextUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.acls.domain.BasePermission; import org.springframework.security.acls.domain.BasePermission;
import org.springframework.security.acls.model.Permission; import org.springframework.security.acls.model.Permission;
...@@ -305,6 +304,6 @@ public class AclServiceImpl implements AclService { ...@@ -305,6 +304,6 @@ public class AclServiceImpl implements AclService {
aclEntry.setGranting(permissionMap.get((int) aclEntry.getMask())); aclEntry.setGranting(permissionMap.get((int) aclEntry.getMask()));
} }
aclEntryPersistence.save(aclEntries); aclEntryPersistence.save(aclEntries);
cacheManager.getCache("acl").removeAll(); cacheManager.getCache("aclcache").clear();
} }
} }
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014 Global Crop Diversity Trust
Licensed 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.
-->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!--Default cache settings -->
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false" />
<!--ACL in-memory cache -->
<cache name="statistics" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="60" timeToLiveSeconds="120" overflowToDisk="false" />
<cache name="contentcache" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="60" timeToLiveSeconds="120" overflowToDisk="false" />
<!--CACHEABLE CACHES -->
<!--ACL in-memory cache -->
<cache name="acl" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false" />
<!--HIBERNATE L2 CACHES -->
<!--Here are specific caches for all persistence models -->
</ehcache>
...@@ -16,35 +16,76 @@ ...@@ -16,35 +16,76 @@
--> -->
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd"> http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.hazelcast.com/schema/spring
<cache:annotation-driven cache-manager="cacheManager"/> http://www.hazelcast.com/schema/spring/hazelcast-spring-3.1.xsd">
<bean name="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
<property name="cacheManagers">
<list>
<!--If ehCache is turned on, no op cache is being used-->
<ref bean="ehCacheCacheManager"/>
</list>
</property>
<property name="fallbackToNoOpCache" value="true"/>
</bean>
<bean name="ehCacheCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehCacheManager"/>
<property name="transactionAware" value="true"/>
</bean>
<bean name="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" destroy-method="destroy">
<property name="configLocation" value="classpath:/ehcache.xml"/>
<!--use single CacheManager across VM-->
<property name="shared" value="true"/>
</bean>
<cache:annotation-driven cache-manager="cacheManager" />
<bean name="cacheManager"
class="org.springframework.cache.support.CompositeCacheManager">
<property name="cacheManagers">
<list>
<!--If it is turned on, no op cache is being used -->
<ref bean="hzCacheManager" />
</list>
</property>
<property name="fallbackToNoOpCache" value="true" />
</bean>
<beans profile="aws">
<hz:hazelcast id="theHazelcast">
<hz:config>
<hz:group name="${hazelcast.name}" password="${hazelcast.password}" />
<hz:properties>
<hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property>
<hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property>
</hz:properties>
<hz:network port="${hazelcast.port}" port-auto-increment="true">
<hz:join>
<hz:multicast enabled="false" />
<hz:tcp-ip enabled="true" />
<hz:aws access-key="${hazelcast.aws.access-key}" region="${hazelcast.aws.region}"
secret-key="${hazelcast.aws.secret-key}" security-group-name="${hazelcast.aws.security-group}" />
</hz:join>
</hz:network>
<hz:map name="default" max-idle-seconds="3600" max-size="5000" time-to-live-seconds="0" eviction-policy="LRU" />
</hz:config>
</hz:hazelcast>
<bean id="hzCacheManager" class="com.hazelcast.spring.cache.HazelcastCacheManager">
<constructor-arg ref="theHazelcast" />
</bean>
</beans>
<beans profile="dev">
<hz:hazelcast id="theHazelcast">
<hz:config>
<hz:group name="${hazelcast.name}" password="${hazelcast.password}" />
<hz:properties>
<hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property>
<hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property>
</hz:properties>
<hz:network port="${hazelcast.port}">
<hz:join>
<hz:multicast enabled="false" />
<hz:tcp-ip enabled="false" />
</hz:join>
</hz:network>
<hz:map name="default" max-idle-seconds="300" max-size="1000" time-to-live-seconds="0" eviction-policy="LRU" />
</hz:config>
</hz:hazelcast>
<bean id="hzCacheManager" class="com.hazelcast.spring.cache.HazelcastCacheManager">
<constructor-arg ref="theHazelcast" />
</bean>
</beans>
</beans> </beans>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<property name="jpaProperties"> <property name="jpaProperties">
<props> <props>
<prop key="hibernate.dialect">${db.dialect}</prop> <prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.connection.autocommit">false</prop> <!-- <prop key="hibernate.connection.autocommit">false</prop> -->
<prop key="hibernate.hbm2ddl.auto">${db.hbm2ddl}</prop> <prop key="hibernate.hbm2ddl.auto">${db.hbm2ddl}</prop>
<prop key="hibernate.search.default.indexBase">${lucene.indexDir}</prop> <prop key="hibernate.search.default.indexBase">${lucene.indexDir}</prop>
<prop key="hibernate.search.default.exclusive_index_use">false</prop> <prop key="hibernate.search.default.exclusive_index_use">false</prop>
......
...@@ -33,12 +33,12 @@ ...@@ -33,12 +33,12 @@
<constructor-arg type="org.springframework.security.acls.domain.AuditLogger" ref="slf4jAuditLogger" /> <constructor-arg type="org.springframework.security.acls.domain.AuditLogger" ref="slf4jAuditLogger" />
</bean> </bean>
<bean name="aclCacheBean" factory-bean="ehCacheManager" factory-method="addCacheIfAbsent"> <bean id="aclCacheCache" factory-bean="cacheManager" factory-method="getCache">
<constructor-arg type="java.lang.String" value="acl" /> <constructor-arg value="aclcache"/>
</bean> </bean>
<bean name="aclCache" class="org.springframework.security.acls.domain.EhCacheBasedAclCache"> <bean name="aclCache" class="org.genesys2.server.cache.HazelcastAclCache">
<constructor-arg type="net.sf.ehcache.Ehcache" ref="aclCacheBean" /> <constructor-arg ref="aclCacheCache" />
<constructor-arg type="org.springframework.security.acls.model.PermissionGrantingStrategy" ref="permissionGrantingStrategy" /> <constructor-arg type="org.springframework.security.acls.model.PermissionGrantingStrategy" ref="permissionGrantingStrategy" />
<constructor-arg type="org.springframework.security.acls.domain.AclAuthorizationStrategy" ref="aclAuthorizationStrategy" /> <constructor-arg type="org.springframework.security.acls.domain.AclAuthorizationStrategy" ref="aclAuthorizationStrategy" />
</bean> </bean>
......
...@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver ...@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver
db.dialect=org.hibernate.dialect.MySQL5Dialect db.dialect=org.hibernate.dialect.MySQL5Dialect
db.username=root db.username=root
db.password= db.password=
db.showSql=true db.showSql=false
db.hbm2ddl=do-nothing db.hbm2ddl=do-nothing
c3p0.acquireIncrement=1 c3p0.acquireIncrement=1
...@@ -88,3 +88,14 @@ executor.queue.capacity=100 ...@@ -88,3 +88,14 @@ executor.queue.capacity=100
#scheduler properties #scheduler properties
scheduler.max.pool.size=16 scheduler.max.pool.size=16
# Hazelcast
hazelcast.name=genesys
hazelcast.password=hazelcasts
hazelcast.port=5701
# AWS Autodetection
hazelcast.aws.access-key=
hazelcast.aws.secret-key=
hazelcast.aws.region=eu-west-1
hazelcast.aws.security-group=sg-hazelcast
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment