Package org.apache.jackrabbit.api.jsr283.query.qom

Examples of org.apache.jackrabbit.api.jsr283.query.qom.EquiJoinConditionTest


            try {
                SessionImpl sImpl = (SessionImpl) session;
                SessionImpl s = (SessionImpl) sImpl.createSession(workspaceName);
                return new UserManagerImpl(s, adminId);
            } catch (NoSuchWorkspaceException e) {
                throw new AccessControlException("Cannot build UserManager for " + session.getUserID(), e);
            }
        } else {
            throw new RepositoryException("Internal error: SessionImpl expected.");
        }
    }
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

        // if the given node is access-controlled, construct a new ACL and add
        // it to the list
        if (isAccessControlled(node)) {
            // build acl for the access controlled node
            NodeImpl aclNode = node.getNode(N_POLICY);
            AccessControlList acl = systemEditor.getACL(aclNode);
            acls.add(new UnmodifiableAccessControlList(acl));
        }
        // then, recursively look for access controlled parents up the hierarchy.
        if (!rootNodeId.equals(node.getId())) {
            NodeImpl parentNode = (NodeImpl) node.getParent();
View Full Code Here

        //load the principalIds array into a set for quick lookup below
      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);
      } catch (RepositoryException re) {
        throw new RepositoryException("Failed to delete access control.", re);
      }
        }
  }
View Full Code Here

    }

    private static void changeReadPermission(Principal principal, Node n, boolean allowRead) throws RepositoryException, NotExecutableException {
        SessionImpl s = (SessionImpl) n.getSession();
        JackrabbitAccessControlList acl = null;
        AccessControlManager acMgr = s.getAccessControlManager();
        AccessControlPolicyIterator it = acMgr.getApplicablePolicies(n.getPath());
        while (it.hasNext()) {
            AccessControlPolicy acp = it.nextAccessControlPolicy();
            if (acp instanceof JackrabbitAccessControlList) {
                acl = (JackrabbitAccessControlList) acp;
                break;
            }
        }
        if (acl == null) {
            AccessControlPolicy[] acps = acMgr.getPolicies(n.getPath());
            for (int i = 0; i < acps.length; i++) {
                if (acps[i] instanceof JackrabbitAccessControlList) {
                    acl = (JackrabbitAccessControlList) acps[i];
                    break;
                }
            }
        }

        if (acl != null) {
            acl.addEntry(principal, new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_READ)}, allowRead);
            acMgr.setPolicy(n.getPath(), acl);
            s.save();
        } else {
            // no JackrabbitAccessControlList found.
            throw new NotExecutableException();
        }
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);
        }

        session.save();
View Full Code Here

            throw new ServletException(throwable);
        }
  }

  private AccessControlEntry[] getDeclaredAccessControlEntries(Session session, String absPath) throws RepositoryException {
    AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
    AccessControlPolicy[] policies = accessControlManager.getPolicies(absPath);
    for (AccessControlPolicy accessControlPolicy : policies) {
      if (accessControlPolicy instanceof AccessControlList) {
        AccessControlEntry[] accessControlEntries = ((AccessControlList)accessControlPolicy).getAccessControlEntries();
        return accessControlEntries;
      }
View Full Code Here

   * @param absPath the path to get the privileges for
   * @return array of Privileges
   * @throws RepositoryException
   */
  public Privilege [] getSupportedPrivileges(Session session, String absPath) throws RepositoryException {
    AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
    Privilege[] supportedPrivileges = accessControlManager.getSupportedPrivileges(absPath);
    return supportedPrivileges;
  }
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
        List<Privilege> deniedPrivilegeList = new ArrayList<Privilege>();
        for (String name : deniedPrivilegeNames) {
          if (name.length() == 0) {
            continue; //empty, skip it.
          }
          Privilege privilege = accessControlManager.privilegeFromName(name);
          deniedPrivilegeList.add(privilege);

          if (log.isDebugEnabled()) {
            if (newPrivileges.length() > 0) {
              newPrivileges.append(", "); //separate entries by commas
            }
            newPrivileges.append("denied=");
            newPrivileges.append(privilege.getName());
          }
        }
        if (deniedPrivilegeList.size() > 0) {
          Principal principal = authorizable.getPrincipal();
          AccessControlUtil.addEntry(updatedAcl, principal, deniedPrivilegeList.toArray(new Privilege[deniedPrivilegeList.size()]), false);
        }
      }

      accessControlManager.setPolicy(resourcePath, updatedAcl);
      if (session.hasPendingChanges()) {
        session.save();
      }

      if (log.isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.api.jsr283.query.qom.EquiJoinConditionTest

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.