通过 JAAS 以编程方式登录用户 [英] Login a user programmatically via JAAS
问题描述
我试图通过以编程方式登录这样的用户(剥离异常处理)以不同的身份验证在 JBoss Container 中运行代码:
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();
}
});
newuser
的登录有效(LoginModule
的调用成功)但 Subject.doAs()
没有将新的主题与EJBContext
.run()
-Method 中的代码仍然从 EJBContext
中获取旧用户的主体.
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");
有什么想法吗?
推荐答案
您现在使用哪个 LoginModule
?在 JBoss 6.1 中,您必须使用 ClientLoginModule
在容器中进行身份验证.
Which LoginModule
do you use now? In JBoss 6.1 you had to use ClientLoginModule
to authenticate in container.
这篇关于通过 JAAS 以编程方式登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!