diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 23521d8c45..a9522e842b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -58,6 +58,9 @@ updates: - dependency-name: "org.omnifaces:omnifaces" update-types: [ "version-update:semver-major" ] + - dependency-name: "org.aspectj:*" + update-types: [ "version-update:semver-patch" ] + - dependency-name: "org.springframework*:*" update-types: [ "version-update:semver-major" ] - dependency-name: "com.flowlogix:flowlogix-jee" @@ -69,6 +72,8 @@ updates: update-types: [ "version-update:semver-major" ] - dependency-name: "org.apache.johnzon:*" update-types: [ "version-update:semver-major" ] + - dependency-name: "com.hazelcast:*" + update-types: [ "version-update:semver-minor" ] # Dependencies for Maven - on 1.13.x - package-ecosystem: 'maven' @@ -109,6 +114,8 @@ updates: update-types: [ "version-update:semver-major" ] - dependency-name: "com.github.mjeanroy:junit-servers-jetty" update-types: [ "version-update:semver-minor" ] + - dependency-name: "com.hazelcast:*" + update-types: [ "version-update:semver-minor" ] # Dependencies for GitHub Actions - package-ecosystem: 'github-actions' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d6586a72ab..7e67f369c2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -60,10 +60,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Cache local Maven repository - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2 + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 #v4.0.2 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} @@ -71,7 +71,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4 + uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -85,7 +85,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4 + uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -98,6 +98,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4 + uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c8af8c7881..025a9777de 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -33,10 +33,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Set up JDK - uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: 11 distribution: temurin @@ -55,7 +55,7 @@ jobs: strategy: matrix: os: [ 'ubuntu-latest', 'windows-latest', 'macOS-latest' ] - jdk: [ 11, 17, 21 ] + jdk: [ 11, 17, 21, 22 ] dist: [ 'temurin', 'adopt-openj9', 'zulu' ] exclude: # was already built @@ -71,16 +71,19 @@ jobs: # no OpenJ9 21 - dist: adopt-openj9 jdk: 21 + # no OpenJ9 22 + - dist: adopt-openj9 + jdk: 22 fail-fast: false runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Set up JDK - uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.dist }} @@ -98,7 +101,7 @@ jobs: -Pskip_jakarta_ee_tests - name: Archive test run logs - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 if: always() with: name: test-logs-${{ matrix.os }}-${{ matrix.jdk }}-${{ matrix.dist }} diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index a3b4b09968..3e93d77195 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -42,12 +42,12 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3.0.0 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v3.0.0 with: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 #tag=2.3.1 + uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 #tag=2.3.3 with: results_file: results.sarif results_format: sarif @@ -66,7 +66,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # tag=v4.0.0 + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # tag=v4.3.3 with: name: SARIF file path: results.sarif @@ -74,6 +74,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a #tag=v2 + uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 #tag=v2 with: sarif_file: results.sarif diff --git a/.gitignore b/.gitignore index 6536a976a9..7c235f21dd 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ release.properties pom.xml.* - .sdkmanrc +.DS_Store diff --git a/.jenkins.groovy b/.jenkins.groovy index ff84288606..b1cecf1ddc 100644 --- a/.jenkins.groovy +++ b/.jenkins.groovy @@ -36,7 +36,7 @@ pipeline { axis { // https://cwiki.apache.org/confluence/display/INFRA/JDK+Installation+Matrix name 'MATRIX_JDK' - values 'jdk_11_latest', 'jdk_17_latest', 'jdk_21_latest' + values 'jdk_11_latest', 'jdk_17_latest', 'jdk_21_latest', 'jdk_22_latest' } // Additional axes, like OS and maven version can be configured here. } diff --git a/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/CommonsInterpolatorTest.groovy b/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/CommonsInterpolatorTest.groovy index 780bcc0eae..fe2683c835 100644 --- a/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/CommonsInterpolatorTest.groovy +++ b/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/CommonsInterpolatorTest.groovy @@ -20,6 +20,7 @@ package org.apache.shiro.config.ogdl import org.apache.shiro.config.ogdl.CommonsInterpolator import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertNull @@ -28,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNull * Tests for {@link org.apache.shiro.config.ogdl.CommonsInterpolator}. * @since 1.4 */ +@Isolated("System property usage") class CommonsInterpolatorTest { @SuppressWarnings("unused") diff --git a/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/ReflectionBuilderTest.groovy b/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/ReflectionBuilderTest.groovy index 86af2eea35..63c6589633 100644 --- a/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/ReflectionBuilderTest.groovy +++ b/config/ogdl/src/test/groovy/org/apache/shiro/config/ogdl/ReflectionBuilderTest.groovy @@ -26,6 +26,7 @@ import org.apache.shiro.config.ConfigurationException import org.apache.shiro.config.Ini import org.apache.shiro.config.ogdl.event.BeanEvent import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import java.util.concurrent.ConcurrentHashMap @@ -36,6 +37,7 @@ import static org.hamcrest.Matchers.* /** * Unit tests for the {@link org.apache.shiro.config.ogdl.ReflectionBuilder} implementation. */ +@Isolated @SuppressWarnings("GrMethodMayBeStatic") class ReflectionBuilderTest { diff --git a/core/pom.xml b/core/pom.xml index 8930983363..12ec84c05e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -36,6 +36,18 @@ + + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.apache.maven.plugins @@ -146,6 +158,7 @@ org.apache.commons commons-configuration2 + true @@ -168,6 +181,19 @@ log4j-core-test test + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + + + org.projectlombok + lombok + ${lombok.version} + provided + true + diff --git a/core/src/main/java/org/apache/shiro/SecurityUtils.java b/core/src/main/java/org/apache/shiro/SecurityUtils.java index 71ee87a5db..04b4c146e3 100644 --- a/core/src/main/java/org/apache/shiro/SecurityUtils.java +++ b/core/src/main/java/org/apache/shiro/SecurityUtils.java @@ -19,8 +19,11 @@ package org.apache.shiro; import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.mgt.WrappedSecurityManager; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ThreadContext; +import java.util.Objects; +import java.util.function.Predicate; /** @@ -123,4 +126,66 @@ public static SecurityManager getSecurityManager() throws UnavailableSecurityMan } return securityManager; } + + /** + * Returns the SecurityManager, ensuring it is of the specified type. + * Unwraps wrapped SecurityManagers if necessary. + * Caution, since this method unwraps SecurityManagers, it is possible that + * functionality of the wrapper is lost by the returned instance. + * + * @param type the expected type of the SecurityManager + * @return the SecurityManager. + * @param the expected type of the SecurityManager + */ + public static SM getSecurityManager(Class type) { + Objects.requireNonNull(type, "Class argument cannot be null."); + return unwrapSecurityManager(getSecurityManager(), type); + } + + /** + * Determines if the specified security manager is of the specified type or a subclass of the specified type. + * + * @param securityManager + * @param type + * @return true if the security manager is of the specified type or a subclass of the specified type, false otherwise. + */ + public static boolean isSecurityManagerTypeOf(SecurityManager securityManager, + Class type) { + return type.isAssignableFrom(unwrapSecurityManager(securityManager, type).getClass()); + } + + /** + * Unwraps wrapped SecurityManagers if necessary. + * @param securityManager the SecurityManager to unwrap + * @param type the expected type of the SecurityManager + * @return the unwrapped SecurityManager + * @param Type of the SecurityManager + */ + public static SM + unwrapSecurityManager(SecurityManager securityManager, Class type) { + return unwrapSecurityManager(securityManager, type, type::isAssignableFrom); + } + + /** + * Unwraps wrapped SecurityManagers if necessary. + * @param securityManager the SecurityManager to unwrap + * @param type the expected type of the SecurityManager + * @param predicate to determine if the SecurityManager is of the expected type + * @return the unwrapped SecurityManager + * @param Type of the SecurityManager + */ + @SuppressWarnings("unchecked") + public static SM + unwrapSecurityManager(SecurityManager securityManager, Class type, + Predicate> predicate) { + while (securityManager instanceof WrappedSecurityManager && !predicate.test(securityManager.getClass())) { + WrappedSecurityManager wrappedSecurityManager = (WrappedSecurityManager) securityManager; + securityManager = wrappedSecurityManager.unwrap(); + if (securityManager == wrappedSecurityManager) { + throw new IllegalStateException("SecurityManager implementation of type [" + type.getName() + + "] is wrapped by itself, which is an invalid configuration."); + } + } + return (SM) securityManager; + } } diff --git a/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java b/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java index 9912f6ab14..4739971942 100644 --- a/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java +++ b/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java @@ -355,7 +355,9 @@ public Subject createSubject(SubjectContext subjectContext) { //(this is needed here in case rememberMe principals were resolved and they need to be stored in the //session, so we don't constantly rehydrate the rememberMe PrincipalCollection on every operation). //Added in 1.2: - save(subject); + if (context.isSessionCreationEnabled()) { + save(subject); + } return subject; } diff --git a/core/src/main/java/org/apache/shiro/mgt/WrappedSecurityManager.java b/core/src/main/java/org/apache/shiro/mgt/WrappedSecurityManager.java new file mode 100644 index 0000000000..2ac4546847 --- /dev/null +++ b/core/src/main/java/org/apache/shiro/mgt/WrappedSecurityManager.java @@ -0,0 +1,32 @@ +/* + * 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.mgt; + +/** + * Interface implemented by {@link SecurityManager} implementations that wrap another {@code SecurityManager} instance. + */ +public interface WrappedSecurityManager { + /** + * Returns the underlying {@code SecurityManager} instance that this instance wraps. + * + * @return instance + * @param {@link SecurityManager} implementation type + */ + SM unwrap(); +} diff --git a/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy b/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy index 38ad06d78f..8e74f74bd2 100644 --- a/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy +++ b/core/src/test/groovy/org/apache/shiro/authc/credential/DefaultPasswordServiceTest.groovy @@ -29,6 +29,7 @@ import org.apache.shiro.crypto.hash.format.Shiro1CryptFormat import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.function.Executable +import org.junit.jupiter.api.parallel.Isolated import static org.easymock.EasyMock.* import static org.junit.jupiter.api.Assertions.* @@ -38,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.* * * @since 1.2 */ +@Isolated class DefaultPasswordServiceTest { @Test diff --git a/core/src/test/java/org/apache/shiro/SecurityUtilsUnwrapTest.java b/core/src/test/java/org/apache/shiro/SecurityUtilsUnwrapTest.java new file mode 100644 index 0000000000..fb8aa0f0af --- /dev/null +++ b/core/src/test/java/org/apache/shiro/SecurityUtilsUnwrapTest.java @@ -0,0 +1,151 @@ +/* + * 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; + +import lombok.RequiredArgsConstructor; +import lombok.experimental.Delegate; +import org.apache.shiro.mgt.DefaultSecurityManager; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.mgt.SessionsSecurityManager; +import org.apache.shiro.mgt.WrappedSecurityManager; +import org.apache.shiro.subject.Subject; +import org.apache.shiro.subject.SubjectContext; +import org.apache.shiro.util.ThreadContext; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.apache.shiro.SecurityUtils.getSecurityManager; +import static org.apache.shiro.SecurityUtils.isSecurityManagerTypeOf; +import static org.apache.shiro.SecurityUtils.unwrapSecurityManager; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class SecurityUtilsUnwrapTest { + @Mock + SecurityManager securityManager; + @Mock + DefaultSecurityManager defaultSecurityManager; + @Mock + Subject subject; + @Mock + SubjectContext subjectContext; + + @RequiredArgsConstructor + static class Wrapped implements WrappedSecurityManager, SecurityManager { + private final @Delegate SecurityManager securityManager; + + @Override + @SuppressWarnings("unchecked") + public SM unwrap() { + return (SM) securityManager; + } + } + + @RequiredArgsConstructor + static class InvalidWrapped implements WrappedSecurityManager, SecurityManager { + private final @Delegate SecurityManager securityManager; + + @Override + @SuppressWarnings("unchecked") + public SM unwrap() { + return (SM) this; + } + } + + @Test + void basicUnwrap() { + SecurityManager sm = unwrapSecurityManager(securityManager, SecurityManager.class); + assertEquals(securityManager, sm); + } + + @Test + void basicTypeCheck() { + assertTrue(isSecurityManagerTypeOf(securityManager, SecurityManager.class)); + } + + @Test + void securityManager() { + try (var threadContext = mockStatic(ThreadContext.class)) { + threadContext.when(ThreadContext::getSecurityManager).thenReturn(defaultSecurityManager); + DefaultSecurityManager dsm = getSecurityManager(DefaultSecurityManager.class); + assertEquals(defaultSecurityManager, dsm); + } + } + + @Test + void failedTypeUnwrap() { + assertThrows(ClassCastException.class, () -> { + SessionsSecurityManager ssm = unwrapSecurityManager(securityManager, SessionsSecurityManager.class); + }); + } + + @Test + void defaultSecurityManager() { + var dsm = unwrapSecurityManager(defaultSecurityManager, DefaultSecurityManager.class); + assertEquals(defaultSecurityManager, dsm); + when(defaultSecurityManager.createSubject(subjectContext)).thenReturn(subject); + Subject subject = dsm.createSubject(subjectContext); + assertEquals(this.subject, subject); + verify(defaultSecurityManager).createSubject(subjectContext); + verifyNoMoreInteractions(defaultSecurityManager, this.subject, subjectContext); + } + + @Test + void invalidCast() { + SecurityManager wrapped = new Wrapped(defaultSecurityManager); + assertThrows(ClassCastException.class, () -> { + DefaultSecurityManager sm = (DefaultSecurityManager) wrapped; + }); + } + + @Test + void unwrapOne() { + SecurityManager wrapped = new Wrapped(defaultSecurityManager); + assertEquals(defaultSecurityManager, unwrapSecurityManager(wrapped, DefaultSecurityManager.class)); + } + + @Test + void unwrapTwo() { + SecurityManager wrapped = new Wrapped(new Wrapped(defaultSecurityManager)); + assertEquals(defaultSecurityManager, unwrapSecurityManager(wrapped, DefaultSecurityManager.class)); + } + + @Test + void invalidWrap() { + SecurityManager wrapped = new Wrapped(new InvalidWrapped(defaultSecurityManager)); + assertThrows(IllegalStateException.class, () -> { + assertEquals(defaultSecurityManager, unwrapSecurityManager(wrapped, DefaultSecurityManager.class)); + }); + } + + @Test + void invalidWrapInverted() { + SecurityManager wrapped = new InvalidWrapped(new Wrapped(defaultSecurityManager)); + assertThrows(IllegalStateException.class, () -> { + assertEquals(defaultSecurityManager, unwrapSecurityManager(wrapped, DefaultSecurityManager.class)); + }); + } +} diff --git a/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java b/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java index c03b5a608f..072d0e52cd 100644 --- a/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java +++ b/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; import java.net.URI; @@ -40,6 +41,7 @@ /** * @since 0.1 */ +@Isolated public class AbstractAuthenticatorTest { static ListAppender listAppender; diff --git a/core/src/test/java/org/apache/shiro/authz/permission/DomainPermissionTest.java b/core/src/test/java/org/apache/shiro/authz/permission/DomainPermissionTest.java index b5faee8205..4e474c9c17 100644 --- a/core/src/test/java/org/apache/shiro/authz/permission/DomainPermissionTest.java +++ b/core/src/test/java/org/apache/shiro/authz/permission/DomainPermissionTest.java @@ -25,7 +25,6 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -44,7 +43,7 @@ void testDefaultConstructor() { p = new DomainPermission(); // Verify domain - assertTrue("domain".equals(p.getDomain())); + assertEquals("domain", p.getDomain()); // Verify actions set = p.getActions(); diff --git a/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java b/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java index 0f31f35f86..345cd8c3b5 100644 --- a/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java +++ b/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java @@ -20,7 +20,6 @@ import org.apache.shiro.subject.support.SubjectRunnable; import org.apache.shiro.test.SecurityManagerTestSupport; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -33,6 +32,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Test cases for the {@link SubjectAwareExecutorService} implementation. */ @@ -52,7 +53,7 @@ public void testSubmitRunnable() { executor.submit(testRunnable); SubjectRunnable subjectRunnable = captor.getValue(); - Assertions.assertNotNull(subjectRunnable); + assertNotNull(subjectRunnable); }); } diff --git a/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java b/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java index dc26793035..ee2f5832cc 100644 --- a/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java +++ b/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java @@ -27,15 +27,19 @@ import org.apache.shiro.session.ExpiredSessionException; import org.apache.shiro.session.Session; import org.apache.shiro.session.mgt.AbstractValidatingSessionManager; +import org.apache.shiro.subject.SimplePrincipalCollection; import org.apache.shiro.subject.Subject; +import org.apache.shiro.subject.SubjectContext; import org.apache.shiro.subject.support.DelegatingSubject; import org.apache.shiro.util.ThreadContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import java.io.Serializable; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -46,6 +50,7 @@ /** * @since 0.2 */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class DefaultSecurityManagerTest extends AbstractSecurityManagerTest { DefaultSecurityManager sm; @@ -80,7 +85,7 @@ void testDefaultConfig() { Session session = subject.getSession(); session.setAttribute("key", "value"); - assertEquals(session.getAttribute("key"), "value"); + assertEquals("value", session.getAttribute("key")); subject.logout(); @@ -137,7 +142,7 @@ void testSubjectReuseAfterLogout() { Serializable firstSessionId = session.getId(); session.setAttribute("key", "value"); - assertEquals(session.getAttribute("key"), "value"); + assertEquals("value", session.getAttribute("key")); subject.logout(); @@ -187,4 +192,33 @@ void testNewSubjectWithoutThreadSecurityManager() { subject.login(token); assertEquals(sm, subject.getSecurityManager()); } + + @Test + void testNewSubjectWithoutSessionCreationEnabled() { + SimplePrincipalCollection principals = new SimplePrincipalCollection("guest", "asd"); + // this tests that calling `buildSubject` doesn't throw an exception due to session-creation being disabled + Subject subject = new Subject.Builder().principals(principals).sessionCreationEnabled(false).buildSubject(); + + assertEquals(subject.getPrincipal(), "guest"); + } + + @Test + void testNewSubjectWithSubjectFactoryThatDisablesSessionCreation() { + ((DefaultSecurityManager) SecurityUtils.getSecurityManager()) + .setSubjectFactory(new SessionCreationDisabledSubjectFactory()); + + SimplePrincipalCollection principals = new SimplePrincipalCollection("guest", "asd"); + // this tests that calling `buildSubject` doesn't throw an exception due to session-creation being disabled + Subject subject = new Subject.Builder().principals(principals).buildSubject(); + + assertEquals(subject.getPrincipal(), "guest"); + } + + private static final class SessionCreationDisabledSubjectFactory extends DefaultSubjectFactory { + @Override + public Subject createSubject(SubjectContext context) { + context.setSessionCreationEnabled(false); + return super.createSubject(context); + } + } } diff --git a/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java b/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java index 3e46b60c47..081ce7867f 100644 --- a/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java +++ b/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java @@ -28,13 +28,17 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** * @since May 8, 2008 12:26:23 AM */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class VMSingletonDefaultSecurityManagerTest { @BeforeEach @@ -62,12 +66,12 @@ void testVMSingleton() { AuthenticationToken token = new UsernamePasswordToken("guest", "guest"); subject.login(token); subject.getSession().setAttribute("key", "value"); - assertTrue(subject.getSession().getAttribute("key").equals("value")); + assertEquals("value", subject.getSession().getAttribute("key")); subject = SecurityUtils.getSubject(); assertTrue(subject.isAuthenticated()); - assertTrue(subject.getSession().getAttribute("key").equals("value")); + assertEquals("value", subject.getSession().getAttribute("key")); } finally { sm.destroy(); //SHIRO-270: diff --git a/core/src/test/java/org/apache/shiro/realm/AuthorizingRealmTest.java b/core/src/test/java/org/apache/shiro/realm/AuthorizingRealmTest.java index 3f6d4f9cfb..c1cd5f8cf7 100644 --- a/core/src/test/java/org/apache/shiro/realm/AuthorizingRealmTest.java +++ b/core/src/test/java/org/apache/shiro/realm/AuthorizingRealmTest.java @@ -254,7 +254,7 @@ public Collection resolvePermissionsInRole(String roleString) { authorizationInfo.addStringPermission("\t"); authorizationInfo.addStringPermission(null); Collection permissions = realm.getPermissions(authorizationInfo); - assertEquals(permissions.size(), 4); + assertEquals(4, permissions.size()); } private void assertArrayEquals(boolean[] expected, boolean[] actual) { diff --git a/core/src/test/java/org/apache/shiro/realm/activedirectory/ActiveDirectoryRealmTest.java b/core/src/test/java/org/apache/shiro/realm/activedirectory/ActiveDirectoryRealmTest.java index f480160cbf..92fdd9f054 100644 --- a/core/src/test/java/org/apache/shiro/realm/activedirectory/ActiveDirectoryRealmTest.java +++ b/core/src/test/java/org/apache/shiro/realm/activedirectory/ActiveDirectoryRealmTest.java @@ -41,9 +41,9 @@ import org.easymock.Capture; import org.easymock.CaptureType; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -53,6 +53,7 @@ import java.util.HashSet; import java.util.Set; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.anyString; import static org.easymock.EasyMock.capture; @@ -63,7 +64,10 @@ import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.is; + +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Simple test case for ActiveDirectoryRealm. @@ -73,6 +77,7 @@ * This version was intended to mimic my current usage scenario in an effort to debug upgrade issues which were not related * to LDAP connectivity. */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class ActiveDirectoryRealmTest { private static final String USERNAME = "testuser"; @@ -108,10 +113,10 @@ void testDefaultConfig() { UsernamePrincipal usernamePrincipal = subject.getPrincipals().oneByType(UsernamePrincipal.class); - assertTrue(usernamePrincipal.getUsername().equals(USERNAME)); + assertEquals(USERNAME, usernamePrincipal.getUsername()); UserIdPrincipal userIdPrincipal = subject.getPrincipals().oneByType(UserIdPrincipal.class); - assertTrue(userIdPrincipal.getUserId() == USER_ID); + assertEquals(USER_ID, userIdPrincipal.getUserId()); assertTrue(realm.hasRole(subject.getPrincipals(), ROLE)); @@ -148,7 +153,7 @@ public void assertExistingUserSuffix(String username, String expectedPrincipalNa try { activeDirectoryRealm.getRoleNamesForUser(username, ldapContext); } catch (NamingException e) { - Assertions.fail("Unexpected NamingException thrown during test"); + fail("Unexpected NamingException thrown during test"); } }); diff --git a/core/src/test/java/org/apache/shiro/realm/jdbc/JDBCRealmTest.java b/core/src/test/java/org/apache/shiro/realm/jdbc/JDBCRealmTest.java index 58e9d31d9f..505cf273ab 100644 --- a/core/src/test/java/org/apache/shiro/realm/jdbc/JDBCRealmTest.java +++ b/core/src/test/java/org/apache/shiro/realm/jdbc/JDBCRealmTest.java @@ -36,8 +36,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.parallel.ResourceLock; import javax.sql.DataSource; @@ -48,10 +48,16 @@ import java.util.HashMap; import java.util.Optional; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * Test case for JDBCRealm. */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class JDBCRealmTest { protected DefaultSecurityManager securityManager; @@ -259,7 +265,7 @@ void testRolePresent() throws Exception { Subject currentUser = builder.buildSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword); currentUser.login(token); - Assertions.assertTrue(currentUser.hasRole(testRole)); + assertTrue(currentUser.hasRole(testRole)); } @Test @@ -273,7 +279,7 @@ void testRoleNotPresent() throws Exception { Subject currentUser = builder.buildSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword); currentUser.login(token); - Assertions.assertFalse(currentUser.hasRole("Game Overall Director")); + assertFalse(currentUser.hasRole("Game Overall Director")); } @Test @@ -288,7 +294,7 @@ void testPermissionPresent() throws Exception { Subject currentUser = builder.buildSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword); currentUser.login(token); - Assertions.assertTrue(currentUser.isPermitted(testPermissionString)); + assertTrue(currentUser.isPermitted(testPermissionString)); } @Test @@ -303,7 +309,7 @@ void testPermissionNotPresent() throws Exception { Subject currentUser = builder.buildSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword); currentUser.login(token); - Assertions.assertFalse(currentUser.isPermitted("testDomain:testTarget:specialAction")); + assertFalse(currentUser.isPermitted("testDomain:testTarget:specialAction")); } /** @@ -357,7 +363,7 @@ protected void createDefaultSchema(String testName, boolean salted) { String password = sha256Hash.toHex(); sql.executeUpdate("insert into users values ('" + username + "', '" + password + "')"); } catch (SQLException ex) { - Assertions.fail("Exception creating test database"); + fail("Exception creating test database"); } finally { JdbcUtils.closeStatement(sql); JdbcUtils.closeConnection(conn); @@ -393,7 +399,7 @@ protected void createSaltColumnSchema(String testName, boolean base64EncodeSalt) "insert into users values ('" + username + "', '" + password + "', '" + maybeBase64EncodedSalt + "')"); } catch (SQLException ex) { - Assertions.fail("Exception creating test database"); + fail("Exception creating test database"); } finally { JdbcUtils.closeStatement(sql); JdbcUtils.closeConnection(conn); @@ -418,7 +424,7 @@ protected void createRolesAndPermissions(DataSource ds) { sql.executeUpdate( "insert into roles_permissions values ('" + testRole + "', '" + testPermissionString + "')"); } catch (SQLException ex) { - Assertions.fail("Exception adding test role and permission"); + fail("Exception adding test role and permission"); } finally { JdbcUtils.closeStatement(sql); JdbcUtils.closeConnection(conn); diff --git a/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java b/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java index cc8628db27..6d159cc79f 100644 --- a/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java +++ b/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java @@ -30,6 +30,7 @@ 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.UUID; @@ -48,6 +49,7 @@ /** * Unit test for the {@link DefaultSessionManager DefaultSessionManager} implementation. */ +@Isolated public class DefaultSessionManagerTest { DefaultSessionManager sm; diff --git a/core/src/test/java/org/apache/shiro/session/mgt/DelegatingSessionTest.java b/core/src/test/java/org/apache/shiro/session/mgt/DelegatingSessionTest.java index 334972835a..f336a85d69 100644 --- a/core/src/test/java/org/apache/shiro/session/mgt/DelegatingSessionTest.java +++ b/core/src/test/java/org/apache/shiro/session/mgt/DelegatingSessionTest.java @@ -23,6 +23,7 @@ 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.io.Serializable; @@ -32,6 +33,7 @@ /** * Unit test for the {@link DelegatingSession} class. */ +@Isolated public class DelegatingSessionTest { DelegatingSession session; @@ -62,7 +64,7 @@ public void sleep(long millis) { @Test void testTimeout() { Serializable origId = session.getId(); - assertEquals(session.getTimeout(), AbstractSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT); + assertEquals(AbstractSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT, session.getTimeout()); session.touch(); session.setTimeout(100); assertEquals(100, session.getTimeout()); diff --git a/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java b/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java index 98c482a930..bb2d4b3c49 100644 --- a/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java +++ b/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java @@ -20,10 +20,12 @@ import org.apache.shiro.session.Session; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + @SuppressWarnings("checkstyle:MagicNumber") public class ExecutorServiceSessionValidationSchedulerTest { @@ -47,8 +49,8 @@ void timeoutSessionValidate() throws InterruptedException { session.setTimeout(2000L); defaultSessionManager.create(session); Thread.sleep(5000L); - Assertions.assertTrue(defaultSessionManager.getActiveSessions().isEmpty()); - Assertions.assertTrue(executorServiceSessionValidationScheduler.isEnabled()); + assertTrue(defaultSessionManager.getActiveSessions().isEmpty()); + assertTrue(executorServiceSessionValidationScheduler.isEnabled()); } @Test @@ -59,19 +61,19 @@ void stopSessionValidate() throws InterruptedException { Thread.sleep(1000L); session.stop(); Thread.sleep(3000L); - Assertions.assertTrue(defaultSessionManager.getActiveSessions().isEmpty()); - Assertions.assertTrue(executorServiceSessionValidationScheduler.isEnabled()); + assertTrue(defaultSessionManager.getActiveSessions().isEmpty()); + assertTrue(executorServiceSessionValidationScheduler.isEnabled()); } @Test void enableSessionValidation() throws InterruptedException { - Assertions.assertTrue(executorServiceSessionValidationScheduler.isEnabled()); + assertTrue(executorServiceSessionValidationScheduler.isEnabled()); executorServiceSessionValidationScheduler.disableSessionValidation(); Thread.sleep(2000L); - Assertions.assertFalse(executorServiceSessionValidationScheduler.isEnabled()); + assertFalse(executorServiceSessionValidationScheduler.isEnabled()); executorServiceSessionValidationScheduler.enableSessionValidation(); Thread.sleep(2000L); - Assertions.assertTrue(executorServiceSessionValidationScheduler.isEnabled()); + assertTrue(executorServiceSessionValidationScheduler.isEnabled()); } @Test @@ -88,8 +90,8 @@ void threadException() throws InterruptedException { Thread.sleep(2000L); session.stop(); Thread.sleep(2000L); - Assertions.assertFalse(defaultSessionManager.getActiveSessions().isEmpty()); - Assertions.assertTrue(executorServiceSessionValidationScheduler.isEnabled()); + assertFalse(defaultSessionManager.getActiveSessions().isEmpty()); + assertTrue(executorServiceSessionValidationScheduler.isEnabled()); } @AfterEach diff --git a/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java b/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java index 6dc41fca64..c9dfcc6ce2 100644 --- a/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java +++ b/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java @@ -39,6 +39,7 @@ import static org.easymock.EasyMock.createNiceMock; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -68,7 +69,7 @@ void testSessionStopThenStart() { Session session = subject.getSession(); session.setAttribute(key, value); - assertTrue(session.getAttribute(key).equals(value)); + assertEquals(session.getAttribute(key), value); Serializable firstSessionId = session.getId(); assertNotNull(firstSessionId); @@ -79,7 +80,7 @@ void testSessionStopThenStart() { assertNull(session.getAttribute(key)); Serializable secondSessionId = session.getId(); assertNotNull(secondSessionId); - assertFalse(firstSessionId.equals(secondSessionId)); + assertNotEquals(firstSessionId, secondSessionId); subject.logout(); @@ -175,7 +176,7 @@ void testRunAs() { //assert we still have the previous (user1) principals: PrincipalCollection previous = subject.getPreviousPrincipals(); assertFalse(previous == null || previous.isEmpty()); - assertTrue(previous.getPrimaryPrincipal().equals("user1")); + assertEquals("user1", previous.getPrimaryPrincipal()); //test the stack functionality: While as user2, run as user3: subject.runAs(new SimplePrincipalCollection("user3", INI_REALM_NAME)); @@ -188,7 +189,7 @@ void testRunAs() { //assert we still have the previous (user2) principals in the stack: previous = subject.getPreviousPrincipals(); assertFalse(previous == null || previous.isEmpty()); - assertTrue(previous.getPrimaryPrincipal().equals("user2")); + assertEquals("user2", previous.getPrimaryPrincipal()); //drop down to user2: subject.releaseRunAs(); @@ -203,7 +204,7 @@ void testRunAs() { //assert we still have the previous (user1) principals: previous = subject.getPreviousPrincipals(); assertFalse(previous == null || previous.isEmpty()); - assertTrue(previous.getPrimaryPrincipal().equals("user1")); + assertEquals("user1", previous.getPrimaryPrincipal()); //drop down to original user1: subject.releaseRunAs(); diff --git a/core/src/test/java/org/apache/shiro/test/AbstractShiroTest.java b/core/src/test/java/org/apache/shiro/test/AbstractShiroTest.java index 2e6e66ad3f..400eb236f2 100644 --- a/core/src/test/java/org/apache/shiro/test/AbstractShiroTest.java +++ b/core/src/test/java/org/apache/shiro/test/AbstractShiroTest.java @@ -33,6 +33,10 @@ * @since 1.2 */ public abstract class AbstractShiroTest { + /** + * The resource name of the global SecurityManager instance used in the test environment + */ + public static final String GLOBAL_SECURITY_MANAGER_RESOURCE = "globalSecurityManager"; private static ThreadState subjectThreadState; diff --git a/core/src/test/java/org/apache/shiro/test/ExampleShiroIntegrationTest.java b/core/src/test/java/org/apache/shiro/test/ExampleShiroIntegrationTest.java index 0559a6703f..9159046cfd 100644 --- a/core/src/test/java/org/apache/shiro/test/ExampleShiroIntegrationTest.java +++ b/core/src/test/java/org/apache/shiro/test/ExampleShiroIntegrationTest.java @@ -23,12 +23,15 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; /** * Simple example test class to be used to show how one might write Shiro-compatible unit tests. * * @since 1.2 */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class ExampleShiroIntegrationTest extends AbstractShiroTest { @BeforeAll diff --git a/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java b/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java index 806431f3ad..9cdb0cadb6 100644 --- a/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java +++ b/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java @@ -21,7 +21,9 @@ import org.apache.shiro.subject.Subject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.ResourceLock; +import static org.apache.shiro.test.AbstractShiroTest.GLOBAL_SECURITY_MANAGER_RESOURCE; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.expect; @@ -30,6 +32,7 @@ * * @since 1.2 */ +@ResourceLock(GLOBAL_SECURITY_MANAGER_RESOURCE) public class ExampleShiroUnitTest extends AbstractShiroTest { @Test diff --git a/core/src/test/java/org/apache/shiro/util/AntPathMatcherTests.java b/core/src/test/java/org/apache/shiro/util/AntPathMatcherTests.java index c01154d61f..b065a89cbd 100644 --- a/core/src/test/java/org/apache/shiro/util/AntPathMatcherTests.java +++ b/core/src/test/java/org/apache/shiro/util/AntPathMatcherTests.java @@ -283,27 +283,27 @@ void uniqueDelimiter() { @Test void extractPathWithinPattern() throws Exception { - assertEquals(pathMatcher.extractPathWithinPattern("/docs/commit.html", "/docs/commit.html"), ""); - - assertEquals(pathMatcher.extractPathWithinPattern("/docs/*", "/docs/cvs/commit"), "cvs/commit"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/cvs/*.html", "/docs/cvs/commit.html"), "commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/**", "/docs/cvs/commit"), "cvs/commit"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/**/*.html", "/docs/cvs/commit.html"), "cvs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/**/*.html", "/docs/commit.html"), "commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/*.html", "/commit.html"), "commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/*.html", "/docs/commit.html"), "docs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("*.html", "/commit.html"), "/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("*.html", "/docs/commit.html"), "/docs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("**/*.*", "/docs/commit.html"), "/docs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("*", "/docs/commit.html"), "/docs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("**/commit.html", "/docs/cvs/other/commit.html"), "/docs/cvs/other/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/**/commit.html", "/docs/cvs/other/commit.html"), "cvs/other/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/**/**/**/**", "/docs/cvs/other/commit.html"), "cvs/other/commit.html"); - - assertEquals(pathMatcher.extractPathWithinPattern("/d?cs/*", "/docs/cvs/commit"), "docs/cvs/commit"); - assertEquals(pathMatcher.extractPathWithinPattern("/docs/c?s/*.html", "/docs/cvs/commit.html"), "cvs/commit.html"); - assertEquals(pathMatcher.extractPathWithinPattern("/d?cs/**", "/docs/cvs/commit"), "docs/cvs/commit"); - assertEquals(pathMatcher.extractPathWithinPattern("/d?cs/**/*.html", "/docs/cvs/commit.html"), "docs/cvs/commit.html"); + assertEquals("", pathMatcher.extractPathWithinPattern("/docs/commit.html", "/docs/commit.html")); + + assertEquals("cvs/commit", pathMatcher.extractPathWithinPattern("/docs/*", "/docs/cvs/commit")); + assertEquals("commit.html", pathMatcher.extractPathWithinPattern("/docs/cvs/*.html", "/docs/cvs/commit.html")); + assertEquals("cvs/commit", pathMatcher.extractPathWithinPattern("/docs/**", "/docs/cvs/commit")); + assertEquals("cvs/commit.html", pathMatcher.extractPathWithinPattern("/docs/**/*.html", "/docs/cvs/commit.html")); + assertEquals("commit.html", pathMatcher.extractPathWithinPattern("/docs/**/*.html", "/docs/commit.html")); + assertEquals("commit.html", pathMatcher.extractPathWithinPattern("/*.html", "/commit.html")); + assertEquals("docs/commit.html", pathMatcher.extractPathWithinPattern("/*.html", "/docs/commit.html")); + assertEquals("/commit.html", pathMatcher.extractPathWithinPattern("*.html", "/commit.html")); + assertEquals("/docs/commit.html", pathMatcher.extractPathWithinPattern("*.html", "/docs/commit.html")); + assertEquals("/docs/commit.html", pathMatcher.extractPathWithinPattern("**/*.*", "/docs/commit.html")); + assertEquals("/docs/commit.html", pathMatcher.extractPathWithinPattern("*", "/docs/commit.html")); + assertEquals("/docs/cvs/other/commit.html", pathMatcher.extractPathWithinPattern("**/commit.html", "/docs/cvs/other/commit.html")); + assertEquals("cvs/other/commit.html", pathMatcher.extractPathWithinPattern("/docs/**/commit.html", "/docs/cvs/other/commit.html")); + assertEquals("cvs/other/commit.html", pathMatcher.extractPathWithinPattern("/docs/**/**/**/**", "/docs/cvs/other/commit.html")); + + assertEquals("docs/cvs/commit", pathMatcher.extractPathWithinPattern("/d?cs/*", "/docs/cvs/commit")); + assertEquals("cvs/commit.html", pathMatcher.extractPathWithinPattern("/docs/c?s/*.html", "/docs/cvs/commit.html")); + assertEquals("docs/cvs/commit", pathMatcher.extractPathWithinPattern("/d?cs/**", "/docs/cvs/commit")); + assertEquals("docs/cvs/commit.html", pathMatcher.extractPathWithinPattern("/d?cs/**/*.html", "/docs/cvs/commit.html")); } @Test diff --git a/integration-tests/jakarta-ee/pom.xml b/integration-tests/jakarta-ee/pom.xml index 29502708c2..3143a82c87 100644 --- a/integration-tests/jakarta-ee/pom.xml +++ b/integration-tests/jakarta-ee/pom.xml @@ -37,17 +37,11 @@ ${maven.compiler.release} ${maven.compiler.release} - 1.8.0.Final - 2.5.6 - 2.5.4 - - --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/java.net=ALL-UNNAMED - --add-opens java.base/sun.net.www=ALL-UNNAMED - + 2.5 + 3.0.0-alpha.4 firefox - 5.2022.5 + 5.2022.5.jdk21 ${skipITs} asadmin ${payara.start.skip} @@ -68,7 +62,7 @@ org.omnifaces omnifaces - 3.14.4 + 3.14.5 org.projectlombok @@ -149,20 +143,20 @@ com.flowlogix flowlogix-jee - 5.5.2 + 5.5.4 org.jboss.arquillian.junit5 arquillian-junit5-container - ${arquillian.version} + 1.8.0.Final test fish.payara.arquillian arquillian-payara-server-remote - 2.5 + ${arquillian.payara5.version} test @@ -176,6 +170,18 @@ arquillian-suite-extension 1.2.2 test + + + org.javassist + javassist + + + + + org.javassist + javassist + 3.30.2-GA + test @@ -190,24 +196,10 @@ - - org.jboss.arquillian - arquillian-bom - ${arquillian.version} - pom - test - - - org.jboss.arquillian.extension - arquillian-drone-bom - ${arquillian.drone.version} - pom - import - org.jboss.shrinkwrap.resolver shrinkwrap-resolver-bom - 3.2.1 + 3.3.0 pom import @@ -242,9 +234,7 @@ ${gh_user} ${gh_token} ${webdriver.browser} - ${webdriver.chrome.driver} ${webdriver.chrome.binary} - ${webdriver.gecko.driver} ${webdriver.firefox.binary} ${failsafe.argLine} ${payara.argLine} @@ -298,7 +288,7 @@ false - fish.payara.distributions + com.flowlogix.payara payara ${payara.version} zip @@ -371,7 +361,7 @@ org.codehaus.mojo exec-maven-plugin - 3.1.1 + 3.3.0 ${project.build.directory}/dependency/payara5/bin/${asadmin.cmd} ${payara.start.skip} @@ -503,7 +493,7 @@ - payara-server-remote + payara-server-local true diff --git a/integration-tests/jaxrs/openliberty/pom.xml b/integration-tests/jaxrs/openliberty/pom.xml index faf2d77cc2..5074a2e5eb 100644 --- a/integration-tests/jaxrs/openliberty/pom.xml +++ b/integration-tests/jaxrs/openliberty/pom.xml @@ -60,7 +60,7 @@ io.openliberty.tools liberty-maven-plugin - 3.10 + 3.10.3 shiro-its-jaxrs-openliberty diff --git a/integration-tests/jaxrs/tests/pom.xml b/integration-tests/jaxrs/tests/pom.xml index 6e5096c64f..65367fb0f9 100644 --- a/integration-tests/jaxrs/tests/pom.xml +++ b/integration-tests/jaxrs/tests/pom.xml @@ -66,7 +66,7 @@ org.apache.cxf cxf-rt-rs-client - 3.6.2 + 3.6.3 runtime diff --git a/integration-tests/meecrowave-support/pom.xml b/integration-tests/meecrowave-support/pom.xml index cddabfe34d..fa36b1c507 100644 --- a/integration-tests/meecrowave-support/pom.xml +++ b/integration-tests/meecrowave-support/pom.xml @@ -60,7 +60,7 @@ org.slf4j jcl-over-slf4j - 2.0.10 + 2.0.13 runtime diff --git a/lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java b/lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java index 04883a47b4..b9097eefa8 100644 --- a/lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java +++ b/lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java @@ -27,61 +27,61 @@ class ClassUtilsTest { @Test void testGetPrimitiveClasses() throws UnknownClassException { - assertEquals(ClassUtils.forName("boolean"), boolean.class); - assertEquals(ClassUtils.forName("byte"), byte.class); - assertEquals(ClassUtils.forName("char"), char.class); - assertEquals(ClassUtils.forName("short"), short.class); - assertEquals(ClassUtils.forName("int"), int.class); - assertEquals(ClassUtils.forName("long"), long.class); - assertEquals(ClassUtils.forName("float"), float.class); - assertEquals(ClassUtils.forName("double"), double.class); - assertEquals(ClassUtils.forName("void"), void.class); + assertEquals(boolean.class, ClassUtils.forName("boolean")); + assertEquals(byte.class, ClassUtils.forName("byte")); + assertEquals(char.class, ClassUtils.forName("char")); + assertEquals(short.class, ClassUtils.forName("short")); + assertEquals(int.class, ClassUtils.forName("int")); + assertEquals(long.class, ClassUtils.forName("long")); + assertEquals(float.class, ClassUtils.forName("float")); + assertEquals(double.class, ClassUtils.forName("double")); + assertEquals(void.class, ClassUtils.forName("void")); - assertEquals(ClassUtils.forName(boolean.class.getName()), boolean.class); - assertEquals(ClassUtils.forName(byte.class.getName()), byte.class); - assertEquals(ClassUtils.forName(char.class.getName()), char.class); - assertEquals(ClassUtils.forName(short.class.getName()), short.class); - assertEquals(ClassUtils.forName(int.class.getName()), int.class); - assertEquals(ClassUtils.forName(long.class.getName()), long.class); - assertEquals(ClassUtils.forName(float.class.getName()), float.class); - assertEquals(ClassUtils.forName(double.class.getName()), double.class); - assertEquals(ClassUtils.forName(void.class.getName()), void.class); + assertEquals(boolean.class, ClassUtils.forName(boolean.class.getName())); + assertEquals(byte.class, ClassUtils.forName(byte.class.getName())); + assertEquals(char.class, ClassUtils.forName(char.class.getName())); + assertEquals(short.class, ClassUtils.forName(short.class.getName())); + assertEquals(int.class, ClassUtils.forName(int.class.getName())); + assertEquals(long.class, ClassUtils.forName(long.class.getName())); + assertEquals(float.class, ClassUtils.forName(float.class.getName())); + assertEquals(double.class, ClassUtils.forName(double.class.getName())); + assertEquals(void.class, ClassUtils.forName(void.class.getName())); } @Test void testGetPrimitiveArrays() throws UnknownClassException { - assertEquals(ClassUtils.forName("[Z"), boolean[].class); - assertEquals(ClassUtils.forName("[B"), byte[].class); - assertEquals(ClassUtils.forName("[C"), char[].class); - assertEquals(ClassUtils.forName("[S"), short[].class); - assertEquals(ClassUtils.forName("[I"), int[].class); - assertEquals(ClassUtils.forName("[J"), long[].class); - assertEquals(ClassUtils.forName("[F"), float[].class); - assertEquals(ClassUtils.forName("[D"), double[].class); + assertEquals(boolean[].class, ClassUtils.forName("[Z")); + assertEquals(byte[].class, ClassUtils.forName("[B")); + assertEquals(char[].class, ClassUtils.forName("[C")); + assertEquals(short[].class, ClassUtils.forName("[S")); + assertEquals(int[].class, ClassUtils.forName("[I")); + assertEquals(long[].class, ClassUtils.forName("[J")); + assertEquals(float[].class, ClassUtils.forName("[F")); + assertEquals(double[].class, ClassUtils.forName("[D")); - assertEquals(ClassUtils.forName(boolean[].class.getName()), boolean[].class); - assertEquals(ClassUtils.forName(byte[].class.getName()), byte[].class); - assertEquals(ClassUtils.forName(char[].class.getName()), char[].class); - assertEquals(ClassUtils.forName(short[].class.getName()), short[].class); - assertEquals(ClassUtils.forName(int[].class.getName()), int[].class); - assertEquals(ClassUtils.forName(long[].class.getName()), long[].class); - assertEquals(ClassUtils.forName(float[].class.getName()), float[].class); - assertEquals(ClassUtils.forName(double[].class.getName()), double[].class); + assertEquals(boolean[].class, ClassUtils.forName(boolean[].class.getName())); + assertEquals(byte[].class, ClassUtils.forName(byte[].class.getName())); + assertEquals(char[].class, ClassUtils.forName(char[].class.getName())); + assertEquals(short[].class, ClassUtils.forName(short[].class.getName())); + assertEquals(int[].class, ClassUtils.forName(int[].class.getName())); + assertEquals(long[].class, ClassUtils.forName(long[].class.getName())); + assertEquals(float[].class, ClassUtils.forName(float[].class.getName())); + assertEquals(double[].class, ClassUtils.forName(double[].class.getName())); } @Test void testGetClass() { - assertEquals(ClassUtils.forName("java.lang.String"), String.class); - assertEquals(ClassUtils.forName("[Ljava.lang.String;"), String[].class); - assertEquals(ClassUtils.forName(String.class.getName()), String.class); - assertEquals(ClassUtils.forName(String[].class.getName()), String[].class); + assertEquals(String.class, ClassUtils.forName("java.lang.String")); + assertEquals(String[].class, ClassUtils.forName("[Ljava.lang.String;")); + assertEquals(String.class, ClassUtils.forName(String.class.getName())); + assertEquals(String[].class, ClassUtils.forName(String[].class.getName())); - assertEquals(ClassUtils.forName("org.apache.shiro.lang.util.ClassUtilsTest"), ClassUtilsTest.class); - assertEquals(ClassUtils.forName("[Lorg.apache.shiro.lang.util.ClassUtilsTest;"), ClassUtilsTest[].class); - assertEquals(ClassUtils.forName(ClassUtilsTest.class.getName()), ClassUtilsTest.class); - assertEquals(ClassUtils.forName(ClassUtilsTest[].class.getName()), ClassUtilsTest[].class); + assertEquals(ClassUtilsTest.class, ClassUtils.forName("org.apache.shiro.lang.util.ClassUtilsTest")); + assertEquals(ClassUtilsTest[].class, ClassUtils.forName("[Lorg.apache.shiro.lang.util.ClassUtilsTest;")); + assertEquals(ClassUtilsTest.class, ClassUtils.forName(ClassUtilsTest.class.getName())); + assertEquals(ClassUtilsTest[].class, ClassUtils.forName(ClassUtilsTest[].class.getName())); } } diff --git a/pom.xml b/pom.xml index e3302b3fd3..d371e2cf01 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ org.apache apache - 31 + 32 org.apache.shiro @@ -87,47 +87,48 @@ modules' OSGi metadata: --> 1.9.20.1 1.9.4 - 1.6.0 + 1.8.0 3.2.2 - 2.9.0 + 2.11.0 3.14.0 - 1.3.0 + 1.3.2 1.8 2.6.11 - 5.3.6 - 2.7.2 + 5.3.7 + 2.7.3 1.3.2 1.1.1 11 - 9.4.53.v20231009 + 9.4.54.v20240208 1.2.3 - 2.3.2 - 2.0.10 - 2.22.1 - 5.3.31 + 2.5.0-rc1 + 2.3.0 + 2.0.13 + 2.23.1 + 5.3.37 2.7.18 4.2.3 2.1.6 - 3.9.0 - 1.77 + 4.2.0 + 1.78.1 - 5.2.0 - 5.8.0 - 1.14.11 + 5.3.0 + 5.12.0 + 1.14.17 3.0.2 - 4.0.17 - 5.10.1 + 4.0.21 + 5.10.2 3.1.1 5.6.15.Final 1.2.5 1.3.5 - 1.18.30 + 1.18.32 ${jdk.version} @@ -277,6 +278,12 @@ native false true + + + junit.jupiter.execution.parallel.enabled = true + junit.jupiter.execution.parallel.mode.default = concurrent + + @@ -297,6 +304,15 @@ maven-javadoc-plugin org.apache.shiro.samples.* + true + + https://docs.oracle.com/javase/${jdk.version}/docs/api/ + https://www.slf4j.org/api/ + https://docs.spring.io/spring/docs/${spring.version}/javadoc-api/ + https://docs.spring.io/spring-boot/docs/${spring-boot.version}/api/ + https://junit.org/junit5/docs/${junit.version}/api/ + https://www.quartz-scheduler.org/api/${quartz.docs.version}/ + @@ -307,7 +323,7 @@ org.apache.maven.plugins maven-help-plugin - 3.4.0 + 3.4.1 org.apache.felix @@ -321,7 +337,7 @@ org.apache.maven.plugins maven-scm-publish-plugin - 3.2.1 + 3.3.0 org.apache.rat @@ -371,17 +387,17 @@ org.codehaus.mojo build-helper-maven-plugin - 3.5.0 + 3.6.0 org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.12 com.mycila license-maven-plugin - 4.3 + 4.5 true
${root.dir}/src/license/header.txt
@@ -415,12 +431,12 @@ org.owasp dependency-check-maven - 9.0.7 + 9.2.0 com.github.siom79.japicmp japicmp-maven-plugin - 0.18.3 + 0.21.2 @@ -485,6 +501,8 @@ + @@ -538,7 +556,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.1 + 3.4.0 ${checkstyle.configLocation} ${checkstyle.supressionsLocation} @@ -563,7 +581,7 @@ com.puppycrawl.tools checkstyle - 10.12.7 + 10.17.0
@@ -654,6 +672,7 @@ org/apache/shiro/**/*Test$* org/apache/shiro/**/*IT org/apache/shiro/**/*IT$* + org/apache/shiro/testing/jakarta/ee/PropertyPrincipal org/apache/shiro/**/__EJB31_Generated* org/apache/shiro/**/Deployments @@ -865,7 +884,7 @@ org.assertj assertj-core - 3.25.1 + 3.26.0 test @@ -1427,20 +1446,8 @@ maven-javadoc-plugin + false - true - - https://docs.oracle.com/javase/11/docs/api/ - https://docs.oracle.com/javaee/7/api/ - https://www.slf4j.org/api/ - https://docs.spring.io/spring/docs/2.5.x/javadoc-api/ - https://junit.org/junit4/javadoc/4.12/ - https://easymock.org/api/ - https://javadoc.io/doc/org.mockito/mockito-core/${mockito.version}/org/mockito/Mockito.html - https://www.quartz-scheduler.org/api/1.8.6/ - - - org.apache.shiro.samples.*