Search in sources :

Example 81 with ContentSession

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

the class ExternalLoginModuleTest method testSyncCreateGroup.

@Test
public void testSyncCreateGroup() throws Exception {
    UserManager userManager = getUserManager(root);
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        root.refresh();
        for (String id : new String[] { "a", "b", "c" }) {
            assertNotNull(userManager.getAuthorizable(id));
        }
        for (String id : new String[] { "aa", "aaa" }) {
            assertNull(userManager.getAuthorizable(id));
        }
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 82 with ContentSession

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

the class ExternalLoginModuleFactoryTest method testSyncCreateUser.

//~-------------------------------------------------------------< tests >---
@Test
public void testSyncCreateUser() throws Exception {
    setUpJaasFactoryWithInjection();
    UserManager userManager = getUserManager(root);
    ContentSession cs = null;
    try {
        assertNull(userManager.getAuthorizable(USER_ID));
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        root.refresh();
        Authorizable a = userManager.getAuthorizable(USER_ID);
        assertNotNull(a);
        ExternalUser user = idp.getUser(USER_ID);
        for (String prop : user.getProperties().keySet()) {
            assertTrue(a.hasProperty(prop));
        }
        assertEquals(TEST_CONSTANT_PROPERTY_VALUE, a.getProperty(TEST_CONSTANT_PROPERTY_NAME)[0].getString());
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Test(org.junit.Test)

Example 83 with ContentSession

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

the class TokenExternalLoginModuleTest method testTokenLogin.

@Test
public void testTokenLogin() throws Exception {
    Credentials creds = createTestCredentials();
    assertTrue(credentialsSupport.setAttributes(creds, ImmutableMap.<String, Object>of(".token", "")));
    String expectedUserId = credentialsSupport.getUserId(creds);
    ContentSession cs = login(creds);
    try {
        String token = credentialsSupport.getAttributes(creds).get(".token").toString();
        cs.close();
        cs = login(new TokenCredentials(token));
        assertEquals(expectedUserId, cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Credentials(javax.jcr.Credentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 84 with ContentSession

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

the class CugEvaluationTest method testReadCug2.

@Test
public void testReadCug2() throws Exception {
    ContentSession cs = createTestSession2();
    try {
        Root r = cs.getLatestRoot();
        assertTrue(r.getTree("/content/a/rep:cugPolicy").exists());
        assertFalse(r.getTree("/content2/rep:cugPolicy").exists());
    } finally {
        cs.close();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 85 with ContentSession

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

the class CugEvaluationTest method testWrite2.

@Test
public void testWrite2() throws Exception {
    ContentSession cs = createTestSession2();
    Root r = cs.getLatestRoot();
    try {
        PermissionProvider pp = createPermissionProvider(cs);
        assertTrue(pp.isGranted(root.getTree("/content/writeTest"), null, Permissions.ADD_NODE));
        assertTrue(pp.isGranted(root.getTree("/content/a/b/c/writeTest"), null, Permissions.ADD_NODE));
        List<String> paths = ImmutableList.of("/content", "/content/a/b/c");
        for (String p : paths) {
            NodeUtil content = new NodeUtil(r.getTree(p));
            content.addChild("writeTest", NT_OAK_UNSTRUCTURED);
            r.commit();
        }
    } finally {
        r.refresh();
        cs.close();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) 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