Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
4971a015
Commit
4971a015
authored
Feb 20, 2014
by
Matija Obreza
Browse files
Removed ehcache, using hazelcast
parent
a901dbec
Changes
8
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
4971a015
...
...
@@ -360,11 +360,6 @@
</dependency>
<!--Other dependencies -->
<dependency>
<groupId>
net.sf.ehcache
</groupId>
<artifactId>
ehcache
</artifactId>
<version>
${ehcache.version}
</version>
</dependency>
<dependency>
<groupId>
net.sf.oval
</groupId>
...
...
@@ -458,6 +453,21 @@
<artifactId>
velocity
</artifactId>
<version>
1.7
</version>
</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>
<build>
...
...
src/main/java/org/genesys2/server/cache/HazelcastAclCache.java
0 → 100644
View file @
4971a015
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
();
}
}
src/main/java/org/genesys2/server/service/impl/AclServiceImpl.java
View file @
4971a015
...
...
@@ -20,8 +20,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
net.sf.ehcache.CacheManager
;
import
org.genesys2.server.aspect.AsAdminAspect
;
import
org.genesys2.server.model.AclAwareModel
;
import
org.genesys2.server.model.acl.AclClass
;
...
...
@@ -39,6 +37,7 @@ import org.genesys2.spring.SecurityContextUtil;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.acls.domain.BasePermission
;
import
org.springframework.security.acls.model.Permission
;
...
...
@@ -305,6 +304,6 @@ public class AclServiceImpl implements AclService {
aclEntry
.
setGranting
(
permissionMap
.
get
((
int
)
aclEntry
.
getMask
()));
}
aclEntryPersistence
.
save
(
aclEntries
);
cacheManager
.
getCache
(
"acl
"
).
removeAll
();
cacheManager
.
getCache
(
"acl
cache"
).
clear
();
}
}
src/main/resources/ehcache.xml
deleted
100644 → 0
View file @
a901dbec
<?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>
src/main/resources/spring/spring-cache.xml
View file @
4971a015
...
...
@@ -16,35 +16,76 @@
-->
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:
cache
=
"http://www.
springframework.org
/schema/
cache
"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache=
"http://www.springframework.org/schema/cache"
xmlns:
hz
=
"http://www.
hazelcast.com
/schema/
spring
"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd"
>
<cache:annotation-driven
cache-manager=
"cacheManager"
/>
<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>
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.hazelcast.com/schema/spring
http://www.hazelcast.com/schema/spring/hazelcast-spring-3.1.xsd"
>
<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>
src/main/resources/spring/spring-db.xml
View file @
4971a015
...
...
@@ -52,7 +52,7 @@
<property
name=
"jpaProperties"
>
<props>
<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.search.default.indexBase"
>
${lucene.indexDir}
</prop>
<prop
key=
"hibernate.search.default.exclusive_index_use"
>
false
</prop>
...
...
src/main/resources/spring/spring-security-acl.xml
View file @
4971a015
...
...
@@ -33,12 +33,12 @@
<constructor-arg
type=
"org.springframework.security.acls.domain.AuditLogger"
ref=
"slf4jAuditLogger"
/>
</bean>
<bean
name
=
"aclCache
Bean
"
factory-bean=
"
ehC
acheManager"
factory-method=
"
add
Cache
IfAbsent
"
>
<constructor-arg
type=
"java.lang.String"
value=
"acl"
/>
<bean
id
=
"aclCache
Cache
"
factory-bean=
"
c
acheManager"
factory-method=
"
get
Cache"
>
<constructor-arg
value=
"acl
cache
"
/>
</bean>
<bean
name=
"aclCache"
class=
"org.
springframework.security.acls.domain.EhCacheBased
AclCache"
>
<constructor-arg
type=
"net.sf.ehcache.Ehcache"
ref=
"aclCache
Bean
"
/>
<bean
name=
"aclCache"
class=
"org.
genesys2.server.cache.Hazelcast
AclCache"
>
<constructor-arg
ref=
"acl
Cache
Cache"
/>
<constructor-arg
type=
"org.springframework.security.acls.model.PermissionGrantingStrategy"
ref=
"permissionGrantingStrategy"
/>
<constructor-arg
type=
"org.springframework.security.acls.domain.AclAuthorizationStrategy"
ref=
"aclAuthorizationStrategy"
/>
</bean>
...
...
src/main/resources/spring/spring.properties
View file @
4971a015
...
...
@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver
db.dialect
=
org.hibernate.dialect.MySQL5Dialect
db.username
=
root
db.password
=
db.showSql
=
tru
e
db.showSql
=
fals
e
db.hbm2ddl
=
do-nothing
c3p0.acquireIncrement
=
1
...
...
@@ -88,3 +88,14 @@ executor.queue.capacity=100
#scheduler properties
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment