Authorizable auth = userManager.getAuthorizable(id);
if (auth == null) {
return new SyncResultImpl(new SyncedIdentityImpl(id, null, false, -1), SyncResult.Status.NO_SUCH_AUTHORIZABLE);
}
// check if we need to deal with this authorizable
ExternalIdentityRef ref = getIdentityRef(auth);
if (ref == null || !idp.getName().equals(ref.getProviderName())) {
return new SyncResultImpl(new SyncedIdentityImpl(id, null, false, -1), SyncResult.Status.FOREIGN);
}
if (auth instanceof Group) {
Group group = (Group) auth;
ExternalGroup external = idp.getGroup(id);
timer.mark("retrieve");
if (external == null) {
SyncedIdentityImpl syncId = createSyncedIdentity(auth);
if (group.getDeclaredMembers().hasNext()) {
log.info("won't remove local group with members: {}", id);
ret = new SyncResultImpl(syncId, SyncResult.Status.NOP);
} else if (!keepMissing) {
auth.remove();
log.debug("removing authorizable '{}' that no longer exists on IDP {}", id, idp.getName());
timer.mark("remove");
ret = new SyncResultImpl(syncId, SyncResult.Status.DELETE);
} else {
ret = new SyncResultImpl(syncId, SyncResult.Status.MISSING);
log.info("external identity missing for {}, but purge == false.", id);
}
} else {
ret = syncGroup(external, group);
timer.mark("sync");
}
} else {
ExternalUser external = idp.getUser(id);
timer.mark("retrieve");
if (external == null) {
SyncedIdentityImpl syncId = createSyncedIdentity(auth);
if (!keepMissing) {
auth.remove();
log.debug("removing authorizable '{}' that no longer exists on IDP {}", id, idp.getName());
timer.mark("remove");
ret = new SyncResultImpl(syncId, SyncResult.Status.DELETE);
} else {
ret = new SyncResultImpl(syncId, SyncResult.Status.MISSING);
log.info("external identity missing for {}, but purge == false.", id);
}
} else {
ret = syncUser(external, (User) auth);
timer.mark("sync");
}
}
if (log.isDebugEnabled()) {
log.debug("sync({}) -> {} {}", id, ref.getString(), timer.getString());
}
return ret;
} catch (RepositoryException e) {
throw new SyncException(e);
} catch (ExternalIdentityException e) {