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);
}
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();
}
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();
}
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");
}
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());
}
Aggregations