This is an automated email from the ASF dual-hosted git repository.
lprimak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/3.x by this push:
new 3af1a972f enh: remove ehcache and hazelcast modules in favor of just
keeping jcache fixes #2516
3af1a972f is described below
commit 3af1a972f642e2fd95676ebbe67e42bcd8fb8f72
Author: lprimak <[email protected]>
AuthorDate: Sat Feb 7 13:52:28 2026 -0600
enh: remove ehcache and hazelcast modules in favor of just keeping jcache
fixes #2516
---
pom.xml | 36 +--
samples/spring-hibernate/pom.xml | 17 --
samples/spring-mvc/pom.xml | 12 +-
.../samples/spring/config/ApplicationConfig.java | 18 +-
support/ehcache/pom.xml | 98 --------
.../org/apache/shiro/cache/ehcache/EhCache.java | 247 ------------------
.../apache/shiro/cache/ehcache/EhCacheManager.java | 275 ---------------------
.../apache/shiro/cache/ehcache/package-info.java | 23 --
support/ehcache/src/main/resources/META-INF/NOTICE | 15 --
.../org/apache/shiro/cache/ehcache/ehcache.xml | 106 --------
.../shiro/cache/ehcache/EhCacheManagerTest.java | 203 ---------------
support/ehcache/src/test/resources/log4j2-test.xml | 62 -----
support/hazelcast/pom.xml | 89 -------
.../hazelcast/cache/HazelcastCacheManager.java | 246 ------------------
.../apache/shiro/hazelcast/cache/package-info.java | 23 --
.../hazelcast/src/main/resources/META-INF/NOTICE | 15 --
.../cache/HazelcastCacheManagerTest.groovy | 156 ------------
.../hazelcast/src/test/resources/log4j2-test.xml | 62 -----
support/pom.xml | 2 -
19 files changed, 13 insertions(+), 1692 deletions(-)
diff --git a/pom.xml b/pom.xml
index 176c93a91..8231943fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -99,11 +99,6 @@
<commons.lang3.version>3.20.0</commons.lang3.version>
<commons.logging.version>1.3.5</commons.logging.version>
<commons.text.version>1.8</commons.text.version>
- <!-- Don't change this version without also changing the shiro-ehcache
and shiro-features
- modules' OSGi metadata: -->
- <ehcache.version>3.11.1</ehcache.version>
- <!-- Don't change this version without also changing the
shiro-hazelcast and shiro-features OSGi metadata: -->
- <hazelcast.version>5.6.0</hazelcast.version>
<hsqldb.version>2.7.4</hsqldb.version>
<jcache.api.version>1.1.1</jcache.api.version>
<jdk.version>17</jdk.version>
@@ -932,7 +927,7 @@
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
- <artifactId>shiro-ehcache</artifactId>
+ <artifactId>shiro-jcache</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -950,11 +945,6 @@
<artifactId>shiro-guice</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-hazelcast</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-jaxrs</artifactId>
@@ -1208,24 +1198,6 @@
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
- <dependency>
- <groupId>org.ehcache</groupId>
- <artifactId>ehcache</artifactId>
- <version>${ehcache.version}</version>
- <classifier>jakarta</classifier>
- <optional>true</optional>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast</artifactId>
- <version>${hazelcast.version}</version>
- </dependency>
<dependency>
<groupId>org.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
@@ -1351,6 +1323,12 @@
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jaxb</groupId>
+ <artifactId>jaxb-runtime</artifactId>
+ <version>4.0.6</version>
+ </dependency>
+
<!-- Guice -->
<dependency>
<groupId>com.google.inject</groupId>
diff --git a/samples/spring-hibernate/pom.xml b/samples/spring-hibernate/pom.xml
index 47c2bce99..742880f40 100644
--- a/samples/spring-hibernate/pom.xml
+++ b/samples/spring-hibernate/pom.xml
@@ -80,23 +80,6 @@
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
- <dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- <version>4.0.5</version>
- </dependency>
- <dependency>
- <groupId>org.ehcache</groupId>
- <artifactId>ehcache</artifactId>
- <classifier>jakarta</classifier>
- <scope>runtime</scope>
- <exclusions>
- <exclusion>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
diff --git a/samples/spring-mvc/pom.xml b/samples/spring-mvc/pom.xml
index 0fe871383..44349d260 100644
--- a/samples/spring-mvc/pom.xml
+++ b/samples/spring-mvc/pom.xml
@@ -68,7 +68,7 @@
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
- <artifactId>shiro-ehcache</artifactId>
+ <artifactId>shiro-jcache</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
@@ -78,20 +78,14 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
- <version>4.0.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
+ <version>3.11.1</version>
<classifier>jakarta</classifier>
- <optional>false</optional>
- <exclusions>
- <exclusion>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- </exclusion>
- </exclusions>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
diff --git
a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/ApplicationConfig.java
b/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/ApplicationConfig.java
index 11ea03d5e..36a71d0d0 100644
---
a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/ApplicationConfig.java
+++
b/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/ApplicationConfig.java
@@ -19,7 +19,7 @@
package org.apache.shiro.samples.spring.config;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
-import org.apache.shiro.cache.ehcache.EhCacheManager;
+import org.apache.shiro.cache.jcache.JCacheManager;
import org.apache.shiro.samples.spring.BootstrapDataPopulator;
import org.apache.shiro.samples.spring.DefaultSampleManager;
import org.apache.shiro.samples.spring.realm.SaltAwareJdbcRealm;
@@ -98,20 +98,8 @@ public class ApplicationConfig {
* @return
*/
@Bean
- protected EhCacheManager cacheManager() {
-
- EhCacheManager ehCacheManager = new EhCacheManager();
-
- // Set a net.sf.ehcache.CacheManager instance here if you already have
one.
- // If not, a new one will be created with a default config:
- // ehCacheManager.setCacheManager(...);
-
- // If you don't have a pre-built net.sf.ehcache.CacheManager instance
to inject, but you want
- // a specific Ehcache configuration to be used, specify that here. If
you don't, a default
- //will be used.:
- //
ehCacheManager.setCacheManagerConfigFile("classpath:some/path/to/ehcache.xml");
-
- return ehCacheManager;
+ protected JCacheManager cacheManager() {
+ return new JCacheManager();
}
/**
diff --git a/support/ehcache/pom.xml b/support/ehcache/pom.xml
deleted file mode 100644
index 6cd55d371..000000000
--- a/support/ehcache/pom.xml
+++ /dev/null
@@ -1,98 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-support</artifactId>
- <version>999-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>shiro-ehcache</artifactId>
- <name>Apache Shiro :: Support :: EHCache</name>
- <packaging>bundle</packaging>
- <properties>
- <module.name>ehcache</module.name>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-cache</artifactId>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- <version>4.0.6</version>
- </dependency>
- <dependency>
- <groupId>org.ehcache</groupId>
- <artifactId>ehcache</artifactId>
- <classifier>jakarta</classifier>
- <exclusions>
- <exclusion>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <!-- Test dependencies -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j2-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
-
<Bundle-SymbolicName>org.apache.shiro.ehcache</Bundle-SymbolicName>
-
<Export-Package>org.apache.shiro.cache.ehcache*;version=${project.version}</Export-Package>
- <Import-Package>
-
org.apache.shiro.cache*;version="${shiro.osgi.importRange}",
- org.ehcache*;version="[3.10, 4)",
- *
- </Import-Package>
- <_removeheaders>Bnd-LastModified</_removeheaders>
- <_reproducible>true</_reproducible>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
diff --git
a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java
b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java
deleted file mode 100644
index 358eb3923..000000000
--- a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.shiro.cache.ehcache;
-
-import java.util.LinkedList;
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.cache.CacheException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-
-/**
- * Shiro {@link org.apache.shiro.cache.Cache} implementation that wraps an
{@link org.ehcache.core.Ehcache} instance.
- *
- * @param <K> K
- * @param <V> V
- * @since 0.2
- */
-public class EhCache<K, V> implements Cache<K, V> {
-
- /**
- * Private internal log instance.
- */
- private static final Logger LOGGER =
LoggerFactory.getLogger(EhCache.class);
-
- /**
- * The wrapped Ehcache instance.
- */
- private org.ehcache.Cache<K, V> cache;
-
- /**
- * Constructs a new EhCache instance with the given cache.
- *
- * @param cache - delegate EhCache instance this Shiro cache instance will
wrap.
- */
- public EhCache(org.ehcache.Cache<K, V> cache) {
- if (cache == null) {
- throw new IllegalArgumentException("Cache argument cannot be
null.");
- }
- this.cache = cache;
- }
-
- /**
- * Gets a value of an element which matches the given key.
- *
- * @param key the key of the element to return.
- * @return The value placed into the cache with an earlier put, or null if
not found or expired
- */
- public V get(K key) throws CacheException {
- try {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Getting object from cache [{}] for key [{}]",
cache, key);
- }
- if (key == null) {
- return null;
- } else {
- V element = cache.get(key);
- if (element == null) {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Element for [{}] is null.", key);
- }
- return null;
- } else {
- return element;
- }
- }
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- /**
- * Puts an object into the cache.
- *
- * @param key the key.
- * @param value the value.
- */
- public V put(K key, V value) throws CacheException {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Putting object in cache [{}] for key [{}]", cache,
key);
- }
- try {
- V previous = get(key);
- cache.put(key, value);
- return previous;
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- /**
- * Removes the element which matches the key.
- *
- * <p>If no element matches, nothing is removed and no Exception is
thrown.</p>
- *
- * @param key the key of the element to remove
- */
- public V remove(K key) throws CacheException {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Removing object from cache [{}] for key [{}]",
cache, key);
- }
- try {
- V previous = get(key);
- cache.remove(key);
- return previous;
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- /**
- * Removes all elements in the cache, but leaves the cache in a usable
state.
- */
- public void clear() throws CacheException {
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Clearing all objects from cache [{}]", cache);
- }
- try {
- cache.removeAll(keys());
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- public int size() {
- try {
- int size = 0;
- for (org.ehcache.Cache.Entry<K, V> ignored : cache) {
- size++;
- }
- return size;
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- public Set<K> keys() {
- try {
- List<K> keys = new LinkedList<>();
- for (org.ehcache.Cache.Entry<K, V> entry : cache) {
- keys.add(entry.getKey());
- }
-
- if (!isEmpty(keys)) {
- return Collections.unmodifiableSet(new LinkedHashSet<>(keys));
- } else {
- return Collections.emptySet();
- }
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- public Collection<V> values() {
- try {
- Set<K> keys = keys();
- if (!isEmpty(keys)) {
- List<V> values = new ArrayList<>(keys.size());
- for (K key : keys) {
- V value = get(key);
- if (value != null) {
- values.add(value);
- }
- }
- return Collections.unmodifiableList(values);
- } else {
- return Collections.emptyList();
- }
- } catch (Throwable t) {
- throw new CacheException(t);
- }
- }
-
- /**
- * Returns the size (in bytes) that this EhCache is using in memory (RAM),
or <code>-1</code> if that
- * number is unknown or cannot be calculated.
- *
- * @return the size (in bytes) that this EhCache is using in memory (RAM),
or <code>-1</code> if that
- * number is unknown or cannot be calculated.
- */
- public long getMemoryUsage() {
- return -1;
- }
-
- /**
- * Returns the size (in bytes) that this EhCache's memory store is using
(RAM), or <code>-1</code> if
- * that number is unknown or cannot be calculated.
- *
- * @return the size (in bytes) that this EhCache's memory store is using
(RAM), or <code>-1</code> if
- * that number is unknown or cannot be calculated.
- */
- public long getMemoryStoreSize() {
- return -1;
- }
-
- /**
- * Returns the size (in bytes) that this EhCache's disk store is consuming
or <code>-1</code> if
- * that number is unknown or cannot be calculated.
- *
- * @return the size (in bytes) that this EhCache's disk store is consuming
or <code>-1</code> if
- * that number is unknown or cannot be calculated.
- */
- public long getDiskStoreSize() {
- return -1;
- }
-
- /**
- * Returns "EhCache [" + cache + "]"
- *
- * @return "EhCache [" + cache + "]"
- */
- public String toString() {
- return "EhCache [" + cache + "]";
- }
-
- //////////////////////////
- // From CollectionUtils //
- //////////////////////////
- // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a
dependency on PrincipalCollection
-
- private static boolean isEmpty(Collection<?> c) {
- return c == null || c.isEmpty();
- }
-}
diff --git
a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java
b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java
deleted file mode 100644
index 58f826b53..000000000
---
a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.shiro.cache.ehcache;
-
-import java.io.Serializable;
-import java.net.URL;
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.cache.CacheException;
-import org.apache.shiro.cache.CacheManager;
-import org.apache.shiro.lang.io.ResourceUtils;
-import org.apache.shiro.lang.util.Destroyable;
-import org.apache.shiro.lang.util.Initializable;
-import org.ehcache.config.CacheConfiguration;
-import org.ehcache.config.builders.CacheManagerBuilder;
-import org.ehcache.xml.XmlConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Shiro {@code CacheManager} implementation utilizing the Ehcache framework
for all cache functionality.
- * <p/>
- * This class can {@link #setCacheManager(org.ehcache.CacheManager) accept} a
manually configured
- * {@link org.ehcache.CacheManager org.ehcache.CacheManager} instance,
- * or an {@code ehcache.xml} path location can be specified instead and one
will be constructed. If neither are
- * specified, Shiro's failsafe <code><a
href="./ehcache.xml">ehcache.xml</a></code> file will be used by default.
- * <p/>
- * This implementation requires EhCache 1.2 and above. Make sure EhCache 1.1
or earlier
- * is not in the classpath or it will not work.
- * <p/>
- * Please see the <a href="http://ehcache.org" target="_top">Ehcache
website</a> for their documentation.
- *
- * @see <a href="http://ehcache.org" target="_top">The Ehcache website</a>
- * @since 0.2
- */
-public class EhCacheManager implements CacheManager, Initializable,
Destroyable {
-
- /**
- * This class's private log instance.
- */
- private static final Logger LOGGER =
LoggerFactory.getLogger(EhCacheManager.class);
-
- /**
- * The EhCache cache manager used by this implementation to create caches.
- */
- protected org.ehcache.CacheManager manager;
-
- /**
- * Indicates if the CacheManager instance was implicitly/automatically
created by this instance, indicating that
- * it should be automatically cleaned up as well on shutdown.
- */
- private boolean cacheManagerImplicitlyCreated;
-
- /**
- * Classpath file location of the ehcache CacheManager config file.
- */
- private String cacheManagerConfigFile =
"classpath:org/apache/shiro/cache/ehcache/ehcache.xml";
-
- /**
- * Default no argument constructor
- */
- public EhCacheManager() {
- }
-
- /**
- * Returns the wrapped Ehcache {@link org.ehcache.CacheManager
CacheManager} instance.
- *
- * @return the wrapped Ehcache {@link org.ehcache.CacheManager
CacheManager} instance.
- */
- public org.ehcache.CacheManager getCacheManager() {
- return manager;
- }
-
- /**
- * Sets the wrapped Ehcache {@link org.ehcache.CacheManager CacheManager}
instance.
- *
- * @param manager the wrapped Ehcache {@link org.ehcache.CacheManager
CacheManager} instance.
- */
- public void setCacheManager(org.ehcache.CacheManager manager) {
- this.manager = manager;
- }
-
- /**
- * Returns the resource location of the config file used to initialize a
new
- * EhCache CacheManager instance. The string can be any resource path
supported by the
- * {@link
org.apache.shiro.lang.io.ResourceUtils#getInputStreamForPath(String)} call.
- * <p/>
- * This property is ignored if the CacheManager instance is injected
directly - that is, it is only used to
- * lazily create a CacheManager if one is not already provided.
- *
- * @return the resource location of the config file used to initialize the
wrapped
- * EhCache CacheManager instance.
- */
- public String getCacheManagerConfigFile() {
- return this.cacheManagerConfigFile;
- }
-
- /**
- * Sets the resource location of the config file used to initialize the
wrapped
- * EhCache CacheManager instance. The string can be any resource path
supported by the
- * {@link
org.apache.shiro.lang.io.ResourceUtils#getInputStreamForPath(String)} call.
- * <p/>
- * This property is ignored if the CacheManager instance is injected
directly - that is, it is only used to
- * lazily create a CacheManager if one is not already provided.
- *
- * @param classpathLocation resource location of the config file used to
create the wrapped
- * EhCache CacheManager instance.
- */
- public void setCacheManagerConfigFile(String classpathLocation) {
- this.cacheManagerConfigFile = classpathLocation;
- }
-
- /**
- * Acquires the InputStream for the ehcache configuration file using
- * {@link ResourceUtils#getInputStreamForPath(String)
ResourceUtils.getInputStreamForPath} with the
- * path returned from {@link #getCacheManagerConfigFile()
getCacheManagerConfigFile()}.
- *
- * @return the InputStream for the ehcache configuration file.
- */
- protected InputStream getCacheManagerConfigFileInputStream() {
- String configFile = getCacheManagerConfigFile();
- try {
- return ResourceUtils.getInputStreamForPath(configFile);
- } catch (IOException e) {
- throw new IllegalStateException("Unable to obtain input stream for
cacheManagerConfigFile ["
- + configFile + "]", e);
- }
- }
-
- /**
- * Acquires the URL for the ehcache configuration file using
- * {@link ResourceUtils#getURLForPath(String) ResourceUtils.getURLForPath}
with the
- * path returned from {@link #getCacheManagerConfigFile()
getCacheManagerConfigFile()}.
- *
- * @return the URL for the ehcache configuration file.
- */
- protected URL getCacheManagerConfigFileUrl() {
- final var configFile = getCacheManagerConfigFile();
- try {
- return ResourceUtils.getURLForPath(configFile);
- } catch (IOException e) {
- throw new IllegalStateException("Unable to parse
cacheManagerConfigFile ["
- + configFile + "]", e);
- }
- }
-
- /**
- * Loads an existing EhCache from the cache manager, or starts a new cache
if one is not found.
- *
- * @param name the name of the cache to load/create.
- */
- @Override
- public final <K, V> Cache<K, V> getCache(String name)
- throws CacheException {
-
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("Acquiring EhCache instance named [{}]", name);
- }
-
- try {
- @SuppressWarnings("unchecked")
- org.ehcache.Cache<K, V> cache = (org.ehcache.Cache<K, V>)
ensureCacheManager()
- .getCache(name, Serializable.class, Serializable.class);
- if (cache == null) {
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Cache with name '{}' does not yet exist.
Creating now.", name);
- }
- @SuppressWarnings("unchecked")
- CacheConfiguration<K, V> config = (CacheConfiguration<K, V>)
new XmlConfiguration(getCacheManagerConfigFileUrl())
- .newCacheConfigurationBuilderFromTemplate("default",
Serializable.class, Serializable.class)
- .build();
- cache = manager.createCache(name, config);
-
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Added EhCache named [{}]", name);
- }
- } else {
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Using existing EHCache named [{}]", name);
- }
- }
- return new EhCache<>(cache);
- } catch (IllegalArgumentException | IllegalStateException |
ReflectiveOperationException e) {
- throw new CacheException(e);
- }
- }
-
- /**
- * Initializes this instance.
- * <p/>
- * If a {@link #setCacheManager CacheManager} has been
- * explicitly set (e.g. via Dependency Injection or programmatically)
prior to calling this
- * method, this method does nothing.
- * <p/>
- * However, if no {@code CacheManager} has been set, the default Ehcache
singleton will be initialized, where
- * Ehcache will look for an {@code ehcache.xml} file at the root of the
classpath. If one is not found,
- * Ehcache will use its own failsafe configuration file.
- * <p/>
- * Because Shiro cannot use the failsafe defaults (fail-safe expunges
cached objects after 2 minutes,
- * something not desirable for Shiro sessions), this class manages an
internal default configuration for
- * this case.
- *
- * @throws org.apache.shiro.cache.CacheException if there are any
CacheExceptions thrown by EhCache.
- * @see org.ehcache.CacheManager#createCache(String,
org.ehcache.config.CacheConfiguration)
- */
- public final void init() throws CacheException {
- ensureCacheManager();
- }
-
- private org.ehcache.CacheManager ensureCacheManager() {
- try {
- if (this.manager == null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("cacheManager property not set. Constructing
CacheManager instance... ");
- }
- final XmlConfiguration xmlConfig = new
XmlConfiguration(getCacheManagerConfigFileUrl());
- this.manager = CacheManagerBuilder.newCacheManager(xmlConfig);
- this.manager.init();
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("instantiated Ehcache CacheManager
instance.");
- }
- cacheManagerImplicitlyCreated = true;
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("implicit cacheManager created
successfully.");
- }
- }
- return this.manager;
- } catch (Exception e) {
- throw new CacheException(e);
- }
- }
-
- /**
- * Shuts-down the wrapped Ehcache CacheManager <b>only if implicitly
created</b>.
- * <p/>
- * If another component injected
- * a non-null CacheManager into this instance before calling {@link
#init() init}, this instance expects that same
- * component to also destroy the CacheManager instance, and it will not
attempt to do so.
- */
- public void destroy() {
- if (cacheManagerImplicitlyCreated) {
- try {
- org.ehcache.CacheManager cacheMgr = getCacheManager();
- cacheMgr.close();
- } catch (Throwable t) {
- if (LOGGER.isWarnEnabled()) {
- LOGGER.warn("Unable to cleanly shutdown implicitly created
CacheManager instance. "
- + "Ignoring (shutting down)...", t);
- }
- } finally {
- this.manager = null;
- this.cacheManagerImplicitlyCreated = false;
- }
- }
- }
-
-}
diff --git
a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/package-info.java
b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/package-info.java
deleted file mode 100644
index 72faf544f..000000000
---
a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-/**
- * <a href="http://ehcache.sourceforge.net" target="_top">Ehcache</a>-based
implementations of Shiro's
- * cache interfaces.
- */
-package org.apache.shiro.cache.ehcache;
diff --git a/support/ehcache/src/main/resources/META-INF/NOTICE
b/support/ehcache/src/main/resources/META-INF/NOTICE
deleted file mode 100644
index bdc909e8c..000000000
--- a/support/ehcache/src/main/resources/META-INF/NOTICE
+++ /dev/null
@@ -1,15 +0,0 @@
-Apache Shiro
-Copyright 2008-2020 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
-The implementation for org.apache.shiro.util.SoftHashMap is based
-on initial ideas from Dr. Heinz Kabutz's publicly posted version
-available at http://www.javaspecialists.eu/archive/Issue015.html,
-with continued modifications.
-
-Certain parts (StringUtils, IpAddressMatcher, etc.) of the source
-code for this product was copied for simplicity and to reduce
-dependencies from the source code developed by the Spring Framework
-Project (http://www.springframework.org).
diff --git
a/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml
b/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml
deleted file mode 100644
index e232e922f..000000000
---
a/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-<config xmlns="http://www.ehcache.org/v3"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.ehcache.org/v3
https://www.ehcache.org/schema/ehcache-core-3.3.xsd">
-
- <!-- Sets the path to the directory where cache .data files are created.
-
- If the path is a Java System Property it is replaced by
- its value in the running VM. The following properties are translated:
-
- user.home - User's home directory
- user.dir - User's current working directory
- java.io.tmpdir - Default temp file path
- -->
- <persistence directory="${java.io.tmpdir}/shiro-ehcache"/>
-
-
- <!--Default Cache configuration. These will applied to caches
programmatically created through
- the CacheManager.
-
- The following attributes are required:
-
- maxElementsInMemory - Sets the maximum number of objects that
will be created in memory
- eternal - Sets whether elements are eternal. If
eternal, timeouts are ignored and the
- element is never expired.
- overflowToDisk - Sets whether elements can overflow to
disk when the in-memory cache
- has reached the maxInMemory limit.
-
- The following attributes are optional:
- timeToIdleSeconds - Sets the time to idle for an element
before it expires.
- i.e. The maximum amount of time between
accesses before an element expires
- Is only used if the element is not
eternal.
- Optional attribute. A value of 0 means
that an Element can idle for infinity.
- The default value is 0.
- timeToLiveSeconds - Sets the time to live for an element
before it expires.
- i.e. The maximum time between creation
time and when an element expires.
- Is only used if the element is not
eternal.
- Optional attribute. A value of 0 means
that and Element can live for infinity.
- The default value is 0.
- diskPersistent - Whether the disk store persists between
restarts of the Virtual Machine.
- The default value is false.
- diskExpiryThreadIntervalSeconds- The number of seconds between runs of the
disk expiry thread. The default value
- is 120 seconds.
- memoryStoreEvictionPolicy - Policy would be enforced upon reaching
the maxElementsInMemory limit. Default
- policy is Least Recently Used (specified
as LRU). Other policies available -
- First In First Out (specified as FIFO)
and Less Frequently Used
- (specified as LFU)
- -->
-
- <cache-template name="default">
- <expiry>
- <ttl>120</ttl>
- </expiry>
- <heap>10000</heap>
- </cache-template>
-
- <!-- We want eternal="true" and no timeToIdle or timeToLive settings
because Shiro manages session
- expirations explicitly. If we set it to false and then set
corresponding timeToIdle and timeToLive properties,
- ehcache would evict sessions without Shiro's knowledge, which would
cause many problems
- (e.g. "My Shiro session timeout is 30 minutes - why isn't a session
available after 2 minutes?"
- Answer - ehcache expired it due to the timeToIdle property set
to 120 seconds.)
-
- diskPersistent=true since we want an enterprise session management
feature - ability to use sessions after
- even after a JVM restart. -->
- <cache alias="shiro-activeSessionCache">
- <key-type>java.io.Serializable</key-type>
- <value-type>java.io.Serializable</value-type>
- <expiry>
- <none/>
- </expiry>
- <resources>
- <heap>10000</heap>
- <disk persistent="true" unit="MB">50</disk>
- </resources>
- </cache>
-
- <cache alias="org.apache.shiro.realm.text.PropertiesRealm-0-accounts">
- <key-type>java.io.Serializable</key-type>
- <value-type>java.io.Serializable</value-type>
- <expiry>
- <none/>
- </expiry>
- <resources>
- <heap>10000</heap>
- <disk persistent="true" unit="MB">50</disk>
- </resources>
- </cache>
-
-</config>
diff --git
a/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java
b/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java
deleted file mode 100644
index 1efcb201f..000000000
---
a/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.shiro.cache.ehcache;
-
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.lang.util.LifecycleUtils;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.Isolated;
-
-import java.util.Collection;
-import java.util.Set;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * TODO - Class JavaDoc
- *
- * @since May 11, 2010 12:41:38 PM
- */
-@Isolated
-public class EhCacheManagerTest {
-
- private EhCacheManager cacheManager;
-
- @BeforeEach
- public void setUp() {
- cacheManager = new EhCacheManager();
- }
-
- @AfterEach
- public void tearDown() {
- LifecycleUtils.destroy(cacheManager);
- }
-
- @Test
- void testCacheManagerCreationDuringInit() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
- cacheManager.init();
- //now assert that an internal CacheManager has been created:
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
- }
-
- @Test
- void testLazyCacheManagerCreationWithoutCallingInit() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
-
- //don't call init here - the ehcache CacheManager should be lazily
created
- //because of the default Shiro ehcache.xml file in the classpath.
Just acquire a cache:
- Cache<String, String> cache = cacheManager.getCache("test");
-
- //now assert that an internal CacheManager has been created:
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
-
- assertThat(cache).isNotNull();
- cache.put("hello", "world");
- String value = cache.get("hello");
- assertThat(value).isNotNull();
- assertThat(value).isEqualTo("world");
- }
-
- @Test
- void testRemove() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
-
- Cache<String, String> cache = cacheManager.getCache("test");
-
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
-
- assertThat(cache).isNotNull();
- cache.put("hello", "world");
- cache.put("hello2", "world2");
- String value = cache.get("hello");
- assertThat(value).isNotNull();
- assertThat(value).isEqualTo("world");
- assertThat(cache.get("hello2")).isEqualTo("world2");
- assertThat(cache.size()).isEqualTo(2);
-
- assertThat(cache.remove("hello")).isEqualTo("world");
- assertThat(cache.size()).isEqualTo(1);
- assertThat(cache.remove("hello2")).isEqualTo("world2");
- assertThat(cache.size()).isEqualTo(0);
-
- assertThat(cache.remove("blah")).isNull();
- }
-
- @Test
- void testClear() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
-
- Cache<String, String> cache = cacheManager.getCache("test");
-
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
-
- assertThat(cache).isNotNull();
- cache.put("hello", "world");
- cache.put("hello2", "world2");
- String value = cache.get("hello");
- assertThat(value).isNotNull();
- assertThat(value).isEqualTo("world");
- assertThat(cache.get("hello2")).isEqualTo("world2");
- assertThat(cache.size()).isEqualTo(2);
-
- cache.clear();
- assertThat(cache.size()).isEqualTo(0);
-
- assertThat(cache.get("hello")).isNull();
- }
-
- @Test
- void testKeys() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
-
- Cache<String, String> cache = cacheManager.getCache("test");
-
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
-
- assertThat(cache).isNotNull();
- cache.put("hello", "world");
- cache.put("hello2", "world2");
- String value = cache.get("hello");
- assertThat(value).isNotNull();
- assertThat(value).isEqualTo("world");
- assertThat(cache.get("hello2")).isEqualTo("world2");
- assertThat(cache.size()).isEqualTo(2);
-
- Set<String> keys = cache.keys();
- assertThat(keys).hasSize(2);
- assertThat(keys).contains("hello");
- assertThat(keys).contains("hello2");
-
- assertThat(cache.remove("hello")).isEqualTo("world");
- assertThat(cache.size()).isEqualTo(1);
-
- keys = cache.keys();
- assertThat(keys).hasSize(1);
- assertThat(keys).contains("hello2");
-
- assertThat(cache.remove("blah")).isNull();
- }
-
- @Test
- void testValues() {
- org.ehcache.CacheManager ehCacheManager =
cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNull();
-
- Cache<String, String> cache = cacheManager.getCache("test");
-
- ehCacheManager = cacheManager.getCacheManager();
- assertThat(ehCacheManager).isNotNull();
-
- assertThat(cache).isNotNull();
- cache.put("hello", "world");
- cache.put("hello2", "world2");
- String value = cache.get("hello");
- assertThat(value).isNotNull();
- assertThat(value).isEqualTo("world");
- assertThat(cache.get("hello2")).isEqualTo("world2");
- assertThat(cache.size()).isEqualTo(2);
-
- Collection<String> values = cache.values();
- assertThat(values).hasSize(2);
- assertThat(values).contains("world");
- assertThat(values).contains("world2");
-
- assertThat(cache.remove("hello")).isEqualTo("world");
- assertThat(cache.size()).isEqualTo(1);
-
- values = cache.values();
- assertThat(values).hasSize(1);
- assertThat(values).contains("world2");
-
- assertThat(cache.remove("blah")).isNull();
- }
-
-}
diff --git a/support/ehcache/src/test/resources/log4j2-test.xml
b/support/ehcache/src/test/resources/log4j2-test.xml
deleted file mode 100644
index bd8c3cb39..000000000
--- a/support/ehcache/src/test/resources/log4j2-test.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-
-<Configuration name="ConfigTest" status="ERROR" monitorInterval="5">
- <!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36}
- %msg%n"/>
- </Console>
- </Appenders>
- <Loggers>
- <Logger name="org.apache" level="warn" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.ehcache" level="warn" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.apache.shiro" level="info" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.apache.shiro.util.ThreadContext" level="warn"
additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Root level="warn">
- <AppenderRef ref="Console"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/support/hazelcast/pom.xml b/support/hazelcast/pom.xml
deleted file mode 100644
index aeee6b0ab..000000000
--- a/support/hazelcast/pom.xml
+++ /dev/null
@@ -1,89 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-support</artifactId>
- <version>999-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>shiro-hazelcast</artifactId>
- <name>Apache Shiro :: Support :: Hazelcast</name>
- <packaging>bundle</packaging>
-
- <properties>
- <hazelcast.osgi.importRange>[4, 5)</hazelcast.osgi.importRange>
- <module.name>hazelcast</module.name>
-
<surefire.argLine>--sun-misc-unsafe-memory-access=allow</surefire.argLine>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-cache</artifactId>
- </dependency>
- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast</artifactId>
- </dependency>
- <!-- Test dependencies -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j2-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
-
<Bundle-SymbolicName>org.apache.shiro.hazelcast</Bundle-SymbolicName>
-
<Export-Package>org.apache.shiro.hazelcast*;version=${project.version}</Export-Package>
- <Import-Package>
-
org.apache.shiro.cache*;version="${shiro.osgi.importRange}",
-
com.hazelcast*;version="${hazelcast.osgi.importRange}",
- *
- </Import-Package>
- <_removeheaders>Bnd-LastModified</_removeheaders>
- <_reproducible>true</_reproducible>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
diff --git
a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
b/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
deleted file mode 100644
index 691c9692a..000000000
---
a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.shiro.hazelcast.cache;
-
-import com.hazelcast.config.Config;
-import com.hazelcast.core.Hazelcast;
-import com.hazelcast.core.HazelcastInstance;
-import org.apache.shiro.lang.ShiroException;
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.cache.CacheException;
-import org.apache.shiro.cache.CacheManager;
-import org.apache.shiro.cache.MapCache;
-import org.apache.shiro.lang.util.Destroyable;
-import org.apache.shiro.lang.util.Initializable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-
-/**
- * A {@code CacheManager} implementation backed by <a
href="http://www.hazelcast.com/">Hazelcast</a>,
- * "an open source clustering and highly scalable data distribution
platform for Java"
- * <p/>
- * This implementation interacts with a {@link HazelcastInstance} to
- * {@link HazelcastInstance#getMap(String) acquire} named {@link
java.util.concurrent.ConcurrentMap ConcurrentMap}
- * instances. Those clustered/distributed Map instances are then wrapped and
made available to {@code CacheManager}
- * callers as {@link MapCache} instances via {@link #getCache(String)}.
- * <h2>Configuration</h2>
- * This implementation's backing {@code HazelcastInstance} can be configured
in one of three ways:
- * <ol>
- * <li>Doing nothing and leveraging default Hazelcast configuration
mechanisms</li>
- * <li>Supplying an already-existing {@code HazelcastInstance}</li>
- * <li>Supplying a {@link Config} instance and using that to create a new
{@code HazelcastInstance}</li>
- * </ol>
- * <h3>Default Configuration</h3>
- * If you simply instantiate a {@code HazelcastCacheManager} and do nothing
further, its backing
- * {@link HazelcastInstance} instance will be created automatically by calling
- * {@link Hazelcast#newHazelcastInstance(com.hazelcast.config.Config)
Hazelcast.newHazelcastInstance(null)}.
- * <p/>
- * The null argument instructs Hazelcast to use whatever default configuration
mechanism it has at its disposal,
- * usually a {@code hazelcast.xml} file at the root of the classpath, or if
that is not present, the
- * {@code hazelcast-default.xml} file contained in the Hazelcast {@code .jar}
file itself.
- * <p/>
- * <h3>An existing {@code HazelcastInstance}</h3>
- * If you have created a {@code HazelcastInstance} outside of Shiro's
knowledge/control, you can simply configure it
- * to be used by calling {@link
#setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
setHazelcastInstance}.
- * <p/>
- * <h3>A {@link Config} instance</h3>
- * If you do not want to use the above two options, you can have programmatic
control over all of Hazelcast's
- * configuration by <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">creating
and configuring a
- * Config instance</a>.
- * <p/>
- * Once constructed, you can set it via {@link
#setConfig(com.hazelcast.config.Config) setConfig(config)}. This config
- * instance will be used to acquire a new Hazelcast instance by calling
- * {@link Hazelcast#newHazelcastInstance(Config)
Hazelcast.newHazelcastInstance(config)}
- *
- * @see <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">Hazelcast
Configuration Documentation</a>
- * @since 1.3
- */
-public class HazelcastCacheManager implements CacheManager, Initializable,
Destroyable {
-
- private static final Logger LOGGER =
LoggerFactory.getLogger(HazelcastCacheManager.class);
-
- private boolean implicitlyCreated;
- private HazelcastInstance hazelcastInstance;
- private Config config;
-
- /**
- * Returns a {@link MapCache} instance representing the named
Hazelcast-managed
- * {@link com.hazelcast.core.IMap IMap}. The Hazelcast Map is obtained by
calling
- * {@link HazelcastInstance#getMap(String) hazelcastInstance.getMap(name)}.
- *
- * @param name the name of the cache to acquire.
- * @param <K> the type of map key
- * @param <V> the type of map value
- * @return a {@link MapCache} instance representing the named
Hazelcast-managed {@link com.hazelcast.core.IMap IMap}.
- * @throws CacheException
- * @see HazelcastInstance#getMap(String)
- * @see #ensureHazelcastInstance()
- */
- public <K, V> Cache<K, V> getCache(String name) throws CacheException {
- //returned map is a ConcurrentMap
- Map<K, V> map = ensureHazelcastInstance().getMap(name);
- return new MapCache<K, V>(name, map);
- }
-
- /**
- * Ensures that this implementation has a backing {@link
HazelcastInstance}, and if not, implicitly creates one
- * via {@link #createHazelcastInstance()}.
- *
- * @return the backing (potentially newly created) {@code
HazelcastInstance}.
- * @see #createHazelcastInstance()
- * @see HazelcastInstance
- */
- protected HazelcastInstance ensureHazelcastInstance() {
- if (this.hazelcastInstance == null) {
- this.hazelcastInstance = createHazelcastInstance();
- this.implicitlyCreated = true;
- }
- return this.hazelcastInstance;
- }
-
- /**
- * Initializes this instance by {@link #ensureHazelcastInstance()
ensuring} there is a backing
- * {@link HazelcastInstance}.
- *
- * @throws ShiroException
- * @see #ensureHazelcastInstance()
- * @see HazelcastInstance
- */
- public void init() throws ShiroException {
- ensureHazelcastInstance();
- }
-
- /**
- * Implicitly creates and returns a new {@link HazelcastInstance} that
will be used to back this implementation.
- * This implementation calls:
- * <pre>
- * return Hazelcast.newHazelcastInstance(this.config);
- * </pre>
- * using any {@link #setConfig(com.hazelcast.config.Config) configured}
{@code Config} object. If no config
- * object has been specified, {@code this.config} will be {@code null},
thereby using Hazelcast's
- * <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">default
configuration mechanism</a>.
- * <p/>
- * Can be overridden by subclasses for custom creation behavior.
- *
- * @return a new {@link HazelcastInstance} that will be used to back this
implementation
- * @see Hazelcast#newHazelcastInstance(com.hazelcast.config.Config)
- * @see Config
- */
- protected HazelcastInstance createHazelcastInstance() {
- return Hazelcast.newHazelcastInstance(this.config);
- }
-
- //needed for unit tests only - not part of Shiro's public API
-
- /**
- * NOT PART OF SHIRO'S ACCESSIBLE API. DO NOT DEPEND ON THIS. This
method was added for testing purposes only.
- * <p/>
- * Returns {@code true} if this {@code HazelcastCacheManager} instance
implicitly created the backing
- * {@code HazelcastInstance}, or {@code false} if one was externally
provided via
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
setHazelcastInstance}.
- *
- * @return {@code true} if this {@code HazelcastCacheManager} instance
implicitly created the backing
- * {@code HazelcastInstance}, or {@code false} if one was externally
provided via
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
setHazelcastInstance}.
- */
- protected final boolean isImplicitlyCreated() {
- return this.implicitlyCreated;
- }
-
- /**
- * Destroys any {@link #ensureHazelcastInstance() implicitly created}
backing {@code HazelcastInstance}. If the
- * backing Hazelcast was not implicitly created (i.e. because it was
configured externally and supplied via
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
setHazelcastInstance}), this method does
- * nothing.
- *
- * @throws Exception if there is a problem shutting down
- */
- public void destroy() throws Exception {
- if (this.implicitlyCreated) {
- try {
- this.hazelcastInstance.getLifecycleService().shutdown();
- } catch (Throwable t) {
- if (LOGGER.isWarnEnabled()) {
- LOGGER.warn("Unable to cleanly shutdown implicitly created
HazelcastInstance. "
- + "Ignoring (shutting down)...", t);
- }
- } finally {
- this.hazelcastInstance = null;
- this.implicitlyCreated = false;
- }
- }
- }
-
- /**
- * Returns the {@code HazelcastInstance} from which named {@link
java.util.concurrent.ConcurrentMap ConcurrentMap}
- * instances will be acquired to create {@link MapCache} instances.
- *
- * @return the {@code HazelcastInstance} from which named {@link
java.util.concurrent.ConcurrentMap ConcurrentMap}
- * instances will be acquired to create {@link MapCache} instances.
- */
- public HazelcastInstance getHazelcastInstance() {
- return hazelcastInstance;
- }
-
- /**
- * Sets the {@code HazelcastInstance} from which named {@link
java.util.concurrent.ConcurrentMap ConcurrentMap}
- * instances will be acquired to create {@link MapCache} instances.
- *
- * @param hazelcastInstance the {@code HazelcastInstance} from which named
- * {@link java.util.concurrent.ConcurrentMap
ConcurrentMap} instances will be acquired to create
- * {@link MapCache} instances.
- */
- public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
- this.hazelcastInstance = hazelcastInstance;
- }
-
- /**
- * Returns the Hazelcast {@code Config} object to use to create a backing
{@code HazelcastInstance} if one is not
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
supplied}, or {@code null} if the
- * default <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">Hazelcast
configuration
- * mechanisms</a> will be used.
- *
- * @return the Hazelcast {@code Config} object to use to create a backing
{@code HazelcastInstance} if one is not
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
supplied}, or {@code null} if the
- * default <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">Hazelcast
configuration
- * mechanisms</a> will be used.
- * @see Hazelcast#newHazelcastInstance(com.hazelcast.config.Config)
- */
- public Config getConfig() {
- return config;
- }
-
- /**
- * Sets the Hazelcast {@code Config} object to use to create a backing
{@code HazelcastInstance} if one is not
- * {@link #setHazelcastInstance(com.hazelcast.core.HazelcastInstance)
supplied}. {@code null} can be set if the
- * default <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">Hazelcast
configuration
- * mechanisms</a> will be used.
- *
- * @param config the Hazelcast {@code Config} object to use to create a
backing {@code HazelcastInstance} if one is not
- * {@link
#setHazelcastInstance(com.hazelcast.core.HazelcastInstance) supplied}, or
{@code null} if the
- * default <a
href="http://www.hazelcast.com/docs/2.5/manual/multi_html/ch12.html">Hazelcast
configuration
- * mechanisms</a> will be used.
- */
- public void setConfig(Config config) {
- this.config = config;
- }
-
-}
diff --git
a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/package-info.java
b/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/package-info.java
deleted file mode 100644
index 572a05688..000000000
---
a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-/**
- * <a href="http://ehcache.sourceforge.net" target="_top">Ehcache</a>-based
implementations of Shiro's
- * cache interfaces.
- */
-package org.apache.shiro.hazelcast.cache;
diff --git a/support/hazelcast/src/main/resources/META-INF/NOTICE
b/support/hazelcast/src/main/resources/META-INF/NOTICE
deleted file mode 100644
index bdc909e8c..000000000
--- a/support/hazelcast/src/main/resources/META-INF/NOTICE
+++ /dev/null
@@ -1,15 +0,0 @@
-Apache Shiro
-Copyright 2008-2020 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
-The implementation for org.apache.shiro.util.SoftHashMap is based
-on initial ideas from Dr. Heinz Kabutz's publicly posted version
-available at http://www.javaspecialists.eu/archive/Issue015.html,
-with continued modifications.
-
-Certain parts (StringUtils, IpAddressMatcher, etc.) of the source
-code for this product was copied for simplicity and to reduce
-dependencies from the source code developed by the Spring Framework
-Project (http://www.springframework.org).
diff --git
a/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
b/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
deleted file mode 100644
index a35eb0d3c..000000000
---
a/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.apache.shiro.hazelcast.cache
-
-import com.hazelcast.config.Config
-import com.hazelcast.core.HazelcastInstance
-import com.hazelcast.core.LifecycleService
-import org.junit.jupiter.api.BeforeAll
-import org.junit.jupiter.api.Test
-
-import static org.junit.jupiter.api.Assertions.assertFalse
-import static org.junit.jupiter.api.Assertions.assertNull
-import static org.junit.jupiter.api.Assertions.assertNotNull
-import static org.junit.jupiter.api.Assertions.assertSame
-import static org.junit.jupiter.api.Assertions.assertTrue
-import static org.mockito.Mockito.*
-
-/**
- * Unit tests for {@link HazelcastCacheManager}.
- *
- * @since 1.3
- */
-class HazelcastCacheManagerTest {
-
- @BeforeAll
- static void setUpLogging() {
- System.setProperty("hazelcast.logging.type", "log4j2")
- }
-
- @Test
- void testGetSetHazelcastInstance() {
-
- // given
- HazelcastInstance hc = mock(HazelcastInstance)
- def manager = new HazelcastCacheManager();
-
- // when
- manager.hazelcastInstance = hc
-
- // then
- assertSame hc, manager.hazelcastInstance
- }
-
- @Test
- void testCustomConfig() {
-
- // given
- Config config = mock(Config)
- def manager = new HazelcastCacheManager();
-
- // when
- manager.config = config
-
- // then
- assertSame config, manager.config
- }
-
- @Test
- void testImplicitlyCreated() {
-
- // given
- HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
-
- HazelcastCacheManager manager = spy(HazelcastCacheManager);
- when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)
-
- // when
- manager.init()
-
- // then
- assertTrue manager.implicitlyCreated
- manager.destroy()
- }
-
- @Test
- void testDestroy() {
-
- // given
- LifecycleService lifecycleService = mock(LifecycleService)
-
- HazelcastInstance hazelcastInstance = spy(HazelcastInstance)
- when(hazelcastInstance.getLifecycleService()).then(args ->
lifecycleService)
-
- HazelcastCacheManager manager = spy(HazelcastCacheManager);
- when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)
-
-
- // when
- manager.init()
- manager.destroy()
-
- // then
- assertFalse manager.implicitlyCreated
- assertNull manager.hazelcastInstance
- verify(hazelcastInstance).getLifecycleService()
- verify(manager).createHazelcastInstance()
- }
-
- @Test
- void testDestroyExplicit() {
-
- // given
- HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
- HazelcastCacheManager manager = new HazelcastCacheManager()
- manager.hazelcastInstance = hazelcastInstance
-
- // when
- manager.init()
- manager.destroy()
-
- // then
- assertNotNull manager.hazelcastInstance
- assertFalse manager.implicitlyCreated
- }
-
- @Test
- void testUncleanShutdown() {
-
- // given
- LifecycleService lifecycleService = mock(LifecycleService)
- when(lifecycleService.shutdown()).thenThrow(new
IllegalStateException())
-
- HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
- when(hazelcastInstance.getLifecycleService()).then(args ->
lifecycleService)
-
- HazelcastCacheManager manager = spy(HazelcastCacheManager);
- when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)
-
- // when
- manager.init()
- manager.destroy()
-
- // then
- assertFalse manager.implicitlyCreated
- verify(lifecycleService).shutdown()
- verify(hazelcastInstance).getLifecycleService()
- verify(manager).createHazelcastInstance()
- }
-
-}
diff --git a/support/hazelcast/src/test/resources/log4j2-test.xml
b/support/hazelcast/src/test/resources/log4j2-test.xml
deleted file mode 100644
index 455736eb4..000000000
--- a/support/hazelcast/src/test/resources/log4j2-test.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-
-<Configuration name="ConfigTest" status="ERROR" monitorInterval="5">
- <!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you 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.
- -->
-
- <Appenders>
- <Console name="Console" target="SYSTEM_OUT">
- <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36}
- %msg%n"/>
- </Console>
- </Appenders>
- <Loggers>
- <Logger name="com.hazelcast" level="warn" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.apache" level="warn" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.apache.shiro" level="info" additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Logger name="org.apache.shiro.util.ThreadContext" level="warn"
additivity="false">
- <AppenderRef ref="Console"/>
- </Logger>
- <Root level="error">
- <AppenderRef ref="Console"/>
- </Root>
- </Loggers>
-</Configuration>
diff --git a/support/pom.xml b/support/pom.xml
index 6295045fc..e6b71e950 100644
--- a/support/pom.xml
+++ b/support/pom.xml
@@ -34,8 +34,6 @@
<modules>
<module>aspectj</module>
<module>jcache</module>
- <module>ehcache</module>
- <module>hazelcast</module>
<module>quartz</module>
<module>guice</module>
<module>servlet-plugin</module>