Apache Shiro: ClassCastException on Realm
<p>Ok, I am officially confused.</p>

<p>In Shiro I have my own realm (DatastoreRealm) that extends AuthorizingRealm.  In my DatastoreRealm, I have the method "<strong>clearCachedAuthorizationInfo</strong>" which allows me to clear the users permissions, etc, (and then re-check) when those permissions change on the fly.</p>

<p>In order to get to that method, I have to get access to my <strong>DatastoreRealm</strong> object.
I do this in the following way...</p>

<pre><code>private static Realm lookupRealm(String realmName)  {
     SecurityManager securityManager = SecurityUtils.getSecurityManager();
     RealmSecurityManager realmSecurityManager = (RealmSecurityManager) securityManager;

     Collection&lt;Realm&gt; realms = realmSecurityManager.getRealms();
     for (Realm realm : realms) {
         if (realm.getName().equalsIgnoreCase(realmName)) {
             log.info("look up realm name is : " + realm.getName());
             return realm;
         }
     }
    return null; }
</code></pre>

<p>This seems to work fine.  It returns me a "DatastoreRealm" object.</p>

<p>Although when I call this method, I am forced to do the following...</p>

<pre><code> DatastoreRealm dsRealm =  (DatastoreRealm) lookupRealm("rfRealm");
</code></pre>

<p>Which throws a "<strong>ClassCastException</strong>" telling me...</p>

<pre><code>rf.gae.DatastoreRealm cannot be cast to rf.gae.DatastoreRealm
</code></pre>

<p>How/Why is this happening???</p>

<p>If I DON'T cast, and simply use the "<strong>Realm</strong>" object, the "<strong>clearCachedAuthorizationInfo</strong>" is not available to me!</p>

<p>Thanks in advance for the help!</p>