[jboss-user] [Security & JAAS/JBoss] - Re: How do I get user roles in 2.6?

nollie do-not-reply at jboss.com
Thu Aug 16 13:42:15 EDT 2007


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?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074928#4074928

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074928



More information about the jboss-user mailing list