Package com.ibm.portal.ac

This package and its sub packages define the portal access control (PAC) API.

See:
          Description

Interface Summary
AccessControlAttributeBasedSecurity The AccessControlAttributeBasedSecurityInterface defines a method to get called by the AccessControlAttributeBasedSecurity pattern.
ContentItem The AccessControlAttributeBasedSecurityCallbackInterface provides methods to retrieve detailed information about the current ContentItem.
 

Package com.ibm.portal.ac Description

This package and its sub packages define the portal access control (PAC) API.

Overview

The PAC API offers functionality to retrieve and modify access control related information of any resources (e.g. portlets, pages) that are managed by portal access control. In particular, the following data objects and relationships can be created, retrieved, modified and deleted:

Class Overview - Service Interfaces

The main service interfaces as listed below can be retrieved through the AccessControlHome

Code Samples

Retrieve ManagedProtectedResource and RoleData Instances

The following sample shows how instances of the ManagedProtectedResource and RoleData can be retrieved through a JNDI lookup and the CommunityHome class. Additionally, the owner of the resource and all principals that are directly mapped to the EDITOR role type are retrieved.
        Identifiable resource = ... ; // some resource, for example a portlet
        Context ctx = new InitialContext();
        AccessControlHome home = (AccessControlHome) ctx.lookup(AccessControlHome.JNDI_NAME);
        ManagedProtectedResource pacResource = home.getManagedProtectedResource(resource);
        RoleData resourceRoleData = home.getRoleData(resource);
        Principal owner = pacResource.getOwner();
        Set editors = resourceRoleData.getMappedPrincipals(RoleType.EDITOR);

Retrieve Role Assignments

The following sample shows how to retrieve all Role Assignments that are effective for a principal on a resource.
        Identifiable resource = ... ; // some resource, for example a portlet
        Principal bob = ... ; // some principal, for example Bob
        Context ctx = new InitialContext();
        AccessControlHome home = (AccessControlHome) ctx.lookup(AccessControlHome.JNDI_NAME);
        RoleData resourceRoleData = home.getRoleData(resource);
        Set assignments = resourceRoleData.getRoleAssignments(bob);
        for (RoleAssignment assignment: assignments) {
           // p is either bob or any group that bob belongs to
           Principal p = assignment.getPrincipal; 
           Role role = assignment.getRole();
           // resourceID is either the ID of the above resource or of any parent
           ObjectID resourceID = role.getResourceID();
           // the role type of the mapping
           RoleType roleType = role.getRoleType();
        }

Evaluate if a principal has certain permissions

The following sample shows how to evaluate if a principal has view permissions on a resource
        Identifiable resource = ... ; // some resource, for example a portlet
        Principal bob = ... ; // some principal, for example Bob
        Context ctx = new InitialContext();
        AccessControlHome home = (AccessControlHome) ctx.lookup(AccessControlHome.JNDI_NAME);
        AccessControlRuntimeModel runtimeModel = home.getAccessControlRuntimeModel(resource);
        boolean isAllowed = runtimeModel.isAllowed(bob, RoleType.USER);
        
        // the following is equivalent
        AccessControlEnvironment environment = home.getAccessControlEnvironment();
        Permission permission = environment.getPermission(resource, RoleType.USER);
        AccessControlGlobalRuntimeModel gobalModel = home.getAccessControlGlobalRuntimeModel();
        globalModel.hasPermission(bob, permission); 

Modify role blocks for a resource

The following sample shows how to add, set or remove role blocks on a resource
        Identifiable resource = ... ; // some resource, for example a portlet
        Principal bob = ... ; // some principal, for example Bob
        Context ctx = new InitialContext();
        AccessControlHome home = (AccessControlHome) ctx.lookup(AccessControlHome.JNDI_NAME);
        ManagedProtectedResource resourceController = home.getManagedProtectedResourceController(resource);
        Collection roleBlocks = Collection.singleton(RoleType.EDITOR);
        
        // the EDITOR inheritance role block is added to the existing role blocks 
        resourceController.addInheritanceBlockedRoleTypes(roleBlocks);

        // the EDITOR inheritance role block is set (so it becomes the only inheritance block) 
        resourceController.setInheritanceBlockedRoleTypes(roleBlocks);
        
        // the EDITOR inheritance role block is removed 
        resourceController.removeInheritanceBlockedRoleTypes(roleBlocks);        

Assign principals to roles

The following sample shows how to assign principals to a role
        Identifiable resource = ... ; // some resource, for example a portlet
        Principal bob = ... ; // some principal, for example Bob
        Context ctx = new InitialContext();
        AccessControlHome home = (AccessControlHome) ctx.lookup(AccessControlHome.JNDI_NAME);
        RoleDataController roleController = home.getRoleDataController(resource);
        Collection principals = Collection.singleton(bob);
        // bob is assigned the EDITOR role
        roleController.addPrincipalsToRole(RoleType.EDITOR, principals);
                
        // bob is unassigned from the MANAGER role
        roleController.removePrincipalsFromRole(RoleType.MANAGER, principals);