Weblogic Portal Authorization – Get and Check User’s Roles

| Posted by watashii | Filed under Java, Programming, Web

The Authorization class provides runtime methods for security policies and roles checks.  The following code fragment obtains the set of roles the logged-in user belongs to.  Note the user must be authenticated first, see Authentication class.

String entAppName = ApplicationHelper.getNonVersionedAppName();
String webAppName = ApplicationHelper.getWebAppName(request);
EnterpriseRoleResource resource = new EnterpriseRoleResource(entAppName,webAppName,EntitlementConstants.P13N_ROLE_POLICY_POOL,"");
Map userRoles = Authorization.getRoles((P13nResource) resource);
if (Authorization.isUserInRole("Admin", userRoles)) {
	return true;
}

Global and Enterprise Application roles are obtained using EnterpriseRoleResource.  For Global, Enterprise, and Web Application roles, use WebappRoleResource.

com.bea.p13n.security.Authentication

Tags: , , , ,