public Collection<Realm> getRealms() throws IllegalStateException {
        Collection<String> jndiNames = getJndiNames();
        if (jndiNames == null || jndiNames.isEmpty()) {
            String msg = "One or more jndi names must be specified for the "
                    + getClass().getName() + " to locate Realms.";
            throw new IllegalStateException(msg);
        }
        List<Realm> realms = new ArrayList<Realm>(jndiNames.size());
        for (String name : jndiNames) {
            try {
                Realm realm = (Realm) lookup(name, Realm.class);
                realms.add(realm);
            } catch (Exception e) {
                throw new IllegalStateException("Unable to look up realm with jndi name '" + name + "'.", e);
            }
        }
        return realms.isEmpty() ? null : realms;
    }
Performs the JNDI lookups for each specified {@link #getJndiNames() JNDI name} and returns all
discovered Realms in an ordered collection.

<p>The returned Collection is in the same order as the specified
{@link #setJndiNames(java.util.Collection) jndiNames}

@return an ordered collection of the {@link #setJndiNames(java.util.Collection) specified Realms} found in JNDI.
@throws IllegalStateException if any of the JNDI names fails to successfully look up a Realm instance.
core/src/main/java/org/apache/shiro/realm/jndi/JndiRealmFactory.java