Search in sources :

Example 96 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 97 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 98 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 99 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)

Example 100 with ContentSession

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

the class Jackrabbit2ConfigurationTest method testInvalidSimpleCredentialsWithAttribute.

@Test
public void testInvalidSimpleCredentialsWithAttribute() throws Exception {
    ContentSession cs = null;
    try {
        SimpleCredentials sc = new SimpleCredentials("test", new char[0]);
        sc.setAttribute(".token", "");
        cs = login(sc);
        fail("Invalid simple credentials login should fail");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) 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