WebLogic:无法在EJB3中获取用户角色

时间:2011-03-11 15:16:27

标签: java security ejb-3.0 weblogic weblogic11g

在我的EJB 3中,我尝试测试主体的角色,但它总是返回false

在我的WebLogic 11g控制台中,我在“MyDomain”下定义了 - > “安全领域” - > “myrealm” - > “用户和组”3个用户(user1,user2& user3)和2个组(role1& role2); role1有user1& user3,role2有user2&用户3。
我的EJB没有定义进一步的安全性(没有@RolesAllowed等等或DD中的条目)。

当我在我的EJB中测试sessionContext.isCallerInRole(role);角色的存在时,总是返回false。如果我拨打sessionContext.getCallerPrincipal().getName();,我会获得正确的用户ID。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

您是否使用@DeclareRoles或?如果我正确阅读规范,第17.2.5.3节似乎要求你必须声明在通过一种或另一种机制调用isCallerInRole()时使用的任何角色名称。

答案 1 :(得分:0)

如果注入了sessionContext,请在@Resource注释中为我指定身份验证类型为容器。 E.g:

@Resource(authenticationType=AuthenticationType.CONTAINER)
private SessionContext sessionCtx;