SyncMBeanImpl implements SynchronizationMBean { @NotNull @Override public String[] syncUsers(@NotNull String[] userIds, boolean purge) { Delegatee delegatee = getDelegatee(); try { return delegatee.syncUsers(userIds, 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 testSyncUsersBefore() { String[] userIds = new String[] {TestIdentityProvider.ID_TEST_USER, TestIdentityProvider.ID_SECOND_USER}; String[] result = syncMBean.syncUsers(userIds, false); assertResultMessages(result, ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "nsa", TestIdentityProvider.ID_SECOND_USER, "nsa")); result = syncMBean.syncUsers(userIds, true); assertResultMessages(result, ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "nsa", TestIdentityProvider.ID_SECOND_USER, "nsa")); }
@Test public void testSyncUsers() throws Exception { sync(idp, TestIdentityProvider.ID_TEST_USER, false); String[] userIds = new String[]{TestIdentityProvider.ID_TEST_USER, TestIdentityProvider.ID_SECOND_USER}; String[] result = syncMBean.syncUsers(userIds, false); assertResultMessages(result, ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "upd", TestIdentityProvider.ID_SECOND_USER, "nsa")); result = syncMBean.syncUsers(userIds, true); assertResultMessages(result, ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "upd", TestIdentityProvider.ID_SECOND_USER, "nsa")); }
@Test public void testSyncUsersAlwaysForcesSync() throws Exception { sync(idp, TestIdentityProvider.ID_TEST_USER, false); String[] userIds = new String[]{TestIdentityProvider.ID_TEST_USER, TestIdentityProvider.ID_SECOND_USER}; syncConfig.user().setExpirationTime(Long.MAX_VALUE); String[]result = syncMBean.syncUsers(userIds, false); assertResultMessages(result, ImmutableMap.of(TestIdentityProvider.ID_TEST_USER, "upd", TestIdentityProvider.ID_SECOND_USER, "nsa")); }
@Test public void testSyncGroups() throws Exception { sync(idp, "a", true); Map<String, String> expected = ImmutableMap.of("a", "upd"); syncConfig.group().setExpirationTime(Long.MAX_VALUE); String[] result = syncMBean.syncUsers(expected.keySet().toArray(new String[0]), false); assertResultMessages(result, expected); }
@Test public void testSyncUsersPurge() throws Exception { sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("gr", idp.getName()), idp); UserManager userManager = getUserManager(); Authorizable[] authorizables = new Authorizable[] { userManager.getAuthorizable("thirdUser"), userManager.getAuthorizable("gr") }; for (Authorizable a : authorizables) { String[] ids = new String[]{a.getID()}; String[] result = syncMBean.syncUsers(ids, false); assertResultMessages(result, a.getID(), "mis"); assertNotNull(userManager.getAuthorizable(a.getID())); result = syncMBean.syncUsers(ids, true); assertResultMessages(result, a.getID(), "del"); assertNull(getUserManager().getAuthorizable(a.getID())); } }
@Test public void testSyncUsersNonExisting() { String[] result = syncMBean.syncUsers(new String[] {"nonExisting"}, false); assertResultMessages(result, "nonExisting", "nsa"); }
@Test public void testSyncUsersLocal() { String[] result = syncMBean.syncUsers(new String[] {UserConstants.DEFAULT_ANONYMOUS_ID}, false); assertResultMessages(result, UserConstants.DEFAULT_ANONYMOUS_ID, "for"); }
@Test public void testSyncUsersLocalPurge() throws Exception { String[] result = syncMBean.syncUsers(new String[] {UserConstants.DEFAULT_ANONYMOUS_ID}, true); assertResultMessages(result, UserConstants.DEFAULT_ANONYMOUS_ID, "for"); assertNotNull(getUserManager().getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID)); }
@Test public void testSyncUsersForeign() throws Exception { SyncResult res = sync(foreignIDP, TestIdentityProvider.ID_TEST_USER, false); assertNotNull(getUserManager().getAuthorizable(TestIdentityProvider.ID_TEST_USER)); assertEquals(foreignIDP.getUser(TestIdentityProvider.ID_TEST_USER).getExternalId(), res.getIdentity().getExternalIdRef()); String[] result = syncMBean.syncUsers(new String[]{TestIdentityProvider.ID_TEST_USER}, false); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for"); assertNotNull(getUserManager().getAuthorizable(TestIdentityProvider.ID_TEST_USER)); result = syncMBean.syncUsers(new String[] {TestIdentityProvider.ID_TEST_USER}, true); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for"); assertNotNull(getUserManager().getAuthorizable(TestIdentityProvider.ID_TEST_USER)); }
@Test public void testSyncGroupsForeign() throws Exception { SyncResult res = sync(foreignIDP, "a", true); assertNotNull(getUserManager().getAuthorizable("a")); assertEquals(foreignIDP.getGroup("a").getExternalId(), res.getIdentity().getExternalIdRef()); String[] result = syncMBean.syncUsers(new String[]{"a"}, false); assertResultMessages(result, "a", "for"); assertNotNull(getUserManager().getAuthorizable("a")); result = syncMBean.syncUsers(new String[] {"a"}, true); assertResultMessages(result, "a", "for"); assertNotNull(getUserManager().getAuthorizable("a")); }
@Test public void testSyncUserException() 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.syncUsers(new String[]{TestIdentityProvider.ID_EXCEPTION}, false); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); }
@Test public void testSyncUserThrowingHandler() throws Exception { sync(idp, TestIdentityProvider.ID_TEST_USER, false); String[] result = createThrowingSyncMBean(false).syncUsers(new String[]{TestIdentityProvider.ID_TEST_USER}, false); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "ERR"); }