SyncMBeanImpl implements SynchronizationMBean { @NotNull @Override public String[] syncAllUsers(boolean purge) { Delegatee delegatee = getDelegatee(); try { return delegatee.syncAllUsers(purge); } finally { delegatee.close(); } } SyncMBeanImpl(@NotNull ContentRepository repository, @NotNull SecurityProvider securityProvider,
                         @NotNull SyncManager syncManager, @NotNull String syncName,
                         @NotNull ExternalIdentityProviderManager idpManager, @NotNull String idpName); @NotNull @Override String getSyncHandlerName(); @NotNull @Override String getIDPName(); @NotNull @Override String[] syncUsers(@NotNull String[] userIds, boolean purge); @NotNull @Override String[] syncAllUsers(boolean purge); @NotNull @Override String[] syncExternalUsers(@NotNull String[] externalIds); @NotNull @Override String[] syncAllExternalUsers(); @NotNull @Override String[] listOrphanedUsers(); @NotNull @Override String[] purgeOrphanedUsers();  }
@Test public void testSyncAllUsersBefore() { String[] result = syncMBean.syncAllUsers(false); assertEquals(0, result.length); }
@Test public void testSyncAllUsers() throws Exception { syncMBean.syncAllExternalUsers(); String[] result = syncMBean.syncAllUsers(false); Map<String, String> expected = getExpectedUserResult("upd", true); assertResultMessages(result, expected); UserManager userManager = getUserManager(); for (String id : expected.keySet()) { ExternalIdentity ei = idp.getUser(id); if (ei == null) { ei = idp.getGroup(id); } assertSync(ei, userManager); } }
@Test public void testSyncAllGroups() throws Exception { Map<String, String> expected = new HashMap<>(); Iterator<ExternalGroup> grIt = idp.listGroups(); while (grIt.hasNext()) { ExternalGroup eg = grIt.next(); sync(idp, eg.getId(), true); expected.put(eg.getId(), "upd"); } String[] result = syncMBean.syncAllUsers(false); assertResultMessages(result, expected); UserManager userManager = getUserManager(); for (String id : expected.keySet()) { ExternalIdentity ei = idp.getGroup(id); assertSync(ei, userManager); } }
@Test public void testSyncAllUsersPurgeFalse() throws Exception { sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); String[] result = syncMBean.syncAllUsers(false); assertResultMessages(result, ImmutableMap.of("thirdUser", "mis", "g", "mis")); UserManager userManager = getUserManager(); assertNotNull(userManager.getAuthorizable("thirdUser")); assertNotNull(userManager.getAuthorizable("g")); }
@Test public void testSyncAllUsersPurgeTrue() throws Exception { sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); String[] result = syncMBean.syncAllUsers(true); assertResultMessages(result, ImmutableMap.of("thirdUser", "del", "g", "del")); UserManager userManager = getUserManager(); assertNull(userManager.getAuthorizable("thirdUser")); assertNull(userManager.getAuthorizable("g")); }
@Test public void testSyncAllUsersForeign() throws Exception { syncConfig.user().setMembershipNestingDepth(0); sync(idp, TestIdentityProvider.ID_TEST_USER, false); sync(idp, "a", true); sync(foreignIDP, TestIdentityProvider.ID_SECOND_USER, false); sync(foreignIDP, "aa", true); String[] result = syncMBean.syncAllUsers(false); Map<String, String> expectedResults = ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "upd", "a", "upd"); assertResultMessages(result, expectedResults); ExternalIdentity[] expectedIds = new ExternalIdentity[] { idp.getUser(TestIdentityProvider.ID_TEST_USER), foreignIDP.getUser(TestIdentityProvider.ID_SECOND_USER), idp.getGroup("a"), foreignIDP.getGroup("aa") }; UserManager userManager = getUserManager(); for (ExternalIdentity externalIdentity : expectedIds) { assertSync(externalIdentity, userManager); } }
@Test public void testSyncAllUsersException() throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.syncAllUsers(false); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); result = syncMBean.syncAllUsers(true); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); }
@Test(expected = IllegalStateException.class) public void testSyncAllUsersThrowingHandler() { String[] result = createThrowingSyncMBean(false).syncAllUsers(false); }