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

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


                }
            }
        }
        // node either not access-controlled or the passed policy didn't apply
        // to the node at 'nodePath' -> throw exception.no policy was removed
        throw new AccessControlException("Policy " + policy + " does not apply to " + nodePath);
    }
View Full Code Here


     */
    private void checkProtectsNode(String nodePath) throws RepositoryException {
        if (session.nodeExists(nodePath)) {
            NodeImpl n = (NodeImpl) session.getNode(nodePath);
            if (n.isNodeType(NT_REP_ACL) || n.isNodeType(NT_REP_ACE)) {
                throw new AccessControlException("Node " + nodePath + " defines ACL or ACE.");
            }
        }
    }
View Full Code Here

     * @throws AccessControlException
     */
    private void checkValidPolicy(String nodePath, AccessControlPolicy policy)
            throws AccessControlException {
        if (policy == null || !(policy instanceof ACLTemplate)) {
            throw new AccessControlException("Attempt to set/remove invalid policy " + policy);
        }
        ACLTemplate acl = (ACLTemplate) policy;
        if (!nodePath.equals(acl.getPath())) {
            throw new AccessControlException("Policy " + policy + " is not applicable or does not apply to the node at " + nodePath);
        }
    }
View Full Code Here

    private Principal getPrincipal(String pathToACNode) throws RepositoryException {
        String name = Text.unescapeIllegalJcrChars(Text.getName(pathToACNode));
        PrincipalManager pMgr = session.getPrincipalManager();
        if (!pMgr.hasPrincipal(name)) {
            throw new AccessControlException("Unknown principal.");
        }
        return pMgr.getPrincipal(name);
    }
View Full Code Here

     * @see AccessControlList#removeAccessControlEntry(AccessControlEntry)
     */
    public void removeAccessControlEntry(AccessControlEntry ace)
            throws AccessControlException, RepositoryException {
        if (!(ace instanceof Entry)) {
            throw new AccessControlException("Invalid AccessControlEntry implementation " + ace.getClass().getName() + ".");
        }
        if (!entries.remove(ace)) {
            throw new AccessControlException("Cannot remove AccessControlEntry " + ace);
        }
    }
View Full Code Here

            }
        }

        private void checkValidEntry() throws AccessControlException, NamespaceException {
            if (!principal.equals(getPrincipal())) {
                throw new AccessControlException("Invalid principal. Expected: " + principal);
            }
            if (!isAllow() && getPrincipal() instanceof Group) {
                throw new AccessControlException("For group principals permissions can only be added but not denied.");
            }

            String[] rNames = getRestrictionNames();
            if (!Arrays.asList(rNames).contains(jcrNodePathName)) {
                throw new AccessControlException("Missing mandatory restriction: " + jcrNodePathName);
            }
        }
View Full Code Here

     */
    public void setPolicy(String absPath, AccessControlPolicy policy) throws PathNotFoundException, AccessControlException, AccessDeniedException, RepositoryException {
        checkInitialized();
        checkPrivileges(absPath, PrivilegeRegistry.MODIFY_AC);

        throw new AccessControlException("AccessControlPolicy " + policy + " cannot be applied.");
    }
View Full Code Here

     */
    public void removePolicy(String absPath, AccessControlPolicy policy) throws PathNotFoundException, AccessControlException, AccessDeniedException, RepositoryException {
        checkInitialized();
        checkPrivileges(absPath, PrivilegeRegistry.MODIFY_AC);

        throw new AccessControlException("No AccessControlPolicy has been set through this API -> Cannot be removed.");
    }
View Full Code Here

      Set<String> pidSet = new HashSet<String>();
      pidSet.addAll(Arrays.asList(applyTo));
     
      try {
        AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
        AccessControlList updatedAcl = null;
        AccessControlPolicyIterator applicablePolicies = accessControlManager.getApplicablePolicies(resourcePath);
        while (applicablePolicies.hasNext()) {
          AccessControlPolicy policy = applicablePolicies.nextAccessControlPolicy();
          if (policy instanceof AccessControlList) {
            updatedAcl = (AccessControlList)policy;
            break;
          }
        }
        if (updatedAcl == null) {
          throw new RepositoryException("Unable to find an access control policy to update.");
        }
       
        //keep track of the existing Aces for the target principal
        AccessControlEntry[] accessControlEntries = updatedAcl.getAccessControlEntries();
        List<AccessControlEntry> oldAces = new ArrayList<AccessControlEntry>();
        for (AccessControlEntry ace : accessControlEntries) {
          if (pidSet.contains(ace.getPrincipal().getName())) {
            oldAces.add(ace);
          }
        }

        //remove the old aces
        if (!oldAces.isEmpty()) {
          for (AccessControlEntry ace : oldAces) {
            updatedAcl.removeAccessControlEntry(ace);
          }
        }
       
        //apply the changed policy
        accessControlManager.setPolicy(resourcePath, updatedAcl);
View Full Code Here

      }
    }

    try {
      AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
      AccessControlList updatedAcl = null;
      AccessControlPolicyIterator applicablePolicies = accessControlManager.getApplicablePolicies(resourcePath);
      while (applicablePolicies.hasNext()) {
        AccessControlPolicy policy = applicablePolicies.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
          updatedAcl = (AccessControlList)policy;
          break;
        }
      }
      if (updatedAcl == null) {
        throw new RepositoryException("Unable to find an access conrol policy to update.");
      }

      StringBuilder oldPrivileges = null;
      StringBuilder newPrivileges = null;
      if (log.isDebugEnabled()) {
        oldPrivileges = new StringBuilder();
        newPrivileges = new StringBuilder();
      }

      //keep track of the existing Aces for the target principal
      AccessControlEntry[] accessControlEntries = updatedAcl.getAccessControlEntries();
      List<AccessControlEntry> oldAces = new ArrayList<AccessControlEntry>();
      for (AccessControlEntry ace : accessControlEntries) {
        if (principalId.equals(ace.getPrincipal().getName())) {
          if (log.isDebugEnabled()) {
            log.debug("Found Existing ACE for principal {0} on resource: ", new Object[] {principalId, resourcePath});
          }
          oldAces.add(ace);
         
          if (log.isDebugEnabled()) {
            //collect the information for debug logging
            boolean isAllow = AccessControlUtil.isAllow(ace);
            Privilege[] privileges = ace.getPrivileges();
            for (Privilege privilege : privileges) {
              if (oldPrivileges.length() > 0) {
                oldPrivileges.append(", "); //separate entries by commas
              }
              if (isAllow) {
                oldPrivileges.append("granted=");
              } else {
                oldPrivileges.append("denied=");
              }
              oldPrivileges.append(privilege.getName());
            }
          }
        }
      }

      //remove the old aces
      if (!oldAces.isEmpty()) {
        for (AccessControlEntry ace : oldAces) {
          updatedAcl.removeAccessControlEntry(ace);
        }
      }
     
      //add a fresh ACE with the granted privileges
      List<Privilege> grantedPrivilegeList = new ArrayList<Privilege>();
      for (String name : grantedPrivilegeNames) {
        if (name.length() == 0) {
          continue; //empty, skip it.
        }
        Privilege privilege = accessControlManager.privilegeFromName(name);
        grantedPrivilegeList.add(privilege);
         
        if (log.isDebugEnabled()) {
          if (newPrivileges.length() > 0) {
            newPrivileges.append(", "); //separate entries by commas
          }
          newPrivileges.append("granted=");
          newPrivileges.append(privilege.getName());
        }
      }
      if (grantedPrivilegeList.size() > 0) {
        Principal principal = authorizable.getPrincipal();
        updatedAcl.addAccessControlEntry(principal, grantedPrivilegeList.toArray(new Privilege[grantedPrivilegeList.size()]));
      }

      //if the authorizable is a user (not a group) process any denied privileges
      if (!authorizable.isGroup()) {
        //add a fresh ACE with the denied privileges
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.