Show TOC

Background documentationChecking Permissions Locate this document in the navigation structure

 

With the IPermission interface, you can do the following:

  • Check if a specific user has a specific permission - isAllowed().

  • Get a list of all the permissions that can be assigned for this object - getAllPermissions().

The interface also has the helper function getPermissionTitle() for getting the display name for a specific permission.

To modify permissions, use the PCD API, as described in Setting PCD Permissions.

Checking a User's Permission

The following code example checks whether the current user has read permission on the object with the PCD name stored in the string myObject:

Syntax Syntax

  1. IAdminBase myAdmin = (IAdminBase)iCtx.lookup(myObject);
    IPermission myIview = (IPermission)
        myAdmin.getImplementation(IAdminBase.PERMISSION);
    
    boolean hasPermission = myIview
        .isAllowed(request.getUser(),IPermission.PCM_ADMIN_READ);
    
    if (hasPermission) {
        response.write(request.getUser().getName() + " has "
            + myIview.getPermissionTitle("Pcd.Read",request.getLocale())
                + " permission.<br>");     
    }
End of the code.
Permission Constants

The IPermission interface provides constants for checking the following permissions:

  • Owner

  • Read

  • Write

  • Read-Write

  • Full Control

  • Use

To check the role assigner permission, use the constant IPortalBasicRoleFactoryService.ROLE_ASSIGNMENT_PERMISSION.

Note Note

The PCM's IPermission and PCD's IPcdStandardPermissions interfaces define different sets of permissions constants. They are not interchangeable.

End of the note.