You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lp...@apache.org on 2026/05/24 02:02:03 UTC

(shiro) branch 3.x updated (169a49825 -> 07a65c9a9)

This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a change to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git


    from 169a49825 Merge branch 'main' into 3.x
     new 436933e40 make sure subject's session gets fully cleared fix for #2704
     new 8a5c0d29a bugfix: session attributes survive id rotation in native session mode fixes #2710
     new b193d5c8d Merge branch 'session-fixation' into 3.x
     add a7265a1a1 chore(deps): bump org.apache.commons:commons-configuration2 (#2706)
     add 9371115fe [#2704] [#2710] Fixed Session fixation-related regressions (#2711)
     new 07a65c9a9 Merge branch 'main' into 3.x

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/shiro/mgt/DefaultSecurityManager.java   | 18 +++++++++++-
 .../shiro/subject/support/DelegatingSubject.java   |  2 +-
 .../shiro/subject/DelegatingSubjectTest.java       | 32 ++++++++++++++++++++++
 pom.xml                                            |  2 +-
 4 files changed, 51 insertions(+), 3 deletions(-)


(shiro) 04/04: Merge branch 'main' into 3.x

Posted by lp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit 07a65c9a97d7898f4453bde9afa2ae7c37996447
Merge: b193d5c8d 9371115fe
Author: lprimak <le...@flowlogix.com>
AuthorDate: Sat May 23 20:58:02 2026 -0500

    Merge branch 'main' into 3.x

 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



(shiro) 01/04: make sure subject's session gets fully cleared fix for #2704

Posted by lp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit 436933e40f47f9fc76f3a598e6f9201dfb2694a3
Author: lprimak <le...@flowlogix.com>
AuthorDate: Wed May 20 20:48:14 2026 -0500

    make sure subject's session gets fully cleared
    fix for #2704
---
 core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java   | 4 ++++
 .../main/java/org/apache/shiro/subject/support/DelegatingSubject.java | 2 +-
 .../src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

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 58149cd93..d97be6894 100644
--- a/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java
+++ b/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java
@@ -35,6 +35,7 @@ import org.apache.shiro.subject.PrincipalCollection;
 import org.apache.shiro.subject.Subject;
 import org.apache.shiro.subject.SubjectContext;
 import org.apache.shiro.subject.support.DefaultSubjectContext;
+import org.apache.shiro.subject.support.DelegatingSubject;
 import org.apache.shiro.util.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -603,6 +604,9 @@ public class DefaultSecurityManager extends SessionsSecurityManager {
         Session s = subject.getSession(false);
         if (s != null) {
             s.stop();
+            if (subject instanceof DelegatingSubject delegatingSubject) {
+                delegatingSubject.sessionStopped();
+            }
         }
     }
 
diff --git a/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java b/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
index 903006bc5..1cc764eee 100644
--- a/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
+++ b/core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java
@@ -378,7 +378,7 @@ public class DelegatingSubject implements Subject {
         }
     }
 
-    private void sessionStopped() {
+    public void sessionStopped() {
         this.session = null;
     }
 
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 6da337ab3..ecccb0db5 100644
--- a/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java
+++ b/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java
@@ -151,6 +151,8 @@ public class DelegatingSubjectTest {
         //login as user1
         Subject subject = new Subject.Builder(sm).buildSubject();
         subject.login(new UsernamePasswordToken("user1", "user1"));
+        // duplicate login, test for https://github.com/apache/shiro/issues/2704
+        subject.login(new UsernamePasswordToken("user1", "user1"));
 
         assertThat(subject.isRunAs()).isFalse();
         assertThat(subject.getPrincipal()).isEqualTo("user1");


(shiro) 02/04: bugfix: session attributes survive id rotation in native session mode fixes #2710

Posted by lp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit 8a5c0d29a0996dbdeb2ff114c8725a8b2ed1ce0d
Author: lprimak <le...@flowlogix.com>
AuthorDate: Wed May 20 22:03:10 2026 -0500

    bugfix: session attributes survive id rotation in native session mode
    fixes #2710
---
 .../apache/shiro/mgt/DefaultSecurityManager.java   | 14 +++++++++-
 .../shiro/subject/DelegatingSubjectTest.java       | 30 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

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 d97be6894..1a3ba503c 100644
--- a/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java
+++ b/core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java
@@ -42,6 +42,8 @@ import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * The Shiro framework's default concrete implementation of the {@link SecurityManager} interface,
@@ -303,7 +305,17 @@ public class DefaultSecurityManager extends SessionsSecurityManager {
      * @param subject Subject
      */
     protected void beforeSuccessfulLogin(Subject subject) {
-        stopSession(subject);
+        Session session = subject.getSession(false);
+        if (session != null) {
+            Map<Object, Object> attributes = new HashMap<>();
+            session.getAttributeKeys().forEach(key -> attributes.put(key, session.getAttribute(key)));
+            stopSession(subject);
+            var newSession = subject.getSession();
+            var keys = newSession.getAttributeKeys();
+            attributes.entrySet().stream()
+                    .filter(entry -> !keys.contains(entry.getKey()))
+                    .forEach(entry -> newSession.setAttribute(entry.getKey(), entry.getValue()));
+        }
     }
 
     protected void onSuccessfulLogin(AuthenticationToken token, AuthenticationInfo info, Subject subject) {
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 ecccb0db5..9b2a2175a 100644
--- a/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java
+++ b/core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java
@@ -220,6 +220,36 @@ public class DelegatingSubjectTest {
         LifecycleUtils.destroy(sm);
     }
 
+    @Test
+    void sessionAttributesSurviveLoginSessionRotation() {
+        Ini ini = new Ini();
+        Ini.Section users = ini.addSection("users");
+        users.put("user1", "user1,role1");
+        users.put("user2", "user2,role2");
+        users.put("user3", "user3,role3");
+        SecurityManager sm = new BasicIniEnvironment(ini).getSecurityManager();
+        Subject subject = new Subject.Builder(sm).buildSubject();
+
+        subject.login(new UsernamePasswordToken("user1", "user1"));
+        subject.logout();
+
+        Session preLoginSession = subject.getSession(true);
+        preLoginSession.setAttribute("tenantId", "ACME");
+        Serializable preLoginSessionId = preLoginSession.getId();
+
+        subject.login(new UsernamePasswordToken("user1", "user1"));
+        assertThat(subject.isAuthenticated()).isTrue();
+
+        Session postLoginSession = subject.getSession(false);
+        assertThat(postLoginSession).isNotNull();
+
+        assertThat(preLoginSessionId).as("session ID should change on login (session fixation protection)")
+                .isNotEqualTo(postLoginSession.getId());
+        assertThat(postLoginSession.getAttribute("tenantId"))
+                .as("session attributes set before login must survive session rotation")
+                .isEqualTo("ACME");
+    }
+
     @Test
     void testToString() {
         // given


(shiro) 03/04: Merge branch 'session-fixation' into 3.x

Posted by lp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit b193d5c8d687aea724263ca3f406418d1e354070
Merge: 169a49825 8a5c0d29a
Author: lprimak <le...@flowlogix.com>
AuthorDate: Sat May 23 20:13:51 2026 -0500

    Merge branch 'session-fixation' into 3.x

 .../apache/shiro/mgt/DefaultSecurityManager.java   | 18 +++++++++++-
 .../shiro/subject/support/DelegatingSubject.java   |  2 +-
 .../shiro/subject/DelegatingSubjectTest.java       | 32 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)