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

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


The following commit(s) were added to refs/heads/3.x by this push:
     new ed92e3f17 enh: made AuthenticationInfo.merge() return this to make it 
fluent and easier to use
ed92e3f17 is described below

commit ed92e3f17ba8cac2e0972cabcefee95b7a557d9f
Author: lprimak <[email protected]>
AuthorDate: Wed Mar 4 12:18:52 2026 -0600

    enh: made AuthenticationInfo.merge() return this to make it fluent and 
easier to use
---
 .../org/apache/shiro/authc/MergableAuthenticationInfo.java    |  4 ++--
 core/src/main/java/org/apache/shiro/authc/SimpleAccount.java  |  4 +++-
 .../java/org/apache/shiro/authc/SimpleAuthenticationInfo.java | 11 +++++++----
 .../apache/shiro/authc/pam/FirstSuccessfulStrategyTest.java   |  8 ++++----
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git 
a/core/src/main/java/org/apache/shiro/authc/MergableAuthenticationInfo.java 
b/core/src/main/java/org/apache/shiro/authc/MergableAuthenticationInfo.java
index 0103fc894..c0334d154 100644
--- a/core/src/main/java/org/apache/shiro/authc/MergableAuthenticationInfo.java
+++ b/core/src/main/java/org/apache/shiro/authc/MergableAuthenticationInfo.java
@@ -41,7 +41,7 @@ public interface MergableAuthenticationInfo extends 
AuthenticationInfo {
      * not be modified in any way.
      *
      * @param info the info that should be merged into this instance.
+     * @return this instance with the new principals and credentials merged in.
      */
-    void merge(AuthenticationInfo info);
-
+    AuthenticationInfo merge(AuthenticationInfo info);
 }
diff --git a/core/src/main/java/org/apache/shiro/authc/SimpleAccount.java 
b/core/src/main/java/org/apache/shiro/authc/SimpleAccount.java
index 959dfe135..d8e01d76b 100644
--- a/core/src/main/java/org/apache/shiro/authc/SimpleAccount.java
+++ b/core/src/main/java/org/apache/shiro/authc/SimpleAccount.java
@@ -443,8 +443,9 @@ public class SimpleAccount implements Account, 
MergableAuthenticationInfo, Salte
      * (only if their values are <code>true</code>).
      *
      * @param info the <code>AuthenticationInfo</code> to merge into this 
account.
+     * @return this instance with the merged information from the specified 
argument.
      */
-    public void merge(AuthenticationInfo info) {
+    public AuthenticationInfo merge(AuthenticationInfo info) {
         authcInfo.merge(info);
 
         // Merge SimpleAccount specific info
@@ -457,6 +458,7 @@ public class SimpleAccount implements Account, 
MergableAuthenticationInfo, Salte
                 setCredentialsExpired(true);
             }
         }
+        return this;
     }
 
     /**
diff --git 
a/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java 
b/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
index b39c20781..60f218f47 100644
--- a/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
+++ b/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
@@ -199,12 +199,13 @@ public class SimpleAuthenticationInfo implements 
MergableAuthenticationInfo, Sal
      * Takes the specified <code>info</code> argument and adds its principals 
and credentials into this instance.
      *
      * @param info the <code>AuthenticationInfo</code> to add into this 
instance.
+     * @return this instance with the new principals and credentials merged in.
      */
     @Override
     @SuppressWarnings("checkstyle:NPathComplexity")
-    public void merge(AuthenticationInfo info) {
+    public AuthenticationInfo merge(AuthenticationInfo info) {
         if (info == null || info.getPrincipals() == null || 
info.getPrincipals().isEmpty()) {
-            return;
+            return this;
         }
 
         if (this.principals == null) {
@@ -230,12 +231,12 @@ public class SimpleAuthenticationInfo implements 
MergableAuthenticationInfo, Sal
         Object otherCredentials = info.getCredentials();
 
         if (otherCredentials == null) {
-            return;
+            return this;
         }
 
         if (thisCredentials == null) {
             this.credentials = otherCredentials;
-            return;
+            return this;
         }
 
         if (!(thisCredentials instanceof Collection)) {
@@ -252,6 +253,8 @@ public class SimpleAuthenticationInfo implements 
MergableAuthenticationInfo, Sal
         } else {
             credentialCollection.add(otherCredentials);
         }
+
+        return this;
     }
 
     /**
diff --git 
a/core/src/test/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategyTest.java
 
b/core/src/test/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategyTest.java
index 1f646159d..081563be4 100644
--- 
a/core/src/test/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategyTest.java
+++ 
b/core/src/test/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategyTest.java
@@ -51,8 +51,8 @@ public class FirstSuccessfulStrategyTest {
     void testMergeWithValidAggregateInfo() {
         AuthenticationInfo aggregate = new MergableAuthenticationInfo() {
             @Override
-            public void merge(AuthenticationInfo info) {
-
+            public AuthenticationInfo merge(AuthenticationInfo info) {
+                return info;
             }
 
             @Override
@@ -73,8 +73,8 @@ public class FirstSuccessfulStrategyTest {
     void testMergeWithInvalidAggregateInfo() {
         AuthenticationInfo aggregate = new MergableAuthenticationInfo() {
             @Override
-            public void merge(AuthenticationInfo info) {
-
+            public AuthenticationInfo merge(AuthenticationInfo info) {
+                return this;
             }
 
             @Override

Reply via email to