简体   繁体   中英

WebLogic: can't get roles for user in EJB3

In my EJB 3 I try to test for the roles of the principal but it always returns false .

In my WebLogic 11g Console I defined under "MyDomain" -> "Security Realms" -> "myrealm" -> "Users and Groups" 3 users (user1 , user2 & user3) and 2 groups (role1 & role2); role1 has user1 & user3, role2 has user2 & user3.
My EJB has no further security defined (no @RolesAllowed , etc. or entries in DDs).

When I test in my EJB for the presence of roles with sessionContext.isCallerInRole(role); it always returns false . If I call sessionContext.getCallerPrincipal().getName(); I do get the correct user ID.

What am I doing wrong?

If your sessionContext is injected, specifying the authentication Type as Container in the @Resource annotation worked for me. Eg:

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

Have you declared your role using either @DeclareRoles or ? If I read the spec correctly section 17.2.5.3 seems to mandate that you have to declare any role names that you use when calling isCallerInRole() through one or the other mechanism.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM