ContentFragment fragment = page.getFragmentById(fragmentId);
if (fragment == null)
{
throw new PortletException("Cannot find fragment: " + fragmentId);
}
SecurityConstraints constraints = new TransientSecurityConstraints(fragment.getSecurityConstraints());
SecurityConstraint constraint = new TransientSecurityConstraint(fragment.newSecurityConstraint());
String [] rolesArray = StringUtils.split(request.getParameter("roles"), DELIMITERS);
String [] groupsArray = StringUtils.split(request.getParameter("groups"), DELIMITERS);
String [] usersArray = StringUtils.split(request.getParameter("users"), DELIMITERS);
if (!ArrayUtils.isEmpty(rolesArray))
{
constraint.setRoles(Arrays.asList(rolesArray));
}
if (!ArrayUtils.isEmpty(groupsArray))
{
constraint.setGroups(Arrays.asList(groupsArray));
}
if (!ArrayUtils.isEmpty(usersArray))
{
constraint.setUsers(Arrays.asList(usersArray));
}
String [] permissionArray = StringUtils.split(StringUtils.defaultString(request.getParameter("permissions")), DELIMITERS);
if (!ArrayUtils.isEmpty(permissionArray))
{
constraint.setPermissions(Arrays.asList(permissionArray));
}
List<SecurityConstraint> constraintList = constraints.getSecurityConstraints();
if (constraintList == null)
{
constraintList = new ArrayList<SecurityConstraint>();
}
constraintList.add(constraint);
constraints.setSecurityConstraints(constraintList);
pageLayoutComponent.updateSecurityConstraints(fragment, constraints);
}
catch (Exception e)
{
throw new PortletException("Failed to add security constraint.", e);
}
}