Skip to content

Commit

Permalink
FirstSuccessfulStrategy now detects empty principal correctly
Browse files Browse the repository at this point in the history
Fixes: SHIRO-747
  • Loading branch information
bdemers committed Mar 11, 2020
1 parent dc38003 commit c7c9c57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -64,7 +64,7 @@ public AuthenticationInfo beforeAllAttempts(Collection<? extends Realm> realms,
* 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;
Expand Down
Expand Up @@ -98,10 +98,22 @@ public void testBeforeAttemptNull() {
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);
}

}

0 comments on commit c7c9c57

Please sign in to comment.