I'm trying to run code within JBoss Container under a different authentication by programatically logging in a user like that (stripped 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();
}
});
Login of newuser
works (Call of LoginModule
was successful) but Subject.doAs()
doesn't associate the new Subject with the EJBContext
. The code in the run()
-Method still fetches the old user's principal from EJBContext
.
I tested another method of retrieving the logged in user but same behavior here:
Subject caller = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
Any ideas?
All you have to know is how to write your application and specify configuration information (such as in a login configuration file) such that the application will be able to utilize the LoginModule specified by the configuration to authenticate the user.
The Java Authentication and Authorization Service (JAAS) was introduced as an optional package (extension) to the Java 2 SDK, Standard Edition (J2SDK), v 1.3.
The Java Authentication and Authorization Service (JAAS) is a set of application program interfaces (APIs) that can determine the identity of a user or computer attempting to run Java code and ensure that the entity has the right to execute the functions requested.
JAAS provides subject-based authorization on authenticated identities. This document focuses on the authentication aspect of JAAS, specifically the LoginModule interface.
Which LoginModule
do you use now? In JBoss 6.1 you had to use ClientLoginModule
to authenticate in container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With