boolean contentFragmentIsReference = (contentFragmentImpl.getReference() != null);
// retrieve current fragment and page or template from page manager
BaseFragmentsElement pageOrTemplate = getPageOrTemplate(contentFragmentImpl.getPageOrTemplate().getPath());
String pageFragmentId = (contentFragmentIsReference ? contentFragmentImpl.getReference().getId() : contentFragmentImpl.getFragment().getId());
BaseFragmentElement fragment = pageOrTemplate.getFragmentById(pageFragmentId);
if (fragment == null)
{
throw new IllegalArgumentException("Fragment and page not consistent");
}
// check for edit permission
fragment.checkAccess(JetspeedActions.EDIT);
// update fragment preferences and page in page manager.
// Initializing security constraints by setting empty one first to reset it after aggregating into fragmentConstraintsConstraints..
//
//TODO: JS2-1259: BaseElementImpl doesn't consider null input; DBPM based security constraints update needs to be more tested.
// For now, set an empty one instead of null to avoid this problem as well as possible side effects.
//
//fragment.setSecurityConstraints(null);
fragment.setSecurityConstraints(fragment.newSecurityConstraints());
if ((constraints != null) && !constraints.isEmpty())
{
SecurityConstraints fragmentConstraints = fragment.newSecurityConstraints();
String constraintsOwner = constraints.getOwner();
if (constraintsOwner != null)
{
fragmentConstraints.setOwner(constraintsOwner);
}
List constraintsConstraints = constraints.getSecurityConstraints();
if ((constraintsConstraints != null) && !constraintsConstraints.isEmpty())
{
List fragmentConstraintsConstraints = new ArrayList(constraintsConstraints.size());
Iterator constraintsIter = constraintsConstraints.iterator();
while (constraintsIter.hasNext())
{
SecurityConstraint constraint = (SecurityConstraint)constraintsIter.next();
SecurityConstraint fragmentConstraintsConstraint = fragment.newSecurityConstraint();
fragmentConstraintsConstraint.setGroups(constraint.getGroups());
fragmentConstraintsConstraint.setPermissions(constraint.getPermissions());
fragmentConstraintsConstraint.setRoles(constraint.getRoles());
fragmentConstraintsConstraint.setUsers(constraint.getUsers());
fragmentConstraintsConstraints.add(fragmentConstraintsConstraint);
}
fragmentConstraints.setSecurityConstraints(fragmentConstraintsConstraints);
}
List constraintsConstraintsRefs = constraints.getSecurityConstraintsRefs();
if ((constraintsConstraintsRefs != null) && !constraintsConstraintsRefs.isEmpty())
{
List fragmentConstraintsConstraintsRefs = new ArrayList(constraintsConstraintsRefs.size());
Iterator constraintsRefsIter = constraintsConstraintsRefs.iterator();
while (constraintsRefsIter.hasNext())
{
fragmentConstraintsConstraintsRefs.add((String)constraintsRefsIter.next());
}
fragmentConstraints.setSecurityConstraintsRefs(fragmentConstraintsConstraintsRefs);
}
fragment.setSecurityConstraints(fragmentConstraints);
}
updatePage(pageOrTemplate);
// update content context
contentFragmentImpl.setSecurityConstraints(constraints);