Search in sources :

Example 11 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class DynamicSyncContextTest method testSyncUserIdExistingGroups.

@Test
public void testSyncUserIdExistingGroups() throws Exception {
    ExternalUser externalUser = idp.getUser(USER_ID);
    DefaultSyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    ctx.sync(externalUser);
    ctx.close();
    Authorizable user = userManager.getAuthorizable(externalUser.getId());
    for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(ref.getId(), Group.class);
        assertTrue(gr.isMember(user));
    }
    syncContext.setForceUserSync(true);
    syncContext.sync(externalUser.getId());
    Authorizable a = userManager.getAuthorizable(USER_ID);
    Tree t = r.getTree(a.getPath());
    assertFalse(t.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
    assertSyncedMembership(userManager, a, externalUser);
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 12 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class DynamicSyncContextTest method testSyncExternalUserExistingGroups.

@Test
public void testSyncExternalUserExistingGroups() throws Exception {
    syncConfig.user().setMembershipNestingDepth(1);
    ExternalUser externalUser = idp.getUser(USER_ID);
    DefaultSyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    ctx.sync(externalUser);
    ctx.close();
    Authorizable a = userManager.getAuthorizable(USER_ID);
    assertSyncedMembership(userManager, a, externalUser);
    syncContext.setForceUserSync(true);
    syncConfig.user().setMembershipExpirationTime(-1);
    syncContext.sync(externalUser);
    Tree t = r.getTree(a.getPath());
    assertFalse(t.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
    assertSyncedMembership(userManager, a, externalUser);
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 13 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncAutoMembership.

@Test
public void testSyncAutoMembership() throws Exception {
    Group gr = createTestGroup();
    syncConfig.user().setAutoMembership(gr.getID());
    SyncResult result = syncCtx.sync(idp.listUsers().next());
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    Authorizable a = userManager.getAuthorizable(result.getIdentity().getId());
    assertTrue(gr.isDeclaredMember(a));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 14 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncDoesNotEnableUsers.

@Test
public void testSyncDoesNotEnableUsers() throws Exception {
    // configure to remove missing users, check that sync does not mess with disabled status
    syncConfig.user().setDisableMissing(false);
    // test sync with 'keepmissing' = false
    syncCtx.setKeepMissing(false);
    ExternalUser user = idp.listUsers().next();
    assertNotNull(user);
    SyncResult result = syncCtx.sync(user);
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    Authorizable authorizable = userManager.getAuthorizable(user.getId());
    assertTrue(authorizable instanceof User);
    User u = (User) authorizable;
    // disable user
    u.disable("disabled locally");
    root.commit();
    // sync
    syncCtx.setForceUserSync(true);
    result = syncCtx.sync(user.getId());
    assertEquals(SyncResult.Status.UPDATE, result.getStatus());
    authorizable = userManager.getAuthorizable(user.getId());
    assertNotNull(authorizable);
    assertTrue(authorizable instanceof User);
    assertTrue(((User) authorizable).isDisabled());
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 15 with Authorizable

use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncPropertiesEmptyMapExistingProps.

@Test
public void testSyncPropertiesEmptyMapExistingProps() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    Value anyValue = valueFactory.createValue("any");
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        a.setProperty(propName, anyValue);
    }
    syncCtx.syncProperties(externalUser, a, ImmutableMap.<String, String>of());
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        assertEquals(anyValue, a.getProperty(propName)[0]);
    }
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)466 Test (org.junit.Test)254 User (org.apache.jackrabbit.api.security.user.User)104 Group (org.apache.jackrabbit.api.security.user.Group)101 UserManager (org.apache.jackrabbit.api.security.user.UserManager)93 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)64 Principal (java.security.Principal)58 Node (javax.jcr.Node)55 RepositoryException (javax.jcr.RepositoryException)55 Query (org.apache.jackrabbit.api.security.user.Query)50 Session (javax.jcr.Session)49 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)45 Value (javax.jcr.Value)29 NodeImpl (org.apache.jackrabbit.core.NodeImpl)29 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)24 SimpleCredentials (javax.jcr.SimpleCredentials)21 HashMap (java.util.HashMap)18 QueryBuilder (org.apache.jackrabbit.api.security.user.QueryBuilder)16