use of org.alfresco.service.cmr.security.PermissionService in project acs-community-packaging by Alfresco.
the class Node method hasPermission.
/**
* Return whether the current user has the specified access permission on this Node
*
* @param permission Permission to validate against
*
* @return true if the permission is applied to the node for this user, false otherwise
*/
public boolean hasPermission(String permission) {
Boolean valid = null;
if (this.permissions != null) {
valid = this.permissions.get(permission);
} else {
this.permissions = new HashMap<String, Boolean>(8, 1.0f);
}
if (valid == null) {
PermissionService service = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPermissionService();
valid = Boolean.valueOf(service.hasPermission(this.nodeRef, permission) == AccessStatus.ALLOWED);
this.permissions.put(permission, valid);
}
return valid.booleanValue();
}
use of org.alfresco.service.cmr.security.PermissionService in project acs-community-packaging by Alfresco.
the class NodePathLinkRenderer method buildPathAsSingular.
/**
* Return the path with the entire path as a single clickable link
*
* @param context FacesContext
* @param component UIComponent to get display attribute from
* @param path Node Path to use
*
* @return the entire path as a single clickable link
*/
private String buildPathAsSingular(FacesContext context, UIComponent component, Path path, boolean showLeaf, boolean disabled) {
StringBuilder buf = new StringBuilder(512);
NodeService nodeService = getNodeService(context);
PermissionService permissionService = getPermissionService(context);
NodeRef lastElementRef = null;
int size = (showLeaf ? path.size() : path.size() - 1);
int lastElementPos = (showLeaf ? path.size() - 1 : path.size() - 2);
for (int i = 0; i < size; i++) {
Path.Element element = path.get(i);
String elementString = null;
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
String name = null;
if (permissionService.hasPermission(elementRef.getChildRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
// use the name property if we are allowed access to it
elementString = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME).toString();
} else {
// revert to using QName if not
elementString = elementRef.getQName().getLocalName();
}
}
if (i == lastElementPos) {
lastElementRef = elementRef.getChildRef();
}
} else {
elementString = element.getElementString();
}
if (elementString != null) {
buf.append("/");
buf.append(elementString);
}
}
if (disabled == false && lastElementRef != null) {
return renderPathElement(context, component, lastElementRef, buf.toString());
} else {
return buf.toString();
}
}
use of org.alfresco.service.cmr.security.PermissionService in project acs-community-packaging by Alfresco.
the class NodePathLinkRenderer method buildPathAsBreadcrumb.
/**
* Return the path with each element as a single clickable link e.g. breadcrumb style
*
* @param context FacesContext
* @param component UIComponent to get display attribute from
* @param path Node Path to use
*
* @return the path with each individual element clickable
*/
private String buildPathAsBreadcrumb(FacesContext context, UIComponent component, Path path, boolean showLeaf) {
StringBuilder buf = new StringBuilder(1024);
NodeService nodeService = getNodeService(context);
PermissionService permissionService = getPermissionService(context);
int size = (showLeaf ? path.size() : path.size() - 1);
for (int i = 0; i < size; i++) {
Path.Element element = path.get(i);
String elementString = null;
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
String name = null;
if (permissionService.hasPermission(elementRef.getChildRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
// use the name property if we are allowed access to it
name = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME).toString();
} else {
// revert to using QName if not
name = elementRef.getQName().getLocalName();
}
elementString = renderPathElement(context, component, elementRef.getChildRef(), name);
}
} else {
elementString = element.getElementString();
}
if (elementString != null) {
buf.append("/");
buf.append(elementString);
}
}
return buf.toString();
}
use of org.alfresco.service.cmr.security.PermissionService in project alfresco-remote-api by Alfresco.
the class AuditAppTest method setup.
@Before
public void setup() throws Exception {
super.setup();
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
auditService = applicationContext.getBean("AuditService", AuditService.class);
AuditModelRegistryImpl auditModelRegistry = (AuditModelRegistryImpl) applicationContext.getBean("auditModel.modelRegistry");
// Register the test model
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-access.xml");
auditModelRegistry.registerModel(testModelUrl);
auditModelRegistry.loadAuditModels();
}
Aggregations