Package javax.jcr

Examples of javax.jcr.Session


        // TODO: improve. avoid round trip over node access.
        return getNode(nodeId, sessionInfo).getPath();
    }

    private Property getProperty(PropertyId id, SessionInfoImpl sessionInfo) throws ItemNotFoundException, PathNotFoundException, RepositoryException {
        Session session = sessionInfo.getSession();
        Node n;
        if (id.getUniqueID() != null) {
            n = session.getNodeByIdentifier(id.getUniqueID());
        } else {
            n = session.getRootNode();
        }
        Path path = id.getPath();
        String jcrPath = sessionInfo.getNamePathResolver().getJCRPath(path);
        if (path.isAbsolute()) {
            jcrPath = jcrPath.substring(1, jcrPath.length());
View Full Code Here


            Repository repository = JcrUtils.getRepository(uri);

            Context context = new ContextBase();
            CommandHelper.setRepository(context, repository, uri);
            try {
                Session session = repository.login();
                CommandHelper.setSession(context, session);
                CommandHelper.setCurrentNode(context, session.getRootNode());
            } catch (RepositoryException ignore) {
                // anonymous login not possible
            }

            new JcrClient(context).runInteractive();
View Full Code Here

        */

        // make sure the 'rep:policy' node has been created.
        assertTrue(superuser.itemExists(tmpl.getPath() + "/rep:policy"));

        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        // test: MODIFY_AC granted at 'path'
        assertTrue(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_MODIFY_ACCESS_CONTROL)));

        // test if testuser can READ access control on the path and on the
        // entire subtree that gets the policy inherited.
        AccessControlPolicy[] policies = testAcMgr.getPolicies(path);
        testAcMgr.getEffectivePolicies(path);
        testAcMgr.getEffectivePolicies(childNPath);

        // test: READ_AC privilege does not apply outside of the tree.
        try {
            testAcMgr.getPolicies(siblingPath);
            fail("READ_AC privilege must not apply outside of the tree it has applied to.");
        } catch (AccessDeniedException e) {
            // success
        }

        // test: MODIFY_AC privilege does not apply outside of the tree.
        try {
            testAcMgr.setPolicy(siblingPath, policies[0]);
            fail("MODIFY_AC privilege must not apply outside of the tree it has applied to.");
        } catch (AccessDeniedException e) {
            // success
        }

        // test if testuser can modify AC-items
        // 1) add an ac-entry
        ACLTemplate acl = (ACLTemplate) policies[0];
        acl.addAccessControlEntry(testUser.getPrincipal(), privilegesFromName(PrivilegeRegistry.REP_WRITE));
        testAcMgr.setPolicy(path, acl);
        testSession.save();

        assertTrue(testAcMgr.hasPrivileges(path,
                privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES)));

        // 2) remove the policy
        testAcMgr.removePolicy(path, policies[0]);
        testSession.save();

        // Finally: testuser removed the policy that granted him permission
        // to modify the AC content. Since testuser removed the policy, it's
        // privileges must be gone again...
        try {
View Full Code Here

        it = acMgr.getApplicablePolicies(childNPath);
        assertTrue(it.hasNext());
    }

    public void testInheritance2() throws RepositoryException, NotExecutableException {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();

        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        // give jcr:write privilege on 'path' and withdraw them on 'childNPath'
        Privilege[] privileges = privilegesFromNames(new String[] {Privilege.JCR_WRITE});
        givePrivileges(path, privileges, getRestrictions(superuser, path));
        withdrawPrivileges(childNPath, privileges, getRestrictions(superuser, path));

        /*
        since evaluation respects inheritance through the node
        hierarchy, the jcr:write privilege must not be granted at childNPath
        */
        assertFalse(testAcMgr.hasPrivileges(childNPath, privileges));

        /*
         ... same for permissions at 'childNPath'
         */
        String actions = Session.ACTION_SET_PROPERTY + "," + Session.ACTION_REMOVE + "," + Session.ACTION_ADD_NODE;

        String nonExistingItemPath = childNPath + "/anyItem";
        assertFalse(testSession.hasPermission(nonExistingItemPath, actions));

        // yet another level in the hierarchy
        Node grandChild = superuser.getNode(childNPath).addNode(nodeName3);
        superuser.save();
        String gcPath = grandChild.getPath();

        // grant write privilege again
        givePrivileges(gcPath, privileges, getRestrictions(superuser, path));
        assertTrue(testAcMgr.hasPrivileges(gcPath, privileges));
        assertTrue(testSession.hasPermission(gcPath + "/anyProp", Session.ACTION_SET_PROPERTY));
        // however: removing the grand-child nodes must not be allowed as
        // remove_child_node privilege is missing on the direct ancestor.
        assertFalse(testSession.hasPermission(gcPath, Session.ACTION_REMOVE));
    }
View Full Code Here

        allow READ/WRITE privilege for testUser at 'childNPath'
        */
        givePrivileges(childNPath, testUser.getPrincipal(), privileges, getRestrictions(superuser, childNPath));


        Session testSession = getTestSession();

        assertFalse(testSession.nodeExists(path));

        // reading the node and it's definition must succeed.
        assertTrue(testSession.nodeExists(childNPath));
        Node n = testSession.getNode(childNPath);

        n.addNode("someChild");
        n.save();
    }
View Full Code Here

            if (multiValue) {
                // converting single into multi value props requires deleting it first
                removeIfSingleValueProperty(parent, prop);
            }

            Session s = parent.resource.getResourceResolver().adaptTo(Session.class);
            if (s != null) {
                final ValueFactory valFac = s.getValueFactory();
                if (type == PropertyType.DATE) {
                    if (storeAsDate(parent, prop.getName(), values, multiValue, valFac)) {
                        return;
                    }
                } else if (isReferencePropertyType(type)) {
View Full Code Here

    }

    public MockedResourceResolver(SlingRepository repositoryOrNull) throws RepositoryException {
      if (repositoryOrNull==null) {
        this.repository = RepositoryProvider.instance().getRepository();
        Session adminSession = null;
        try {
            adminSession = this.repository.loginAdministrative(null);
                RepositoryUtil.registerSlingNodeTypes(adminSession);
        } catch ( final IOException ioe ) {
            throw new RepositoryException(ioe);
        } finally {
            if ( adminSession != null ) {
                adminSession.logout();
            }
        }
      } else {
        this.repository = repositoryOrNull;
      }
View Full Code Here

    public String map(HttpServletRequest request, String resourcePath) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public Resource getResource(String path) {
        Session session;
        try {
            session = getSession();
            session.getNode(path);
        } catch (PathNotFoundException e) {
            return null;
        } catch (RepositoryException e) {
            throw new RuntimeException("RepositoryException: " + e, e);
        }
View Full Code Here

    public CompilationResult compile(final String[] srcFiles, final Options compilerOptions)
    throws Exception {
        // make sure we have options
        final Options options = (compilerOptions == null ? new Options() : new Options(compilerOptions));
        // open session
        Session session = null;
        try {
            session = this.repository.loginAdministrative(null);

            // create compilation units
            CompilationUnit[] units = new CompilationUnit[srcFiles.length];
            for (int i = 0; i < units.length; i++) {
                units[i] = createCompileUnit(srcFiles[i], session);
            }

            // and compile
            return mapResult(compiler.compile(units, options), srcFiles, units);
        } finally {
            if ( session != null ) {
                session.logout();
            }
        }
    }
View Full Code Here

        osgiMock.addService(announcementRegistry);
        osgiMock.addService(votingHandler);

        resourceResolver = resourceResolverFactory
                .getAdministrativeResourceResolver(null);
        Session session = resourceResolver.adaptTo(Session.class);
        observationManager = session.getWorkspace()
                .getObservationManager();

        observationListener =
                new EventListener() {
View Full Code Here

TOP

Related Classes of javax.jcr.Session

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.