- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 8.1.0.Final 版本中使用 Wildfly。我正在以如下方式通过休息服务使用 HttpServletRequest 进行身份验证。
@Context
HttpServletRequest request;
...
request.login(user, password);
然后,我就可以使用 request.getUserPrincipal() 获取已记录的用户主体;
但是来自 web 层的登录身份不会传播到 ejb 层。如果我试图从 ejb bean 获取用户主体,则用户主体始终是“匿名的”:
@Stateless
@SecurityDomain("other")
@PermitAll
public class FooBean implements Foo {
@Resource
private EJBContext ejbContext;
public void someMethod() {
String name = ejbContext.getCallerPrincipal().getName();
}
}
是否有任何方法可以将记录的用户主体从 web 层传递到 ejb 上下文?
最佳答案
我总是在 Wildfly 8.0.0.Final 上收到 Anonymous CallerPricipal 或 null UserPrincipal,直到我应用了补丁以移动到 Wildfly 8.1.0.Final 并且一切都很好。
我们项目之间唯一明显的区别是,我没有使用 @SecurityDomain,而是使用 xml 来避免代码中的供应商细节。我建议您重新检查使用该注释的要求或试用 xml 并查看您是否仍然有问题
我的 jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<security-domain>myJaasSecurityDomain</security-domain>
</jboss>
我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<security-role>
<role-name>ADMIN</role-name>
</security-role>
<security-role>
<role-name>CUSTOMER</role-name>
</security-role>
</web-app>
希望下一个人不会像我一样在这上面花 2 天时间
关于java - 如何将用户主体从 HttpServletRequest 传播到 EJBContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24432897/
我正在使用 JBoss AS 7.1 开发带有外部数据库 (Postgres) 的简单 EJB 应用程序。 我想在 Bean 中找出当前登录用户的用户名。我收到此异常: javax.servlet.S
EjbContext 有什么用处以及它如何在 Ejb 应用程序中发挥作用? 在哪些场景下我们需要EjbContext?我正在使用 Ejb 创建一个应用程序。所以只是想知道 EjbContext 是否有
我在 8.1.0.Final 版本中使用 Wildfly。我正在以如下方式通过休息服务使用 HttpServletRequest 进行身份验证。 @Context HttpServletRequest
我正在阅读 Java EE 7 的事务管理,我对嵌套事务的概念和 EJBContext#setRollbackOnly() 的功能感到困惑。 假设我有两个 session Bean,Bean1Impl
我计划使用 EJBContext 将一些属性从应用程序层(特别是消息驱动的 bean)传递到无法直接注入(inject)或传递参数的持久性生命周期回调( session 监听器)在 EclipseLi
我在Weblogic服务器中得到以下异常,从日志来看,这绝对是weblogic内部的东西,但是,不确定weblogic正在尝试归档应用程序的哪一部分,你知道为什么会发生这种情况吗?
我想从登录用户获取单例中的调用者主体。用户正在使用用户名/密码对其余服务进行身份验证 安全域在war中的jboss-web.xml中 application-security war 的终点是: @P
我是一名优秀的程序员,十分优秀!