我在 Glassfish 3.1.2 中使用 ProgrammaticLogin 以及用户名、密码和领域,效果很好。无论如何,当我调用 context.getCallerPrincipal() 时,我会得到 org.glassfish.security.common.PrincipalImpl 和 context.getCallerPrincipal().getName() ,它返回用户名。
有什么方法可以通过 ProgrammaticLogin 传递 Principle 所以它在我的 ejb 中传递并可从 SessionContext - context.getCallerPrincipal() 获取?
最佳答案
我猜您所处的环境无法通过注释进行资源注入(inject)。 您可以尝试通过手动 JNDI 查找来获取所需 EJB 的实例。
示例:
InitialContext init = new InitialContext();
YourBean bean = (YourBean) init.lookup(JNDI_NAME_OF_YOUR_BEAN);
现在您应该能够将委托(delegate)人传递给您的 bean。
关于java - 程序化登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13531762/