Search in sources :

Example 86 with ContentSession

use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.

the class CugOakTest method runTest.

@Override
protected void runTest() throws Exception {
    boolean logout = false;
    ContentSession readSession;
    if (singleSession) {
        readSession = cs;
    } else {
        readSession = Subject.doAs(subject, new PrivilegedAction<ContentSession>() {

            @Override
            public ContentSession run() {
                try {
                    return contentRepository.login(null, null);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
        logout = true;
    }
    Root root = readSession.getLatestRoot();
    try {
        int nodeCnt = 0;
        int propertyCnt = 0;
        int noAccess = 0;
        int size = allPaths.size();
        long start = System.currentTimeMillis();
        for (int i = 0; i < itemsToRead; i++) {
            double rand = size * Math.random();
            int index = (int) Math.floor(rand);
            String path = allPaths.get(index);
            TreeLocation treeLocation = TreeLocation.create(root, path);
            if (treeLocation.exists()) {
                PropertyState ps = treeLocation.getProperty();
                if (ps != null) {
                    propertyCnt++;
                } else {
                    nodeCnt++;
                }
            } else {
                noAccess++;
            }
        }
        long end = System.currentTimeMillis();
        if (doReport) {
            System.out.println("ContentSession " + cs.getAuthInfo().getUserID() + " reading " + (itemsToRead - noAccess) + " (Tree: " + nodeCnt + "; PropertyState: " + propertyCnt + ") completed in " + (end - start));
        }
    } finally {
        if (logout) {
            readSession.close();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) PrivilegedAction(java.security.PrivilegedAction) TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 87 with ContentSession

use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.

the class OakTest method testWithDefaultWorkspaceName.

@Test
public void testWithDefaultWorkspaceName() throws Exception {
    ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
    String[] valid = new String[] { null, "test" };
    for (String wspName : valid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            assertEquals("test", cs.getWorkspaceName());
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
    String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
    for (String wspName : invalid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            fail("invalid workspace nam");
        } catch (NoSuchWorkspaceException e) {
        // success
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Example 88 with ContentSession

use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.

the class OakTest method checkMissingStrategySetting.

@Test(expected = CommitFailedException.class)
public void checkMissingStrategySetting() throws Exception {
    Whiteboard wb = new DefaultWhiteboard();
    WhiteboardIndexEditorProvider wbProvider = new WhiteboardIndexEditorProvider();
    wbProvider.start(wb);
    Registration r1 = wb.register(IndexEditorProvider.class, new PropertyIndexEditorProvider(), null);
    Registration r2 = wb.register(IndexEditorProvider.class, new ReferenceEditorProvider(), null);
    Oak oak = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(wb).with(wbProvider).withFailOnMissingIndexProvider();
    ContentRepository repo = oak.createContentRepository();
    ContentSession cs = repo.login(null, null);
    Root root = cs.getLatestRoot();
    Tree t = root.getTree("/");
    t.setProperty("foo", "u1", Type.REFERENCE);
    r1.unregister();
    root.commit();
    cs.close();
    ((Closeable) repo).close();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) WhiteboardIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.WhiteboardIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Example 89 with ContentSession

use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.

the class DefaultConflictHandlerTheirsTest method setUp.

@Before
public void setUp() throws CommitFailedException {
    ContentSession session = new Oak().with(new OpenSecurityProvider()).with(DefaultConflictHandler.THEIRS).createContentSession();
    // Add test content
    Root root = session.getLatestRoot();
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    tree.setProperty("b", 2);
    tree.setProperty("c", 3);
    tree.addChild("x");
    tree.addChild("y");
    tree.addChild("z");
    root.commit();
    ourRoot = session.getLatestRoot();
    theirRoot = session.getLatestRoot();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Oak(org.apache.jackrabbit.oak.Oak) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Before(org.junit.Before)

Example 90 with ContentSession

use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.

the class Jackrabbit2ConfigurationTest method testTokenCreationAndImpersonation.

@Test
public void testTokenCreationAndImpersonation() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
        sc.setAttribute(".token", "");
        ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
        cs = login(ic);
        Object token = sc.getAttribute(".token").toString();
        assertNotNull(token);
        TokenCredentials tc = new TokenCredentials(token.toString());
        cs.close();
        cs = login(tc);
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Principal(java.security.Principal) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

ContentSession (org.apache.jackrabbit.oak.api.ContentSession)146 Test (org.junit.Test)132 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 SimpleCredentials (javax.jcr.SimpleCredentials)60 Root (org.apache.jackrabbit.oak.api.Root)43 LoginException (javax.security.auth.login.LoginException)35 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)26 Tree (org.apache.jackrabbit.oak.api.Tree)25 UserManager (org.apache.jackrabbit.api.security.user.UserManager)19 User (org.apache.jackrabbit.api.security.user.User)17 PermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider)15 GuestCredentials (javax.jcr.GuestCredentials)13 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)12 Principal (java.security.Principal)10 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)10 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)9 Group (org.apache.jackrabbit.api.security.user.Group)8 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)8 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)7 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)6