Search in sources :

Example 51 with ContentSession

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

the class ContentRemoteSessionTest method testWriteBinary.

@Test
public void testWriteBinary() throws Exception {
    Blob blob = mock(Blob.class);
    InputStream stream = mock(InputStream.class);
    Root root = mock(Root.class);
    doReturn(blob).when(root).createBlob(stream);
    ContentSession session = mock(ContentSession.class);
    doReturn(root).when(session).getLatestRoot();
    ContentRemoteBinaries binaries = mock(ContentRemoteBinaries.class);
    doReturn("id").when(binaries).put(blob);
    ContentRemoteSession remoteSession = createSession(session, binaries);
    assertEquals("id", remoteSession.writeBinary(stream).asString());
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) Root(org.apache.jackrabbit.oak.api.Root) InputStream(java.io.InputStream) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 52 with ContentSession

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

the class L3_LoginModuleTest method testLogin.

@Test
public void testLogin() throws LoginException, NoSuchWorkspaceException, IOException {
    ContentSession contentSession = login(new GuestCredentials());
    contentSession.close();
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 53 with ContentSession

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

the class LoginModuleImplTest method testGuestLogin.

@Test
public void testGuestLogin() throws Exception {
    try (ContentSession cs = login(new GuestCredentials())) {
        AuthInfo authInfo = cs.getAuthInfo();
        String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
        assertEquals(anonymousID, authInfo.getUserID());
    }
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 54 with ContentSession

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

the class LoginModuleImplTest method testUserLoginIsCaseInsensitive.

@Test
public void testUserLoginIsCaseInsensitive() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        cs = login(new SimpleCredentials(USER_ID_CASED, USER_PW.toCharArray()));
        AuthInfo authInfo = cs.getAuthInfo();
        UserManager userMgr = getUserManager(root);
        Authorizable auth = userMgr.getAuthorizable(authInfo.getUserID());
        assertNotNull(auth);
        assertTrue(auth.getID().equalsIgnoreCase(USER_ID_CASED));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 55 with ContentSession

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

the class LoginModuleImplTest method testUnknownUserLogin.

@Test
public void testUnknownUserLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials("unknown", "".toCharArray()));
        fail("Unknown user must not be able to login");
    } 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