User login by user through JAAS

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?

+6
source share
2 answers

Which LoginModule are you using now? In JBoss 6.1, you had to use ClientLoginModule to authenticate in the container.

+2
source

As I understand it, JBoss AS 7.1 is not currently supported. See this thread

Edit

What I wrote here is incorrect, the stream is used only to enter the client side (outside of JBoss).

0
source

Source: https://habr.com/ru/post/927174/


All Articles