I am trying to run the code in a JBoss container under a different authentication by programming it this way (disabled exception handling):
LoginContext ctx = ctx = new LoginContext("MyLoginSchema", new UsernamePasswordCallbackHandler("newuser", "") ); ctx.login(); Subject.doAs(ctx.getSubject(), new PrivilegedAction<T>() { @Override public T run() { Subject.getSubject(AccessController.getContext()); InitialContext ic = new InitialContext(); EJBContext sctxLookup = (EJBContext) ic.lookup("java:comp/EJBContext"); Principal principal = sctxLookup.getCallerPrincipal(); } });
The newuser login is working ( LoginModule was successful), but Subject.doAs() does not associate the new object with the EJBContext . The code in run() -Method still selects the old user-user from EJBContext .
I tested another way to get a registered user, but the same behavior here:
Subject caller = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
Any ideas?
source share