Search in sources :

Example 1 with SyncContext

use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext in project jackrabbit-oak by apache.

the class DefaultSyncHandlerTest method testCreateContext.

@Test
public void testCreateContext() throws Exception {
    SyncContext ctx = syncHandler.createContext(idp, userManager, getValueFactory());
    assertTrue(ctx instanceof DefaultSyncContext);
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) Test(org.junit.Test)

Example 2 with SyncContext

use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext in project jackrabbit-oak by apache.

the class DefaultSyncHandlerTest method sync.

private void sync(@Nonnull String id, boolean isGroup) throws Exception {
    SyncContext ctx = syncHandler.createContext(idp, userManager, getValueFactory());
    ExternalIdentity exIdentity = (isGroup) ? idp.getGroup(id) : idp.getUser(id);
    assertNotNull(exIdentity);
    SyncResult res = ctx.sync(exIdentity);
    assertSame(SyncResult.Status.ADD, res.getStatus());
    root.commit();
}
Also used : ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)

Example 3 with SyncContext

use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext in project jackrabbit-oak by apache.

the class AbstractPrincipalTest method before.

@Override
public void before() throws Exception {
    super.before();
    // sync external users into the system using the 2 different sync-context implementations
    Root systemRoot = getSystemRoot();
    SyncContext syncContext = new DynamicSyncContext(syncConfig, idp, getUserManager(systemRoot), getValueFactory(systemRoot));
    syncContext.sync(idp.getUser(USER_ID));
    syncContext.close();
    syncContext = new DefaultSyncContext(syncConfig, idp, getUserManager(systemRoot), getValueFactory(systemRoot));
    syncContext.sync(idp.getUser(TestIdentityProvider.ID_SECOND_USER));
    syncContext.close();
    systemRoot.commit();
    root.refresh();
    principalProvider = createPrincipalProvider();
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) Root(org.apache.jackrabbit.oak.api.Root) DynamicSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DynamicSyncContext) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) DynamicSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DynamicSyncContext)

Example 4 with SyncContext

use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext in project jackrabbit-oak by apache.

the class ExternalLoginModule method syncUser.

/**
     * Initiates synchronization of the external user.
     * @param user the external user
     * @throws SyncException if an error occurs
     */
private void syncUser(@Nonnull ExternalUser user) throws SyncException {
    Root root = getRoot();
    if (root == null) {
        throw new SyncException("Cannot synchronize user. root == null");
    }
    UserManager userManager = getUserManager();
    if (userManager == null) {
        throw new SyncException("Cannot synchronize user. userManager == null");
    }
    int numAttempt = 0;
    while (numAttempt++ < MAX_SYNC_ATTEMPTS) {
        SyncContext context = null;
        try {
            DebugTimer timer = new DebugTimer();
            context = syncHandler.createContext(idp, userManager, new ValueFactoryImpl(root, NamePathMapper.DEFAULT));
            SyncResult syncResult = context.sync(user);
            timer.mark("sync");
            if (root.hasPendingChanges()) {
                root.commit();
                timer.mark("commit");
            }
            debug("syncUser({}) {}, status: {}", user.getId(), timer.getString(), syncResult.getStatus().toString());
            return;
        } catch (CommitFailedException e) {
            log.warn("User synchronization failed during commit: {}. (attempt {}/{})", e.toString(), numAttempt, MAX_SYNC_ATTEMPTS);
            root.refresh();
        } finally {
            if (context != null) {
                context.close();
            }
        }
    }
    throw new SyncException("User synchronization failed during commit after " + MAX_SYNC_ATTEMPTS + " attempts");
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Root(org.apache.jackrabbit.oak.api.Root) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) SyncException(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncException) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 5 with SyncContext

use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext in project jackrabbit-oak by apache.

the class DynamicSyncContextTest method testSyncMembershipForExternalGroup.

@Test
public void testSyncMembershipForExternalGroup() throws Exception {
    // a group that has declaredGroups
    ExternalGroup externalGroup = idp.getGroup("a");
    SyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    ctx.sync(externalGroup);
    ctx.close();
    r.commit();
    Authorizable gr = userManager.getAuthorizable(externalGroup.getId());
    syncContext.syncMembership(externalGroup, gr, 1);
    assertFalse(gr.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
    assertFalse(r.hasPendingChanges());
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

SyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext)8 DefaultSyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext)6 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)4 Root (org.apache.jackrabbit.oak.api.Root)3 Test (org.junit.Test)3 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 DebugTimer (org.apache.jackrabbit.oak.commons.DebugTimer)2 ValueFactoryImpl (org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl)2 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)2 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)2 SyncException (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncException)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)1 DynamicSyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DynamicSyncContext)1