public void setApplicationContext(final ApplicationContext applicationContext)
     throws BeansException {
   manager =
       (IBackingRepositoryLifecycleManager)
           applicationContext.getBean("backingRepositoryLifecycleManager");
   SessionFactory jcrSessionFactory =
       (SessionFactory) applicationContext.getBean("jcrSessionFactory");
   testJcrTemplate = new JcrTemplate(jcrSessionFactory);
   testJcrTemplate.setAllowCreate(true);
   testJcrTemplate.setExposeNativeSession(true);
   repositoryAdminUsername = (String) applicationContext.getBean("repositoryAdminUsername");
   authenticatedAuthorityName =
       (String) applicationContext.getBean("singleTenantAuthenticatedAuthorityName");
   adminAuthorityName = (String) applicationContext.getBean("singleTenantAdminAuthorityName");
   sysAdminAuthorityName = (String) applicationContext.getBean("superAdminAuthorityName");
   sysAdminUserName = (String) applicationContext.getBean("superAdminUserName");
   authorizationPolicy = (IAuthorizationPolicy) applicationContext.getBean("authorizationPolicy");
   roleBindingDaoTarget =
       (IRoleAuthorizationPolicyRoleBindingDao)
           applicationContext.getBean("roleAuthorizationPolicyRoleBindingDaoTarget");
   tenantManager = (ITenantManager) applicationContext.getBean("tenantMgrTxn");
   repositoryFileDao = (IRepositoryFileDao) applicationContext.getBean("repositoryFileDao");
   userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
   tenantedUserNameUtils =
       (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedUserNameUtils");
   tenantedRoleNameUtils =
       (ITenantedPrincipleNameResolver) applicationContext.getBean("tenantedRoleNameUtils");
   repo = (IUnifiedRepository) applicationContext.getBean("unifiedRepository");
   TestPrincipalProvider.userRoleDao = (IUserRoleDao) applicationContext.getBean("userRoleDaoTxn");
   TestPrincipalProvider.adminCredentialsStrategy =
       (CredentialsStrategy) applicationContext.getBean("jcrAdminCredentialsStrategy");
   TestPrincipalProvider.repository = (Repository) applicationContext.getBean("jcrRepository");
 }
  @Override
  public List<RepositorySearchResult> search(final String query) {
    jcrTemplate.execute(
        new JcrCallback() {
          @Override
          public Object doInJcr(final Session session) throws RepositoryException, IOException {
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            String expression = "SELECT * FROM pho:File where name like '" + query + "'";
            String language = Query.JCR_SQL2;
            Query query = queryManager.createQuery(expression, language);

            QueryResult result = query.execute();

            javax.jcr.NodeIterator nodeIterator = result.getNodes();

            while (nodeIterator.hasNext()) {
              Node node = nodeIterator.nextNode();
            }

            return null;
          }
        });

    return null;
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public List<RepositoryFileAce> getEffectiveAces(
      final Serializable id, final boolean forceEntriesInheriting) {
    return (List<RepositoryFileAce>)
        jcrTemplate.execute(
            new JcrCallback() {
              public Object doInJcr(final Session session) throws RepositoryException, IOException {
                Node node = session.getNodeByIdentifier(id.toString());

                if (node == null) {
                  throw new RepositoryException(
                      Messages.getInstance()
                          .getString(
                              "JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND",
                              id.toString())); // $NON-NLS-1$
                }

                // consult the parent node's effective policy if force is true and parent is not
                // null
                if (forceEntriesInheriting
                    && session.getNodeByIdentifier(id.toString()).getParent() != null) {
                  node = node.getParent();
                }

                String absPath = node.getPath();

                AccessControlPolicy[] acPolicies =
                    session.getAccessControlManager().getEffectivePolicies(absPath);
                // logic assumes policies are ordered from leaf to root
                for (AccessControlPolicy policy : acPolicies) {
                  Assert.isTrue(policy instanceof AccessControlList);
                  AccessControlList acList = ((AccessControlList) policy);
                  if (!isEntriesInheriting(session, absPath, acList)) {
                    List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>();
                    AccessControlEntry[] acEntries = acList.getAccessControlEntries();
                    List<AccessControlEntry> cleanedAcEntries =
                        JcrRepositoryFileAclUtils.removeAclMetadata(Arrays.asList(acEntries));
                    for (AccessControlEntry acEntry : cleanedAcEntries) {
                      aces.add(toAce(session, acEntry));
                    }
                    return aces;
                  }
                }

                // none are entriesInheriting=false so root aces are the effective aces
                AccessControlList acList = (AccessControlList) acPolicies[acPolicies.length - 1];
                List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>();
                AccessControlEntry[] acEntries = acList.getAccessControlEntries();
                List<AccessControlEntry> cleanedAcEntries =
                    JcrRepositoryFileAclUtils.removeAclMetadata(Arrays.asList(acEntries));
                for (AccessControlEntry acEntry : cleanedAcEntries) {
                  aces.add(toAce(session, acEntry));
                }
                return aces;
              }
            });
  }
 public RepositoryFileAcl getAcl(final Serializable id) {
   return (RepositoryFileAcl)
       jcrTemplate.execute(
           new JcrCallback() {
             public Object doInJcr(final Session session) throws RepositoryException, IOException {
               PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
               return toAcl(session, pentahoJcrConstants, id);
             }
           });
 }
 protected RepositoryFileAcl getParentAcl(final Serializable id) {
   return (RepositoryFileAcl)
       jcrTemplate.execute(
           new JcrCallback() {
             public Object doInJcr(final Session session) throws RepositoryException, IOException {
               PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
               Node node = session.getNodeByIdentifier(id.toString());
               if (!node.getParent().isSame(session.getRootNode())) {
                 return toAcl(session, pentahoJcrConstants, node.getParent().getIdentifier());
               } else {
                 return null;
               }
             }
           });
 }
 public RepositoryFileAcl createAcl(final Serializable fileId, final RepositoryFileAcl acl) {
   return (RepositoryFileAcl)
       jcrTemplate.execute(
           new JcrCallback() {
             public Object doInJcr(final Session session) throws RepositoryException, IOException {
               PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
               Node node = session.getNodeByIdentifier(fileId.toString());
               String absPath = node.getPath();
               AccessControlManager acMgr = session.getAccessControlManager();
               AccessControlList acList = getAccessControlList(acMgr, absPath);
               acMgr.setPolicy(absPath, acList);
               return internalUpdateAcl(session, pentahoJcrConstants, fileId, acl);
             }
           });
 }
 public RepositoryFileAcl updateAcl(final RepositoryFileAcl acl) {
   return (RepositoryFileAcl)
       jcrTemplate.execute(
           new JcrCallback() {
             public Object doInJcr(final Session session) throws RepositoryException, IOException {
               PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
               JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(
                   session, pentahoJcrConstants, acl.getId());
               RepositoryFileAcl updatedAcl =
                   internalUpdateAcl(session, pentahoJcrConstants, acl.getId(), acl);
               JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(
                   session, pentahoJcrConstants, acl.getId(), null, null, true);
               return updatedAcl;
             }
           });
 }
 /** {@inheritDoc} */
 public boolean hasAccess(
     final String relPath, final EnumSet<RepositoryFilePermission> permissions) {
   return (Boolean)
       jcrTemplate.execute(
           new JcrCallback() {
             public Object doInJcr(final Session session) throws RepositoryException, IOException {
               Privilege[] privs =
                   permissionConversionHelper.pentahoPermissionsToPrivileges(session, permissions);
               try {
                 String absPath = pathConversionHelper.relToAbs(relPath);
                 return session.getAccessControlManager().hasPrivileges(absPath, privs);
               } catch (PathNotFoundException e) {
                 // never throw an exception if the path does not exist; just return false
                 return false;
               }
             }
           });
 }
 private void setAclManagement() {
   testJcrTemplate.execute(
       new JcrCallback() {
         @Override
         public Object doInJcr(Session session) throws IOException, RepositoryException {
           PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
           Workspace workspace = session.getWorkspace();
           PrivilegeManager privilegeManager =
               ((JackrabbitWorkspace) workspace).getPrivilegeManager();
           try {
             privilegeManager.getPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE());
           } catch (AccessControlException ace) {
             privilegeManager.registerPrivilege(
                 pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false, new String[0]);
           }
           session.save();
           return null;
         }
       });
 }
  public RepositoryFileAcl createAcl(final Serializable fileId, final RepositoryFileAcl acl) {
    if (isKioskEnabled()) {
      throw new RuntimeException(
          Messages.getInstance()
              .getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); // $NON-NLS-1$
    }

    return (RepositoryFileAcl)
        jcrTemplate.execute(
            new JcrCallback() {
              public Object doInJcr(final Session session) throws RepositoryException, IOException {
                PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
                Node node = session.getNodeByIdentifier(fileId.toString());
                String absPath = node.getPath();
                AccessControlManager acMgr = session.getAccessControlManager();
                AccessControlList acList = getAccessControlList(acMgr, absPath);
                acMgr.setPolicy(absPath, acList);
                return internalUpdateAcl(session, pentahoJcrConstants, fileId, acl);
              }
            });
  }