shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject [shiro] 01/01: FirstSuccessfulStrategy now detects empty principal correctly
Date Wed, 11 Mar 2020 19:18:31 GMT
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch SHIRO-747
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit c7c9c57d69a180dce679c5f26d4f6db64b250a7e
Author: Brian Demers <bdemers@apache.org>
AuthorDate: Wed Mar 11 15:17:46 2020 -0400

    FirstSuccessfulStrategy now detects empty principal correctly
    
    Fixes: SHIRO-747
---
 .../apache/shiro/authc/pam/FirstSuccessfulStrategy.java  |  2 +-
 .../shiro/authc/pam/FirstSuccessfulStrategyTest.java     | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategy.java b/core/src/main/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategy.java
index 87cb5cc..3d332f1 100644
--- a/core/src/main/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategy.java
+++ b/core/src/main/java/org/apache/shiro/authc/pam/FirstSuccessfulStrategy.java
@@ -64,7 +64,7 @@ public class FirstSuccessfulStrategy extends AbstractAuthenticationStrategy
{
      * otherwise.
      */
     public AuthenticationInfo beforeAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo
aggregate) throws AuthenticationException {
-        if (getStopAfterFirstSuccess() && aggregate != null && isEmpty(aggregate.getPrincipals()))
{
+        if (getStopAfterFirstSuccess() && aggregate != null && !isEmpty(aggregate.getPrincipals()))
{
             throw new ShortCircuitIterationException();
         }
         return aggregate;
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 68fe395..5f06566 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
@@ -98,10 +98,22 @@ public class FirstSuccessfulStrategyTest {
         assertNull(strategy.beforeAttempt(null, null, null));
     }
 
+    @Test
+    public void testBeforeAttemptEmptyPrincipal() {
+        AuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+        assertEquals(strategy.beforeAttempt(null, null, aggregate), aggregate);
+    }
+
+    @Test
+    public void testBeforeAttemptEmptyList() {
+        SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
+        AuthenticationInfo aggregate = new SimpleAuthenticationInfo(principalCollection,
null);
+        assertEquals(strategy.beforeAttempt(null, null, aggregate), aggregate);
+    }
+
     @Test (expected=ShortCircuitIterationException.class)
     public void testBeforeAttemptStopAfterFirstSuccess() {
-        AuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+        AuthenticationInfo aggregate = new SimpleAuthenticationInfo("principal", null, "a-realm-name");
         strategy.beforeAttempt(null, null, aggregate);
     }
-
 }


Mime
View raw message