Package org.apache.jackrabbit.api.jsr283.security

Examples of org.apache.jackrabbit.api.jsr283.security.Privilege


   * @throws RepositoryException
   */
  public AccessRights getEffectiveAccessRightsForPrincipal(Session session, String absPath, String principalId) throws RepositoryException {
    AccessRights rights = new AccessRights();
    if (principalId != null && principalId.length() > 0) {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      AccessControlPolicy[] policies = accessControlManager.getEffectivePolicies(absPath);
      for (AccessControlPolicy accessControlPolicy : policies) {
        if (accessControlPolicy instanceof AccessControlList) {
          AccessControlEntry[] accessControlEntries = ((AccessControlList)accessControlPolicy).getAccessControlEntries();
          for (AccessControlEntry ace : accessControlEntries) {
            if (principalId.equals(ace.getPrincipal().getName())) {
View Full Code Here


   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canAddChildren(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      return accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_ADD_CHILD_NODES)
            });
    } catch (RepositoryException e) {
      return false;
    }
  }
View Full Code Here

   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canDeleteChildren(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
     
      return accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_CHILD_NODES)
            });
    } catch (RepositoryException e) {
      return false;
    }
  }
View Full Code Here

   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canDelete(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
     
      String parentPath = absPath.substring(0, absPath.lastIndexOf('/'));
      boolean canDelete = accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_NODE)
            }) && canDeleteChildren(session, parentPath);
      return canDelete;
    } catch (RepositoryException e) {
      return false;
    }
View Full Code Here

   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canModifyProperties(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      return accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_MODIFY_PROPERTIES)
            });
    } catch (RepositoryException e) {
      return false;
    }
  }
View Full Code Here

   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canReadAccessControl(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      return accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL)
            });
    } catch (RepositoryException e) {
      return false;
    }
  }
View Full Code Here

   * @param absPath the path of the resource to check
   * @return true if the current user has the privileges, false otherwise
   */
  public boolean canModifyAccessControl(Session session, String absPath) {
    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      return accessControlManager.hasPrivileges(absPath, new Privilege[] {
              accessControlManager.privilegeFromName(Privilege.JCR_MODIFY_ACCESS_CONTROL)
            });
    } catch (RepositoryException e) {
      return false;
    }
  }
View Full Code Here

        if (user == null) {
            user = userManager.createUser("test", "quatloos");
        }
        // set up permissions
        String permissionsPath = session.getRootNode().getPath();
        AccessControlManager accessControlManager = session
                .getAccessControlManager();
        AccessControlPolicyIterator acls = accessControlManager
                .getApplicablePolicies(permissionsPath);
        if (acls.hasNext()) {
            JackrabbitAccessControlList acl = (JackrabbitAccessControlList) acls
                    .nextAccessControlPolicy();
            acl.addEntry(user.getPrincipal(), accessControlManager
                    .getSupportedPrivileges(permissionsPath), true);
            accessControlManager.setPolicy(permissionsPath, acl);
        } else {
            throw new Exception("could not set access control for path "
                    + permissionsPath);
        }
View Full Code Here

        if (user == null) {
            user = userManager.createUser("test", "quatloos");
        }
        // set up permissions
        String permissionsPath = session.getRootNode().getPath();
        AccessControlManager accessControlManager = session
                .getAccessControlManager();
        AccessControlPolicyIterator acls = accessControlManager
                .getApplicablePolicies(permissionsPath);
        if (acls.hasNext()) {
            JackrabbitAccessControlList acl = (JackrabbitAccessControlList) acls
                    .nextAccessControlPolicy();
            acl.addEntry(user.getPrincipal(), accessControlManager
                    .getSupportedPrivileges(permissionsPath), true);
            accessControlManager.setPolicy(permissionsPath, acl);
        } else {
            throw new Exception("could not set access control for path "
                    + permissionsPath);
        }
View Full Code Here

                Map restrictions = new HashMap();
                restrictions.put(session.getJCRName(ACLTemplate.P_NODE_PATH), vf.createValue(root.getPath(), PropertyType.PATH));
                restrictions.put(session.getJCRName(ACLTemplate.P_GLOB), vf.createValue(GlobPattern.WILDCARD_ALL));

                PrincipalManager pMgr = session.getPrincipalManager();
                AccessControlManager acMgr = session.getAccessControlManager();
                Principal administrators;
                String pName = SecurityConstants.ADMINISTRATORS_NAME;
                if (pMgr.hasPrincipal(pName)) {
                    administrators = pMgr.getPrincipal(pName);
                } else {
                    log.warn("Administrators principal group is missing.");
                    administrators = new PrincipalImpl(pName);
                }
                AccessControlPolicy[] acls = editor.editAccessControlPolicies(administrators);
                ACLTemplate acl = (ACLTemplate) acls[0];
                if (acl.isEmpty()) {
                    log.info("... Privilege.ALL for administrators principal.");
                    acl.addEntry(administrators,
                            new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_ALL)},
                            true, restrictions);
                    editor.setPolicy(acl.getPath(), acl);
                } else {
                    log.info("... policy for administrators principal already present.");
                }

                Principal everyone = pMgr.getEveryone();
                acls = editor.editAccessControlPolicies(everyone);
                acl = (ACLTemplate) acls[0];
                if (acl.isEmpty()) {
                    log.info("... Privilege.READ for everyone principal.");
                    acl.addEntry(everyone,
                            new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_READ)},
                            true, restrictions);
                    editor.setPolicy(acl.getPath(), acl);
                } else {
                    log.info("... policy for everyone principal already present.");
                }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.api.jsr283.security.Privilege

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.