Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
But do not add questions without answers to this page. If you have a question about how to do something in tomcat which has not been addressed yet, ask the tomcat-user list: \[http://jakarta.apache.org/tomcat/faq/tomcatuser.html \] Once you've figured out how to fix your problem, come back and update the Wiki to allow the rest of us to benefit from what you've learned!

...

How can I access members of a custom Realm or Principal? When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your webapp code, you'll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server's ClassLoader, and you are trying to access it through you webapp's ClassLoader. While the classes maybe otherwise exactly the same, different (sibling) ClassLoaders makes them different classes.

This assumes you created a MyUserPrincipal class, and put in Tomcat's server\classes directory, as well as in your webapp's webinf\classes directory.