Search in sources :

Example 66 with ContentSession

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

the class ContentRemoteSessionTest method testReadLastRevisionAsString.

@Test
public void testReadLastRevisionAsString() {
    Root root = mock(Root.class);
    AuthInfo authInfo = mock(AuthInfo.class);
    ContentSession session = mock(ContentSession.class);
    doReturn(authInfo).when(session).getAuthInfo();
    doReturn(root).when(session).getLatestRoot();
    ContentRemoteRevisions revisions = mock(ContentRemoteRevisions.class);
    doReturn("id").when(revisions).put(authInfo, root);
    assertEquals("id", createSession(session, revisions).readLastRevision().asString());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 67 with ContentSession

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

the class ContentRemoteSessionTest method testReadRevisionAsString.

@Test
public void testReadRevisionAsString() {
    Root root = mock(Root.class);
    AuthInfo authInfo = mock(AuthInfo.class);
    ContentSession session = mock(ContentSession.class);
    doReturn(authInfo).when(session).getAuthInfo();
    ContentRemoteRevisions revisions = mock(ContentRemoteRevisions.class);
    doReturn(root).when(revisions).get(authInfo, "id");
    assertEquals("id", createSession(session, revisions).readRevision("id").asString());
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 68 with ContentSession

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

the class ContentRemoteSessionTest method testWriteBinaryFailure.

@Test(expected = RuntimeException.class)
public void testWriteBinaryFailure() throws Exception {
    InputStream stream = mock(InputStream.class);
    Root root = mock(Root.class);
    doThrow(IOException.class).when(root).createBlob(stream);
    ContentSession session = mock(ContentSession.class);
    doReturn(root).when(session).getLatestRoot();
    ContentRemoteSession remoteSession = createSession(session);
    remoteSession.writeBinary(stream);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) InputStream(java.io.InputStream) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 69 with ContentSession

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

the class ContentRemoteSessionTest method testReadRevision.

@Test
public void testReadRevision() {
    Root root = mock(Root.class);
    AuthInfo authInfo = mock(AuthInfo.class);
    ContentSession session = mock(ContentSession.class);
    doReturn(authInfo).when(session).getAuthInfo();
    ContentRemoteRevisions revisions = mock(ContentRemoteRevisions.class);
    doReturn(root).when(revisions).get(authInfo, "id");
    assertNotNull(createSession(session, revisions).readRevision("id"));
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 70 with ContentSession

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

the class ExternalLoginModuleAutoMembershipTest method testLoginSyncAutoMembershipSetup1.

@Test
public void testLoginSyncAutoMembershipSetup1() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        // the login must set the existing auto-membership principals to the subject
        Set<Principal> principals = cs.getAuthInfo().getPrincipals();
        assertTrue(principals.contains(setup1.gr.getPrincipal()));
        assertFalse(principals.contains(new PrincipalImpl(NON_EXISTING_NAME)));
        assertFalse(principals.contains(setup2.gr.getPrincipal()));
        assertFalse(principals.contains(setup3.gr.getPrincipal()));
        // however, the existing auto-membership group must _not_ have changed
        // and the test user must not be a stored member of this group.
        root.refresh();
        UserManager uMgr = getUserManager(root);
        User user = uMgr.getAuthorizable(USER_ID, User.class);
        Group gr = uMgr.getAuthorizable(setup1.gr.getID(), Group.class);
        assertFalse(gr.isDeclaredMember(user));
        assertFalse(gr.isMember(user));
    } finally {
        options.clear();
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) 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