This content has been marked as final.
Show 2 replies
-
1. Re: How do I get user roles in 2.6?
nollie Aug 16, 2007 1:42 PM (in response to nollie)Right now I'm doing this, but I'd rather have a cleaner solution with the RoleModule ...
public static boolean hasRole(String roleName) { Subject caller = SecurityAssociation.getSubject(); if ( caller == null ) { return false; } Set princes = caller.getPrincipals(); Iterator i = princes.iterator(); while (i.hasNext() ) { String roles = i.next().toString(); // e.g. Roles(members:User,Admin,Administrators,Authenticated) // make sure to check for commas, colons, and close paren // so "User" isn't mistaken for "SuperUser" and the like if ( roles.contains(":" + roleName + ",") || roles.contains("," + roleName + ",") || roles.contains("," + roleName + ")")) { return true; } } return false; }
Any suggestions? -
2. Re: How do I get user roles in 2.6?
jc7442 Aug 17, 2007 2:35 AM (in response to nollie)You can also delegate that to a session bean:
SessionContext ctx = ... ... ctx.isCallerInRole("myRole");