I encouter a problem like this, sessionContext.getCallerPrincipal() always returns a SimplePrincipal instance, and its name is "anonymous", I expected that it would return a customed principal which implements the interface Principal.
At client side, I implement a LoginModule, in the method commit(), add a my own customed principal, then call the remote EJB.
I have exactly the same issue with JBoss 7.1.1. For the ClassCastException itself, I do not have a solution, but I have a workaround which works until I have a clean and staight solution.
When retrieving the principal via
public SessionContext sessionContext;
Principal principal = sessionContext.getCallerPrincipal();
I check the name of the instantiated class via
to assure the correct implementation and to avoid later exceptions. Then I work with reflection to access fields and method via getMethod() and getField(). It works fine, but it is quite ugly. Does anyone have a better idea?
Solution for me was, login modul is deployed as jboss modul. No packages from my login module are included in any deployments!.
my login modul is defined in standalone.xml as global, so any class loaders can find it.
I still had to add my login modul as dependency to some othe jboss provided modules... you see while testing which modul get problems, so you add your login modul to this modul as dependecy...