private void updatePermissions(
            IPortletDefinition def,
            Set<IGroupMember> newPrincipals,
            String owner,
            String activity) {
        final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);

        final IUpdatingPermissionManager pm =
                authorizationService.newUpdatingPermissionManager(owner);

        /* Create the new permissions array */
        final List<IPermission> newPermissions = new ArrayList<>();
        for (final IGroupMember newPrincipal : newPrincipals) {
            final IAuthorizationPrincipal authorizationPrincipal =
                    authorizationService.newPrincipal(newPrincipal);
            final IPermission permission = pm.newPermission(authorizationPrincipal);
            permission.setType(IPermission.PERMISSION_TYPE_GRANT);
            permission.setActivity(activity);
            permission.setTarget(portletTargetId);
            newPermissions.add(permission);
            logger.trace("In updatePermissions() - adding a new permission of: {}", permission);
        }

        /* Remove former permissions for this portlet / activity */
        final IPermission[] oldPermissions = pm.getPermissions(activity, portletTargetId);
        pm.removePermissions(oldPermissions);

        /* Add the new permissions */
        pm.addPermissions(newPermissions.toArray(new IPermission[newPermissions.size()]));
    }
private void updatePermissions ( IPortletDefinition def , Set < IGroupMember > newPrincipals , String owner , String activity ) { final String portletTargetId = PermissionHelper . permissionTargetIdForPortletDefinition ( def ) ; final IUpdatingPermissionManager pm = authorizationService . newUpdatingPermissionManager ( owner ) ; final List < IPermission > newPermissions = new ArrayList < > ( ) ; for ( final IGroupMember newPrincipal : newPrincipals ) { final IAuthorizationPrincipal authorizationPrincipal = authorizationService . newPrincipal ( newPrincipal ) ; final IPermission permission = pm . newPermission ( authorizationPrincipal ) ; permission . setType ( IPermission . PERMISSION_TYPE_GRANT ) ; permission . setActivity ( activity ) ; permission . setTarget ( portletTargetId ) ; newPermissions . add ( permission ) ; logger . trace ( "In updatePermissions() - adding a new permission of: {}" , permission ) ; } final IPermission [ ] oldPermissions = pm . getPermissions ( activity , portletTargetId ) ; pm . removePermissions ( oldPermissions ) ; pm . addPermissions ( newPermissions . toArray ( new IPermission [ newPermissions . size ( ) ] ) ) ; }
/*
Update permissions for a given owner, activity, and portlet definition combination. Adds new principals' permissions passed in and removes
principals' permissions if not in the list for the given activity.