use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult in project jackrabbit-oak by apache.
the class DynamicSyncContextTest method testSyncExternalGroupVerifyStatus.
@Test
public void testSyncExternalGroupVerifyStatus() throws Exception {
ExternalGroup gr = idp.listGroups().next();
SyncResult result = syncContext.sync(gr);
assertEquals(SyncResult.Status.NOP, result.getStatus());
result = syncContext.sync(gr);
assertEquals(SyncResult.Status.NOP, result.getStatus());
syncContext.setForceGroupSync(true);
result = syncContext.sync(gr);
assertEquals(SyncResult.Status.NOP, result.getStatus());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult 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.SyncResult in project jackrabbit-oak by apache.
the class Delegatee method syncExternalUsers.
/**
* @see SynchronizationMBean#syncExternalUsers(String[])
*/
@Nonnull
String[] syncExternalUsers(@Nonnull String[] externalIds) {
List<String> list = new ArrayList<String>();
context.setForceGroupSync(true).setForceUserSync(true);
List<SyncResult> results = new ArrayList<SyncResult>(batchSize);
for (String externalId : externalIds) {
ExternalIdentityRef ref = ExternalIdentityRef.fromString(externalId);
if (!idp.getName().equals(ref.getProviderName())) {
results.add(new DefaultSyncResultImpl(new DefaultSyncedIdentity(ref.getId(), ref, false, -1), SyncResult.Status.FOREIGN));
} else {
try {
ExternalIdentity id = idp.getIdentity(ref);
if (id != null) {
results = syncUser(id, results, list);
} else {
results.add(new DefaultSyncResultImpl(new DefaultSyncedIdentity("", ref, false, -1), SyncResult.Status.NO_SUCH_IDENTITY));
}
} catch (ExternalIdentityException e) {
log.warn("error while fetching the external identity {}", externalId, e);
results.add(new ErrorSyncResult(ref, e));
}
}
}
commit(list, results, NO_BATCH_SIZE);
return list.toArray(new String[list.size()]);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult in project jackrabbit-oak by apache.
the class Delegatee method syncAllExternalUsers.
/**
* @see SynchronizationMBean#syncAllExternalUsers()
*/
@Nonnull
String[] syncAllExternalUsers() {
List<String> list = new ArrayList<String>();
context.setForceGroupSync(true).setForceUserSync(true);
try {
List<SyncResult> results = new ArrayList<SyncResult>(batchSize);
Iterator<ExternalUser> it = idp.listUsers();
while (it.hasNext()) {
ExternalUser user = it.next();
results = syncUser(user, results, list);
}
commit(list, results, NO_BATCH_SIZE);
return list.toArray(new String[list.size()]);
} catch (ExternalIdentityException e) {
throw new SyncRuntimeException("Unable to retrieve external users", e);
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult in project jackrabbit-oak by apache.
the class DefaultSyncContextTest method sync.
/**
* Test utility method to synchronize the given identity into the repository.
* This is intended to simplify those tests that require a given user/group
* to be synchronized before executing the test.
*
* @param externalIdentity The external identity to be synchronized.
* @throws Exception
*/
private void sync(@Nonnull ExternalIdentity externalIdentity) throws Exception {
SyncResult result = syncCtx.sync(externalIdentity);
assertSame(SyncResult.Status.ADD, result.getStatus());
root.commit();
}
Aggregations