Search in sources :

Example 56 with ContentSession

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

the class LoginModuleImplTest method testNullLogin.

@Test
public void testNullLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(null);
        fail("Null login should fail");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 57 with ContentSession

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

the class LoginModuleImplTest method testSelfImpersonation.

@Test
public void testSelfImpersonation() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
        cs = login(sc);
        AuthInfo authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
        cs.close();
        sc = new SimpleCredentials(USER_ID, new char[0]);
        ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo);
        cs = login(ic);
        authInfo = cs.getAuthInfo();
        assertEquals(USER_ID, authInfo.getUserID());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 58 with ContentSession

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

the class LoginModuleImplTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() throws Exception {
    String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
    UserManager userMgr = getUserManager(root);
    // verify initial user-content looks like expected
    Authorizable anonymous = userMgr.getAuthorizable(anonymousID);
    assertNotNull(anonymous);
    assertFalse(root.getTree(anonymous.getPath()).hasProperty(UserConstants.REP_PASSWORD));
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(anonymousID, new char[0]));
        fail("Login with anonymousID should fail since the initial setup doesn't provide a password.");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 59 with ContentSession

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

the class CugEvaluationTest method testReadAcl2.

@Test
public void testReadAcl2() throws Exception {
    ContentSession cs = createTestSession2();
    try {
        Root r = cs.getLatestRoot();
        assertTrue(r.getTree("/content/rep:policy").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 60 with ContentSession

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

the class CugEvaluationTest method testWriteCug.

@Test
public void testWriteCug() throws Exception {
    ContentSession cs = createTestSession2();
    Root r = cs.getLatestRoot();
    try {
        // modify the existing cug
        Tree tree = r.getTree("/content/a/rep:cugPolicy");
        tree.setProperty(REP_PRINCIPAL_NAMES, ImmutableList.of(EveryonePrincipal.NAME, testGroupPrincipal.getName()), Type.STRINGS);
        r.commit();
        fail();
    } catch (CommitFailedException e) {
        assertTrue(e.isAccessViolation());
    } finally {
        r.refresh();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) 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