Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

NoSuchElementException when reading principals where multiple Realms in use #2

Open
zgrose opened this issue Apr 8, 2014 · 1 comment

Comments

@zgrose
Copy link

zgrose commented Apr 8, 2014

I have an application that uses multiple Realms (in this particular case an IniRealm and the ApplicationRealm). ApplicationRealm.getAccountHref() assumes that the subject was authenticated against the ApplicationRealm

protected String getAccountHref(PrincipalCollection principals) {
    Collection c = principals.fromRealm(getName());
    //Based on the createPrincipals implementation above, the first one is the Account href:
    return (String) c.iterator().next();
}

When a PrincipalCollection is passed to doGetAuthorizationInfo, the c.size() == 0 so there is no next().

java.util.NoSuchElementException
at java.util.Collections$EmptyIterator.next(Collections.java:3006)

Trapping an empty collection and returning a default/empty SimpleAuthorizationInfo seems the most appropriate solution but that's just a guess.

@mike10004
Copy link

This happened to me on the first visit to a site after switching my application's realm from IniRealm to ApplicationRealm, because it still had the cookie from the previous login. (Or, I assume that's the explanation, because visiting in incognito mode worked and then clearing the cookie and refreshing worked.) I understand what happened, but the NoSuchElementException stack trace in the logs did not point me in the right direction.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants