DefaultSyncContext implements SyncContext { protected void applyMembership(@NotNull Authorizable member, @NotNull Set<String> groups) throws RepositoryException { for (String groupName : groups) { Authorizable group = userManager.getAuthorizable(groupName); if (group == null) { log.warn("Unable to apply auto-membership to {}. No such group: {}", member.getID(), groupName); } else if (group instanceof Group) { ((Group) group).addMember(member); } else { log.warn("Unable to apply auto-membership to {}. Authorizable '{}' is not a group.", member.getID(), groupName); } } } DefaultSyncContext(@NotNull DefaultSyncConfig config, @NotNull ExternalIdentityProvider idp, @NotNull UserManager userManager, @NotNull ValueFactory valueFactory); @Nullable static DefaultSyncedIdentity createSyncedIdentity(@Nullable Authorizable auth); @Nullable static ExternalIdentityRef getIdentityRef(@Nullable Authorizable auth); static String joinPaths(String... paths); @Override void close(); @Override boolean isKeepMissing(); @NotNull @Override SyncContext setKeepMissing(boolean keepMissing); @Override boolean isForceUserSync(); @NotNull @Override SyncContext setForceUserSync(boolean forceUserSync); @Override boolean isForceGroupSync(); @Override @NotNull SyncContext setForceGroupSync(boolean forceGroupSync); @NotNull @Override SyncResult sync(@NotNull ExternalIdentity identity); @NotNull @Override SyncResult sync(@NotNull String id); static final String REP_EXTERNAL_ID; static final String REP_LAST_SYNCED; }
@Test public void testApplyMembership() throws Exception { User u = getTestUser(); Group gr = createTestGroup(); syncCtx.applyMembership(u, ImmutableSet.of(gr.getID())); assertTrue(gr.isDeclaredMember(u)); assertTrue(root.hasPendingChanges()); }