You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2020/03/11 19:18:30 UTC

[shiro] branch SHIRO-747 created (now c7c9c57)

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

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


      at c7c9c57  FirstSuccessfulStrategy now detects empty principal correctly

This branch includes the following new commits:

     new c7c9c57  FirstSuccessfulStrategy now detects empty principal correctly

The 1 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.



[shiro] 01/01: FirstSuccessfulStrategy now detects empty principal correctly

Posted by bd...@apache.org.
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 <bd...@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);
     }
-
 }