Search in sources :

Example 16 with ContentSession

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

the class LdapDefaultLoginModuleTest method testGuestLogin.

/**
     * Login with {@link javax.jcr.GuestCredentials} must succeed and result in
     * an guest session as the SUFFICIENT
     * {@link org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl}
     * handles the guest login (in contrast to the ExternalLoginModule).
     *
     * @throws Exception
     */
@Test
public void testGuestLogin() throws Exception {
    ContentSession cs = login(new GuestCredentials());
    assertEquals(UserConstants.DEFAULT_ANONYMOUS_ID, cs.getAuthInfo().getUserID());
    cs.close();
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) GuestCredentials(javax.jcr.GuestCredentials) Test(org.junit.Test)

Example 17 with ContentSession

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

the class LdapLoginStandaloneTest method testGuestLogin.

@Test
public void testGuestLogin() throws Exception {
    try {
        ContentSession sc = login(new GuestCredentials());
        sc.close();
        fail("Guest login must fail.");
    } catch (LoginException e) {
    // success
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) GuestCredentials(javax.jcr.GuestCredentials) Test(org.junit.Test)

Example 18 with ContentSession

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

the class LdapLoginTestBase method testSyncCreateUser.

@Test
public void testSyncCreateUser() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        Authorizable user = userManager.getAuthorizable(USER_ID);
        assertNotNull(user);
        assertTrue(user.hasProperty(USER_PROP));
        Tree userTree = cs.getLatestRoot().getTree(user.getPath());
        assertFalse(userTree.hasProperty(UserConstants.REP_PASSWORD));
        assertNull(userManager.getAuthorizable(GROUP_DN));
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Example 19 with ContentSession

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

the class LdapLoginTestBase method testNullLogin.

/**
     * Null login must fail.
     *
     * @throws Exception
     * @see org.apache.jackrabbit.oak.security.authentication.ldap.GuestTokenDefaultLdapLoginModuleTest
     */
@Test
public void testNullLogin() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(null);
        fail("Expected null login to 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) Test(org.junit.Test)

Example 20 with ContentSession

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

the class LdapLoginTestBase method testSyncUpdate.

@Test
public void testSyncUpdate() throws Exception {
    // create user upfront in order to test update mode
    Authorizable user = userManager.createUser(USER_ID, null);
    ExternalUser externalUser = idp.getUser(USER_ID);
    user.setProperty("rep:externalId", new ValueFactoryImpl(root, NamePathMapper.DEFAULT).createValue(externalUser.getExternalId().getString()));
    root.commit();
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
        root.refresh();
        user = userManager.getAuthorizable(USER_ID);
        assertNotNull(user);
        assertTrue(user.hasProperty(USER_PROP));
        assertNull(userManager.getAuthorizable(GROUP_DN));
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) 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