From 57557212447257b83c13122c5ae93e028d5e3e19 Mon Sep 17 00:00:00 2001
From: lprimak
Date: Tue, 19 Dec 2023 22:52:52 -0600
Subject: [PATCH] enh: cleaned up all compiler warnings
---
.../shiro/cache/AbstractCacheManager.java | 15 ++++---
.../cache/MemoryConstrainedCacheManager.java | 4 +-
.../config/ogdl/CommonsInterpolator.java | 7 ++-
.../shiro/config/ogdl/ReflectionBuilder.java | 12 ++---
core/pom.xml | 4 ++
.../credential/HashedCredentialsMatcher.java | 11 ++---
.../credential/Sha256CredentialsMatcher.java | 1 +
.../credential/Sha384CredentialsMatcher.java | 1 +
.../credential/Sha512CredentialsMatcher.java | 1 +
.../apache/shiro/env/BasicIniEnvironment.java | 4 ++
.../apache/shiro/jndi/JndiObjectFactory.java | 1 +
.../shiro/realm/AuthenticatingRealm.java | 2 +-
.../shiro/realm/ldap/JndiLdapRealm.java | 1 +
.../mgt/eis/EnterpriseCacheSessionDAO.java | 4 +-
.../apache/shiro/util/CollectionUtils.java | 2 +
.../apache/shiro/util/OsgiDependencies.java | 30 +++++++++++++
.../AbstractHashedCredentialsMatcherTest.java | 4 +-
.../HashedCredentialsMatcherTest.java | 1 +
.../Sha256CredentialsMatcherTest.java | 5 ++-
.../Sha384CredentialsMatcherTest.java | 5 ++-
.../Sha512CredentialsMatcherTest.java | 5 ++-
.../shiro/config/HashMapCacheManager.java | 4 +-
.../shiro/realm/jdbc/JDBCRealmTest.java | 6 +--
.../shiro/realm/ldap/JndiLdapRealmTest.java | 1 +
.../shiro/subject/DelegatingSubjectTest.java | 10 ++---
.../test/ExampleShiroIntegrationTest.java | 8 ++--
.../apache/shiro/crypto/hash/SimpleHash.java | 14 +++---
.../hash/format/ProvidedHashFormat.java | 2 +
crypto/support/hashes/argon2/pom.xml | 11 +++++
.../hashes/argon2/OsgiDependencies.java | 30 +++++++++++++
crypto/support/hashes/bcrypt/pom.xml | 11 +++++
.../hashes/bcrypt/OsgiDependencies.java | 30 +++++++++++++
.../guice/SampleShiroServletModule.java | 1 +
integration-tests/guice4/pom.xml | 4 ++
integration-tests/jakarta-ee/pom.xml | 44 +++++++++++++------
.../testing/web/AbstractContainerIT.java | 5 +--
lang/pom.xml | 5 +++
.../apache/shiro/lang/io/XmlSerializer.java | 1 +
.../org/apache/shiro/lang/util/Assert.java | 2 +-
.../apache/shiro/lang/util/ClassUtils.java | 31 +++++++------
.../shiro/lang/util/JspEngineDependency.java | 31 +++++++++++++
.../apache/shiro/lang/util/SoftHashMap.java | 2 +
.../apache/shiro/lang/util/StringUtils.java | 1 +
.../aspectj/bank/SecureBankServiceTest.java | 14 +++---
.../quickstart/src/main/java/Quickstart.java | 6 +--
.../samples/sprhib/dao/HibernateUserDAO.java | 4 +-
.../shiro/samples/sprhib/model/Role.java | 7 +--
.../shiro/samples/sprhib/model/User.java | 8 ++--
.../samples/sprhib/security/SampleRealm.java | 1 +
.../sprhib/web/CurrentUserInterceptor.java | 4 +-
.../spring/config/RemotingServletConfig.java | 1 +
samples/web/pom.xml | 2 +-
support/aspectj/pom.xml | 5 +++
.../shiro/aspectj/DummyServiceTest.java | 9 ++--
.../apache/shiro/cache/ehcache/EhCache.java | 2 +-
support/guice/pom.xml | 1 +
.../shiro/guice/web/ShiroWebModule.java | 9 +++-
.../shiro/guice/BeanTypeListenerTest.java | 3 ++
.../guice/LifecycleTypeListenerTest.java | 3 ++
.../web/AbstractInjectionProviderTest.java | 1 +
.../shiro/guice/web/DefaultFiltersTest.java | 1 +
.../web/FilterChainResolverProviderTest.java | 4 +-
.../web/PathMatchingFilterProviderTest.java | 1 +
.../shiro/guice/web/ShiroWebModuleTest.java | 4 ++
.../web/SimpleFilterChainResolverTest.java | 1 +
support/jcache/pom.xml | 2 +-
.../org/apache/shiro/tools/hasher/Hasher.java | 7 ++-
.../config/IniFilterChainResolverFactory.java | 1 +
.../shiro/web/env/IniWebEnvironment.java | 10 ++++-
.../filter/mgt/DefaultFilterChainManager.java | 4 +-
.../web/servlet/AbstractShiroFilter.java | 11 ++---
.../web/servlet/ShiroHttpServletRequest.java | 1 +
.../web/servlet/ShiroHttpServletResponse.java | 3 +-
.../shiro/web/servlet/ShiroHttpSession.java | 24 +++++-----
.../WebIniSecurityManagerFactoryTest.java | 2 +
.../filter/mgt/SimpleNamedFilterListTest.java | 5 +--
.../mgt/DefaultWebSecurityManagerTest.java | 4 ++
77 files changed, 384 insertions(+), 155 deletions(-)
create mode 100644 core/src/main/java/org/apache/shiro/util/OsgiDependencies.java
create mode 100644 crypto/support/hashes/argon2/src/main/java/org/apache/shiro/crypto/support/hashes/argon2/OsgiDependencies.java
create mode 100644 crypto/support/hashes/bcrypt/src/main/java/org/apache/shiro/crypto/support/hashes/bcrypt/OsgiDependencies.java
create mode 100644 lang/src/main/java/org/apache/shiro/lang/util/JspEngineDependency.java
diff --git a/cache/src/main/java/org/apache/shiro/cache/AbstractCacheManager.java b/cache/src/main/java/org/apache/shiro/cache/AbstractCacheManager.java
index 3c2d6b3667..62550c2587 100644
--- a/cache/src/main/java/org/apache/shiro/cache/AbstractCacheManager.java
+++ b/cache/src/main/java/org/apache/shiro/cache/AbstractCacheManager.java
@@ -38,13 +38,13 @@ public abstract class AbstractCacheManager implements CacheManager, Destroyable
/**
* Retains all Cache objects maintained by this cache manager.
*/
- private final ConcurrentMap caches;
+ private final ConcurrentMap> caches;
/**
* Default no-arg constructor that instantiates an internal name-to-cache {@code ConcurrentMap}.
*/
public AbstractCacheManager() {
- this.caches = new ConcurrentHashMap();
+ this.caches = new ConcurrentHashMap<>();
}
/**
@@ -56,17 +56,18 @@ public AbstractCacheManager() {
* @throws IllegalArgumentException if the {@code name} argument is {@code null} or does not contain text.
* @throws CacheException if there is a problem lazily creating a {@code Cache} instance.
*/
+ @SuppressWarnings("unchecked")
public Cache getCache(String name) throws IllegalArgumentException, CacheException {
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Cache name cannot be null or empty.");
}
- Cache cache;
+ Cache cache;
- cache = caches.get(name);
+ cache = (Cache) caches.get(name);
if (cache == null) {
cache = createCache(name);
- Cache existing = caches.putIfAbsent(name, cache);
+ Cache existing = (Cache) caches.putIfAbsent(name, cache);
if (existing != null) {
cache = existing;
}
@@ -83,7 +84,7 @@ public Cache getCache(String name) throws IllegalArgumentException,
* @return a new {@code Cache} instance associated with the specified {@code name}.
* @throws CacheException if the {@code Cache} instance cannot be created.
*/
- protected abstract Cache createCache(String name) throws CacheException;
+ protected abstract Cache createCache(String name) throws CacheException;
/**
* Cleanup method that first {@link LifecycleUtils#destroy destroys} all of it's managed caches and then
@@ -101,7 +102,7 @@ public void destroy() throws Exception {
}
public String toString() {
- Collection values = caches.values();
+ Collection> values = caches.values();
StringBuilder sb = new StringBuilder(getClass().getSimpleName())
.append(" with ")
.append(caches.size())
diff --git a/cache/src/main/java/org/apache/shiro/cache/MemoryConstrainedCacheManager.java b/cache/src/main/java/org/apache/shiro/cache/MemoryConstrainedCacheManager.java
index f9f683e20a..017403b91d 100644
--- a/cache/src/main/java/org/apache/shiro/cache/MemoryConstrainedCacheManager.java
+++ b/cache/src/main/java/org/apache/shiro/cache/MemoryConstrainedCacheManager.java
@@ -42,7 +42,7 @@ public class MemoryConstrainedCacheManager extends AbstractCacheManager {
* @return a new {@link MapCache MapCache} instance backed by a {@link SoftHashMap}.
*/
@Override
- protected Cache createCache(String name) {
- return new MapCache
*/
@Entity
-@Table(name = "users")
+@Table(name = "users", indexes = {
+ @Index(name = "idx_users_username", columnList = "username"),
+ @Index(name = "idx_users_email", columnList = "email")})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User {
@@ -71,7 +73,6 @@ public void setId(Long id) {
*/
@Basic(optional = false)
@Column(length = 100)
- @Index(name = "idx_users_username")
public String getUsername() {
return username;
}
@@ -81,7 +82,6 @@ public void setUsername(String username) {
}
@Basic(optional = false)
- @Index(name = "idx_users_email")
public String getEmail() {
return email;
}
diff --git a/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/security/SampleRealm.java b/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/security/SampleRealm.java
index 51860c0d8d..08b3be4053 100644
--- a/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/security/SampleRealm.java
+++ b/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/security/SampleRealm.java
@@ -49,6 +49,7 @@ public class SampleRealm extends AuthorizingRealm {
protected UserDAO userDAO;
+ @SuppressWarnings("deprecation")
public SampleRealm() {
//This name must match the name in the User class's getPrincipals() method
setName("SampleRealm");
diff --git a/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/web/CurrentUserInterceptor.java b/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/web/CurrentUserInterceptor.java
index 7c3c024430..0cd64e1f10 100644
--- a/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/web/CurrentUserInterceptor.java
+++ b/samples/spring-hibernate/src/main/java/org/apache/shiro/samples/sprhib/web/CurrentUserInterceptor.java
@@ -22,8 +22,8 @@
import org.apache.shiro.samples.sprhib.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -34,7 +34,7 @@
* cached in the Hibernate second-level cache.
*/
@Component
-public class CurrentUserInterceptor extends HandlerInterceptorAdapter {
+public class CurrentUserInterceptor implements HandlerInterceptor {
private UserService userService;
diff --git a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java b/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java
index 9d79bca98d..403f0761b1 100644
--- a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java
+++ b/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java
@@ -33,6 +33,7 @@
public class RemotingServletConfig {
@Bean(name = "/sampleManager")
+ @SuppressWarnings("deprecation")
public HttpInvokerServiceExporter accountServiceExporter(SampleManager sampleManager,
SecureRemoteInvocationExecutor secureRemoteInvocationExecutor) {
diff --git a/samples/web/pom.xml b/samples/web/pom.xml
index 6d66ec0ef6..135ef4ac78 100644
--- a/samples/web/pom.xml
+++ b/samples/web/pom.xml
@@ -110,7 +110,7 @@
org.slf4j
- slf4j-log4j12
+ slf4j-reload4j
${slf4j.version}
runtime
diff --git a/support/aspectj/pom.xml b/support/aspectj/pom.xml
index 9f52698f6e..1f87b9227e 100644
--- a/support/aspectj/pom.xml
+++ b/support/aspectj/pom.xml
@@ -69,6 +69,11 @@
org.codehaus.mojo
aspectj-maven-plugin
+
+
+ -Xlint:adviceDidNotMatch=ignore
+
+
aspectj-compile
diff --git a/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java b/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java
index 06b544bb75..b4d5bb0a54 100644
--- a/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java
+++ b/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java
@@ -22,10 +22,8 @@
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
-import org.apache.shiro.ini.IniSecurityManagerFactory;
-import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.env.BasicIniEnvironment;
import org.apache.shiro.subject.Subject;
-import org.apache.shiro.lang.util.Factory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -47,9 +45,8 @@ public class DummyServiceTest {
@BeforeAll
public static void setUpClass() throws Exception {
- Factory factory = new IniSecurityManagerFactory("classpath:shiroDummyServiceTest.ini");
- SecurityManager securityManager = factory.getInstance();
- SecurityUtils.setSecurityManager(securityManager);
+ var basicIniEnvironment = new BasicIniEnvironment("classpath:shiroDummyServiceTest.ini");
+ SecurityUtils.setSecurityManager(basicIniEnvironment.getSecurityManager());
securedService = new SecuredDummyService();
restrictedService = new RestrictedDummyService();
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
index 86b2de3985..b2f34e1923 100644
--- 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
@@ -69,6 +69,7 @@ public EhCache(net.sf.ehcache.Ehcache cache) {
* @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
*/
+ @SuppressWarnings("unchecked")
public V get(K key) throws CacheException {
try {
if (LOGGER.isTraceEnabled()) {
@@ -84,7 +85,6 @@ public V get(K key) throws CacheException {
}
return null;
} else {
- //noinspection unchecked
return (V) element.getObjectValue();
}
}
diff --git a/support/guice/pom.xml b/support/guice/pom.xml
index 36e2406c2a..bd3358bd11 100644
--- a/support/guice/pom.xml
+++ b/support/guice/pom.xml
@@ -34,6 +34,7 @@
guice
true
+ none()
diff --git a/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java b/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
index e1790ed6ed..c867f38c8a 100644
--- a/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
+++ b/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
@@ -129,6 +129,7 @@ public List> globalFilters() {
}
@Override
+ @SuppressWarnings("unchecked")
protected final void configureShiro() {
bindBeanType(TypeLiteral.get(ServletContext.class), Key.get(ServletContext.class, Names.named(NAME)));
bind(Key.get(ServletContext.class, Names.named(NAME))).toInstance(this.servletContext);
@@ -148,6 +149,7 @@ protected final void configureShiro() {
bind(FilterChainResolver.class).toProvider(new FilterChainResolverProvider(setupFilterChainConfigs()));
}
+ @SuppressWarnings("unchecked")
private Map[]> setupFilterChainConfigs() {
// loop through and build a map of Filter Key -> Map
@@ -271,6 +273,7 @@ protected void bindWebEnvironment(AnnotatedBindingBuilder super WebEnvironment
bind.to(WebGuiceEnvironment.class).asEagerSingleton();
}
+ @SuppressWarnings("unchecked")
protected final void addFilterChain(String pattern, Key extends Filter> key) {
// check for legacy API
if (key instanceof FilterConfigKey) {
@@ -290,6 +293,7 @@ protected final void addFilterChain(String pattern, Key extends Filter> key) {
* and config to be used when processing resources on pattern
.
* @since 1.4
*/
+ @SafeVarargs
protected final void addFilterChain(String pattern, FilterConfig extends Filter>... filterConfigs) {
filterChains.put(pattern, filterConfigs);
}
@@ -383,9 +387,9 @@ static boolean isGuiceVersion3() {
}
}
+ @SuppressWarnings("unchecked")
private void addLegacyFilterChain(String pattern, FilterConfigKey filterConfigKey) {
-
- FilterConfig filterConfig = new FilterConfig(filterConfigKey.getKey(), filterConfigKey.getConfigValue());
+ FilterConfig filterConfig = new FilterConfig<>(filterConfigKey.getKey(), filterConfigKey.getConfigValue());
addFilterChain(pattern, filterConfig);
}
@@ -399,6 +403,7 @@ private void addLegacyFilterChain(String pattern, FilterConfigKey filterConfigKe
* @param keys
*/
@Deprecated
+ @SuppressWarnings("unchecked")
protected final void addFilterChain(String pattern, Key extends Filter>... keys) {
// We need to extract the keys and FilterConfigKey and convert to the new format.
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/BeanTypeListenerTest.java b/support/guice/src/test/java/org/apache/shiro/guice/BeanTypeListenerTest.java
index 00f615fae2..09b2a84e76 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/BeanTypeListenerTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/BeanTypeListenerTest.java
@@ -73,8 +73,10 @@ void testMatchedPackage() throws Exception {
@Test
void testPropertySetting() throws Exception {
+ @SuppressWarnings("unchecked")
TypeEncounter encounter = mock(TypeEncounter.class);
+ @SuppressWarnings("unchecked")
Provider injectorProvider = mock(Provider.class);
Injector injector = mock(Injector.class);
@@ -82,6 +84,7 @@ void testPropertySetting() throws Exception {
when(injectorProvider.get()).then(args -> injector);
+ @SuppressWarnings("unchecked")
ArgumentCaptor> captor = ArgumentCaptor.forClass(MembersInjector.class);
SecurityManager securityManager = mock(SecurityManager.class);
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/LifecycleTypeListenerTest.java b/support/guice/src/test/java/org/apache/shiro/guice/LifecycleTypeListenerTest.java
index 76ea107fa1..e145f03c6c 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/LifecycleTypeListenerTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/LifecycleTypeListenerTest.java
@@ -33,6 +33,7 @@
public class LifecycleTypeListenerTest {
@Test
+ @SuppressWarnings({"unchecked", "rawtypes"})
void testHearInitializable() throws Exception {
TypeEncounter encounter = createMock(TypeEncounter.class);
@@ -48,7 +49,9 @@ void testHearInitializable() throws Exception {
}
@Test
+ @SuppressWarnings("unchecked")
void testHearDestroyable() throws Exception {
+ @SuppressWarnings("rawtypes")
TypeEncounter encounter = createMock(TypeEncounter.class);
encounter.register(anyObject(DestroyableInjectionListener.class));
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/AbstractInjectionProviderTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/AbstractInjectionProviderTest.java
index d1fb4edbd1..77b4abf166 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/AbstractInjectionProviderTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/AbstractInjectionProviderTest.java
@@ -49,6 +49,7 @@ public class AbstractInjectionProviderTest {
static Key keyF1 = Key.get(Object.class, Names.named("field1"));
@Test
+ @SuppressWarnings("unchecked")
void testGet() throws Exception {
Injector mockInjector = createMock(Injector.class);
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/DefaultFiltersTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/DefaultFiltersTest.java
index 613c651671..453e13ffab 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/DefaultFiltersTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/DefaultFiltersTest.java
@@ -36,6 +36,7 @@ void checkDefaultFilters() throws Exception {
EnumSet defaultFilters = EnumSet.allOf(DefaultFilter.class);
for (Field field : ShiroWebModule.class.getFields()) {
if (Modifier.isStatic(field.getModifiers()) && Key.class.isAssignableFrom(field.getType())) {
+ @SuppressWarnings("unchecked")
Class extends Filter> filterType = ((Key) field.get(null)).getTypeLiteral().getRawType();
boolean found = false;
for (DefaultFilter filter : defaultFilters) {
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/FilterChainResolverProviderTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/FilterChainResolverProviderTest.java
index 203876a7f2..889adb24a5 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/FilterChainResolverProviderTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/FilterChainResolverProviderTest.java
@@ -51,8 +51,9 @@ public class FilterChainResolverProviderTest {
private FilterChainResolverProvider underTest;
@BeforeEach
+ @SuppressWarnings("unchecked")
public void setup() {
- chains = new LinkedHashMap[]>();
+ chains = new LinkedHashMap<>();
key1a = Key.get(Filter.class, Names.named("key1a"));
key1b = Key.get(Filter.class, Names.named("key1b"));
@@ -66,6 +67,7 @@ public void setup() {
}
@Test
+ @SuppressWarnings("unchecked")
void testGetDependencies() throws Exception {
Set> dependencySet = underTest.getDependencies();
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/PathMatchingFilterProviderTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/PathMatchingFilterProviderTest.java
index 2620cbf40d..09f1929008 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/PathMatchingFilterProviderTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/PathMatchingFilterProviderTest.java
@@ -32,6 +32,7 @@
public class PathMatchingFilterProviderTest {
@Test
+ @SuppressWarnings("unchecked")
void testPostProcess() {
PathMatchingFilter filter = createMock(PathMatchingFilter.class);
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
index 452d37b458..1c0416896d 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
@@ -45,6 +45,7 @@
import org.apache.shiro.web.session.mgt.ServletContainerSessionManager;
import org.easymock.EasyMock;
import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import javax.inject.Named;
@@ -270,6 +271,7 @@ public ShiroModuleTest.MockRealm createRealm() {
* @since 1.4
*/
@Test
+ @Tag("Guice3")
void testAddFilterChainGuice3Only() {
Assumptions.assumeTrue(ShiroWebModule.isGuiceVersion3(), "This test only runs against Guice 3.x");
@@ -290,6 +292,8 @@ void testAddFilterChainGuice3Only() {
Injector injector = Guice.createInjector(new ShiroWebModule(servletContext) {
@Override
+ @SuppressWarnings("unchecked")
+ @Deprecated
protected void configureShiroWeb() {
bindRealm().to(ShiroModuleTest.MockRealm.class);
expose(FilterChainResolver.class);
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/SimpleFilterChainResolverTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/SimpleFilterChainResolverTest.java
index 7a9f9a5a87..ea00352684 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/SimpleFilterChainResolverTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/SimpleFilterChainResolverTest.java
@@ -49,6 +49,7 @@
public class SimpleFilterChainResolverTest {
@Test
+ @SuppressWarnings("unchecked")
void testGetChain() throws Exception {
// test that it uses the pattern matcher - check
// test that the FIRST chain found is the one that gets returned - check
diff --git a/support/jcache/pom.xml b/support/jcache/pom.xml
index bdfdb28990..4266492374 100644
--- a/support/jcache/pom.xml
+++ b/support/jcache/pom.xml
@@ -74,7 +74,7 @@
org.apache.shiro.jcache
- org.apache.shiro.jcache*;version=${project.version}
+ org.apache.shiro.cache.jcache*;version=${project.version}
org.apache.shiro*;version="${shiro.osgi.importRange}",
javax.cache*;version="${jcache.osgi.importRange}",
diff --git a/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java b/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java
index f9bdb58809..83ae0926e1 100644
--- a/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java
+++ b/tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java
@@ -266,7 +266,7 @@ public static void main(String[] args) {
if (password) {
formatString = Shiro2CryptFormat.class.getName();
} else {
- formatString = HexFormat.class.getName();
+ formatString = getHexFormatString();
}
}
@@ -297,6 +297,11 @@ public static void main(String[] args) {
}
}
+ @SuppressWarnings("deprecation")
+ private static String getHexFormatString() {
+ return HexFormat.class.getName();
+ }
+
private static String createMutexMessage(Option... options) {
StringBuilder sb = new StringBuilder();
sb.append("The ");
diff --git a/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java b/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
index d452e30ac9..07dfbbad6a 100644
--- a/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
+++ b/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
@@ -43,6 +43,7 @@
*
* @since 1.0
*/
+@SuppressWarnings("deprecation")
public class IniFilterChainResolverFactory extends IniFactorySupport {
/**
diff --git a/web/src/main/java/org/apache/shiro/web/env/IniWebEnvironment.java b/web/src/main/java/org/apache/shiro/web/env/IniWebEnvironment.java
index da02f19980..a98fe05f44 100644
--- a/web/src/main/java/org/apache/shiro/web/env/IniWebEnvironment.java
+++ b/web/src/main/java/org/apache/shiro/web/env/IniWebEnvironment.java
@@ -70,8 +70,10 @@ public class IniWebEnvironment extends ResourceBasedWebEnvironment implements In
*/
private Ini ini;
+ @SuppressWarnings("deprecation")
private WebIniSecurityManagerFactory factory;
+ @SuppressWarnings("deprecation")
public IniWebEnvironment() {
factory = new WebIniSecurityManagerFactory();
}
@@ -278,6 +280,7 @@ protected ShiroFilterConfiguration createFilterConfiguration() {
return (ShiroFilterConfiguration) this.objects.get(SHIRO_FILTER_CONFIG_NAME);
}
+ @SuppressWarnings("deprecation")
protected FilterChainResolver createFilterChainResolver() {
FilterChainResolver resolver = null;
@@ -285,9 +288,10 @@ protected FilterChainResolver createFilterChainResolver() {
Ini ini = getIni();
if (!CollectionUtils.isEmpty(ini)) {
+ @SuppressWarnings("unchecked")
Factory factory = (Factory) this.objects.get(FILTER_CHAIN_RESOLVER_NAME);
if (factory instanceof IniFactorySupport) {
- IniFactorySupport iniFactory = (IniFactorySupport) factory;
+ var iniFactory = (IniFactorySupport>) factory;
iniFactory.setIni(ini);
iniFactory.setDefaults(this.objects);
}
@@ -326,6 +330,7 @@ protected WebSecurityManager createWebSecurityManager() {
*
* @return an array with two elements, {@code /WEB-INF/shiro.ini} and {@code classpath:shiro.ini}.
*/
+ @SuppressWarnings("deprecation")
protected String[] getDefaultConfigLocations() {
return new String[] {
DEFAULT_WEB_INI_RESOURCE_PATH,
@@ -429,7 +434,7 @@ protected Map getDefaults() {
* @return the SecurityManager factory used by this WebEnvironment.
* @since 1.4
*/
- @SuppressWarnings("unused")
+ @SuppressWarnings({"unused", "deprecation"})
protected WebIniSecurityManagerFactory getSecurityManagerFactory() {
return factory;
}
@@ -440,6 +445,7 @@ protected WebIniSecurityManagerFactory getSecurityManagerFactory() {
* @param factory the SecurityManager factory to used.
* @since 1.4
*/
+ @SuppressWarnings("deprecation")
protected void setSecurityManagerFactory(WebIniSecurityManagerFactory factory) {
this.factory = factory;
}
diff --git a/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java b/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
index 087d580366..59893db959 100644
--- a/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
+++ b/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
@@ -31,7 +31,6 @@
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -359,8 +358,7 @@ public boolean hasChains() {
}
public Set getChainNames() {
- //noinspection unchecked
- return this.filterChains != null ? this.filterChains.keySet() : Collections.EMPTY_SET;
+ return this.filterChains != null ? this.filterChains.keySet() : Set.of();
}
public FilterChain proxy(FilterChain original, String chainName) {
diff --git a/web/src/main/java/org/apache/shiro/web/servlet/AbstractShiroFilter.java b/web/src/main/java/org/apache/shiro/web/servlet/AbstractShiroFilter.java
index eb7fbf9b77..0b1304347c 100644
--- a/web/src/main/java/org/apache/shiro/web/servlet/AbstractShiroFilter.java
+++ b/web/src/main/java/org/apache/shiro/web/servlet/AbstractShiroFilter.java
@@ -373,13 +373,10 @@ protected void doFilterInternal(ServletRequest servletRequest, ServletResponse s
final Subject subject = createSubject(request, response);
- //noinspection unchecked
- subject.execute(new Callable() {
- public Object call() throws Exception {
- updateSessionLastAccessTime(request, response);
- executeChain(request, response, chain);
- return null;
- }
+ subject.execute((Callable) () -> {
+ updateSessionLastAccessTime(request, response);
+ executeChain(request, response, chain);
+ return null;
});
} catch (ExecutionException ex) {
t = ex.getCause();
diff --git a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletRequest.java b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletRequest.java
index 72c4a9974c..664014f576 100644
--- a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletRequest.java
+++ b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletRequest.java
@@ -222,6 +222,7 @@ public boolean isRequestedSessionIdFromURL() {
}
}
+ @Deprecated
public boolean isRequestedSessionIdFromUrl() {
return isRequestedSessionIdFromURL();
}
diff --git a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletResponse.java b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletResponse.java
index 22899471c2..9b16b51a72 100644
--- a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletResponse.java
+++ b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletResponse.java
@@ -91,7 +91,7 @@ public String encodeRedirectURL(String url) {
}
}
-
+ @Deprecated
public String encodeRedirectUrl(String s) {
return encodeRedirectURL(s);
}
@@ -116,6 +116,7 @@ public String encodeURL(String url) {
}
}
+ @Deprecated
public String encodeUrl(String s) {
return encodeURL(s);
}
diff --git a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpSession.java b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpSession.java
index 871cdb1cba..3223eb4b0b 100644
--- a/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpSession.java
+++ b/web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpSession.java
@@ -28,7 +28,6 @@
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import java.util.Collection;
-import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
@@ -50,12 +49,12 @@ public class ShiroHttpSession implements HttpSession {
*/
public static final String DEFAULT_SESSION_ID_NAME = "JSESSIONID";
- private static final Enumeration EMPTY_ENUMERATION = new Enumeration() {
+ private static final Enumeration EMPTY_ENUMERATION = new Enumeration<>() {
public boolean hasMoreElements() {
return false;
}
- public Object nextElement() {
+ public String nextElement() {
return null;
}
};
@@ -67,7 +66,7 @@ public HttpSession getSession(String s) {
return null;
}
- public Enumeration getIds() {
+ public Enumeration getIds() {
return EMPTY_ENUMERATION;
}
};
@@ -141,11 +140,12 @@ public Object getAttribute(String s) {
}
}
+ @Deprecated
+ @Override
public Object getValue(String s) {
return getAttribute(s);
}
- @SuppressWarnings({"unchecked"})
protected Set getKeyNames() {
Collection keySet;
try {
@@ -160,25 +160,27 @@ protected Set getKeyNames() {
keyNames.add(o.toString());
}
} else {
- keyNames = Collections.EMPTY_SET;
+ keyNames = Set.of();
}
return keyNames;
}
- public Enumeration getAttributeNames() {
+ @Override
+ public Enumeration getAttributeNames() {
Set keyNames = getKeyNames();
- final Iterator iterator = keyNames.iterator();
- return new Enumeration() {
+ final Iterator iterator = keyNames.iterator();
+ return new Enumeration<>() {
public boolean hasMoreElements() {
return iterator.hasNext();
}
- public Object nextElement() {
+ public String nextElement() {
return iterator.next();
}
};
}
+ @Deprecated
public String[] getValueNames() {
Set keyNames = getKeyNames();
String[] array = new String[keyNames.size()];
@@ -219,6 +221,7 @@ public void setAttribute(String s, Object o) {
}
}
+ @Deprecated
public void putValue(String s, Object o) {
setAttribute(s, o);
}
@@ -232,6 +235,7 @@ public void removeAttribute(String s) {
}
}
+ @Deprecated
public void removeValue(String s) {
removeAttribute(s);
}
diff --git a/web/src/test/java/org/apache/shiro/web/config/WebIniSecurityManagerFactoryTest.java b/web/src/test/java/org/apache/shiro/web/config/WebIniSecurityManagerFactoryTest.java
index a1071fe16f..ed99d9d1b6 100644
--- a/web/src/test/java/org/apache/shiro/web/config/WebIniSecurityManagerFactoryTest.java
+++ b/web/src/test/java/org/apache/shiro/web/config/WebIniSecurityManagerFactoryTest.java
@@ -47,9 +47,11 @@ void testDefaultFiltersPresent() {
Ini ini = new Ini();
//just a normal configuration line in the MAIN section for any of the default filters should work
//out of the box. So, create the main section and just config one of them:
+ @SuppressWarnings("deprecation")
Ini.Section section = ini.addSection(IniSecurityManagerFactory.MAIN_SECTION_NAME);
section.put("authc.loginUrl", "/login.jsp");
+ @SuppressWarnings("deprecation")
WebIniSecurityManagerFactory factory = new WebIniSecurityManagerFactory(ini);
org.apache.shiro.mgt.SecurityManager sm = factory.getInstance();
assertNotNull(sm);
diff --git a/web/src/test/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterListTest.java b/web/src/test/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterListTest.java
index 2eb965a8b1..1b187f3630 100644
--- a/web/src/test/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterListTest.java
+++ b/web/src/test/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterListTest.java
@@ -160,9 +160,6 @@ void testListMethods() {
assertEquals(3, list.size());
list.retainAll(multipleFilters);
assertEquals(2, list.size());
- //noinspection unchecked
- assertEquals(new ArrayList(list), multipleFilters);
+ assertEquals(new ArrayList<>(list), multipleFilters);
}
-
-
}
diff --git a/web/src/test/java/org/apache/shiro/web/mgt/DefaultWebSecurityManagerTest.java b/web/src/test/java/org/apache/shiro/web/mgt/DefaultWebSecurityManagerTest.java
index 1c351dedee..ac1196b239 100644
--- a/web/src/test/java/org/apache/shiro/web/mgt/DefaultWebSecurityManagerTest.java
+++ b/web/src/test/java/org/apache/shiro/web/mgt/DefaultWebSecurityManagerTest.java
@@ -61,6 +61,7 @@ public class DefaultWebSecurityManagerTest extends AbstractWebSecurityManagerTes
private DefaultWebSecurityManager sm;
@BeforeEach
+ @SuppressWarnings("deprecation")
public void setup() {
sm = new DefaultWebSecurityManager();
sm.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
@@ -82,6 +83,7 @@ protected Subject newSubject(ServletRequest request, ServletResponse response) {
}
@Test
+ @SuppressWarnings("deprecation")
void checkSessionManagerDeterminesContainerSessionMode() {
sm.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
WebSessionManager sessionManager = mock(WebSessionManager.class);
@@ -96,6 +98,7 @@ void checkSessionManagerDeterminesContainerSessionMode() {
}
@Test
+ @SuppressWarnings("deprecation")
void shiroSessionModeInit() {
sm.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
}
@@ -211,6 +214,7 @@ void testBuildNonWebSubjectWithDefaultServletContainerSessionManager() {
Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME);
section.put("user1", "user1");
+ @SuppressWarnings("deprecation")
WebIniSecurityManagerFactory factory = new WebIniSecurityManagerFactory(ini);
WebSecurityManager securityManager = (WebSecurityManager) factory.getInstance();