Search in sources :

Example 11 with PermissionService

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();
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService)

Example 12 with PermissionService

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();
    }
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) Path(org.alfresco.service.cmr.repository.Path) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 13 with PermissionService

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();
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) Path(org.alfresco.service.cmr.repository.Path) UINodePath(org.alfresco.web.ui.repo.component.UINodePath) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 14 with PermissionService

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();
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) AuditModelRegistryImpl(org.alfresco.repo.audit.model.AuditModelRegistryImpl) AuditService(org.alfresco.service.cmr.audit.AuditService) URL(java.net.URL) Before(org.junit.Before)

Aggregations

PermissionService (org.alfresco.service.cmr.security.PermissionService)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 NodeService (org.alfresco.service.cmr.repository.NodeService)7 StoreRef (org.alfresco.service.cmr.repository.StoreRef)5 ServiceRegistry (org.alfresco.service.ServiceRegistry)4 StringTokenizer (java.util.StringTokenizer)3 QName (org.alfresco.service.namespace.QName)3 InputStream (java.io.InputStream)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 Path (org.alfresco.service.cmr.repository.Path)2 UINodePath (org.alfresco.web.ui.repo.component.UINodePath)2 Before (org.junit.Before)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketException (java.net.SocketException)1 URL (java.net.URL)1