Search in sources :

Example 11 with DefaultSyncContext

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

the class PreAuthDefaultExternalLoginModuleTest method testExistingExternalReSync.

@Test
public void testExistingExternalReSync() throws Exception {
    // sync user upfront
    UserManager uMgr = getUserManager(root);
    SyncContext syncContext = new DefaultSyncContext(syncConfig, idp, uMgr, getValueFactory(root));
    SyncResult result = syncContext.sync(idp.getUser(TestIdentityProvider.ID_TEST_USER));
    long lastSynced = result.getIdentity().lastSynced();
    root.commit();
    PreAuthCredentials creds = new PreAuthCredentials(TestIdentityProvider.ID_TEST_USER);
    ContentSession cs = null;
    try {
        // wait until the synced user is expired
        waitUntilExpired(uMgr.getAuthorizable(TestIdentityProvider.ID_TEST_USER, User.class), root, syncConfig.user().getExpirationTime());
        cs = login(creds);
        assertEquals(PreAuthCredentials.PRE_AUTH_DONE, creds.getMessage());
        assertEquals(TestIdentityProvider.ID_TEST_USER, cs.getAuthInfo().getUserID());
        root.refresh();
        User u = getUserManager(root).getAuthorizable(TestIdentityProvider.ID_TEST_USER, User.class);
        assertNotNull(u);
        // user _should_ be re-synced
        assertFalse(lastSynced == DefaultSyncContext.createSyncedIdentity(u).lastSynced());
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) Test(org.junit.Test)

Aggregations

DefaultSyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext)11 Test (org.junit.Test)9 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)5 SyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext)5 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 User (org.apache.jackrabbit.api.security.user.User)3 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)3 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)3 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)3 Tree (org.apache.jackrabbit.oak.api.Tree)2 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)2 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)2 Group (org.apache.jackrabbit.api.security.user.Group)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 Root (org.apache.jackrabbit.oak.api.Root)1 DynamicSyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DynamicSyncContext)1