02-12-2014 12:33 PM
public class MyPermissionServiceImpl extends PermissionServiceImpl
{
public static final String PERSONNEL_FOLDER = "personnel-folder";
private static SoftCache cacheAcls = new SoftCache();
private static Log log = LogFactory.getLog(MyPermissionServiceImpl.class);
@Override
public AccessStatus hasPermission(NodeRef passedNodeRef, PermissionReference permIn)
{
String fileName = (String) nodeService.getProperty(passedNodeRef, ContentModel.PROP_NAME);
String currentUser = AuthenticationUtil.getRunAsUser();
AccessStatus status = super.hasPermission(passedNodeRef, permIn);
if ((status != AccessStatus.ALLOWED) && (nodeService.getPath(passedNodeRef).toString().indexOf(PERSONNEL_FOLDER) > -1))
status = hasPermission(currentUser, fileName, passedNodeRef, permIn);
log.info("Permission: " + currentUser + ": " + fileName + " - " + permIn + ": " + status);
return status;
}
private AccessStatus hasPermission(String currentUser, String fileName, NodeRef node, PermissionReference permIn)
{
AccessStatus status = (AccessStatus)cacheAcls.get(node.getId() + ":" + currentUser + ":" + permIn.getName());
if (status == null)
{
if (permIn.getName().startsWith(READ))
status = hasReadPermission(currentUser, fileName, node, permIn);
else if (permIn.getName().startsWith(WRITE) || permIn.getName().startsWith(DELETE) || permIn.getName().startsWith(CREATE_CHILDREN) || permIn.getName().startsWith(CREATE_ASSOCIATIONS))
status = hasWritePermission(currentUser, fileName, node, permIn);
else if (permIn.getName().equals(CANCEL_CHECK_OUT))
status = hasCancelCheckOutPermission(currentUser, fileName, node, permIn);
else if (permIn.getName().equals(CHANGE_PERMISSIONS))
status = hasChangePermPermission(currentUser, fileName, node, permIn);
else
{
status = AccessStatus.DENIED;
log.fatal("UNKNOWN PERMISSION: " + currentUser + ": " + fileName + " - " + permIn + ": " + status);
}
cacheAcls.put(node.getId() + ":" + currentUser + ":" + permIn.getName(), status);
}
return status;
}
private AccessStatus hasReadPermission(String currentUser, String fileName, NodeRef node, PermissionReference permIn)
{
// Do our own access control
}
// …
}
02-13-2014 07:11 AM
02-13-2014 11:38 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.