SyncMBeanImpl implements SynchronizationMBean { @NotNull @Override public String[] syncExternalUsers(@NotNull String[] externalIds) { Delegatee delegatee = getDelegatee(); try { return delegatee.syncExternalUsers(externalIds); } 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 testInitialSyncExternalUsers() throws Exception { ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER); String[] externalId = new String[] {externalUser.getExternalId().getString()}; String[] result = syncMBean.syncExternalUsers(externalId); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add"); UserManager userManager = getUserManager(); User testUser = userManager.getAuthorizable(externalUser.getId(), User.class); assertNotNull(testUser); for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) { assertNotNull(userManager.getAuthorizable(groupRef.getId())); } }
@Test public void testInitialSyncExternalUsersNoNesting() throws Exception { syncConfig.user().setMembershipNestingDepth(-1); ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER); String[] externalId = new String[] {externalUser.getExternalId().getString()}; String[] result = syncMBean.syncExternalUsers(externalId); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add"); UserManager userManager = getUserManager(); User testUser = userManager.getAuthorizable(externalUser.getId(), User.class); assertNotNull(testUser); for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) { assertNull(userManager.getAuthorizable(groupRef.getId())); } }
@Test public void testSyncExternalUsersLastSyncedProperty() throws Exception { ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER); String[] externalId = new String[]{externalUser.getExternalId().getString()}; syncMBean.syncExternalUsers(externalId); UserManager userManager = getUserManager(); User testUser = userManager.getAuthorizable(externalUser.getId(), User.class); long lastSynced = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong(); for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) { Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class); long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong(); assertTrue(lastSynced == groupLastSynced); } while (System.currentTimeMillis() <= lastSynced) { } syncMBean.syncExternalUsers(externalId); userManager = getUserManager(); testUser = userManager.getAuthorizable(externalUser.getId(), User.class); long lastSynced2 = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong(); assertTrue("lastSynced: " + lastSynced + ", lastSynced2: " + lastSynced2, lastSynced < lastSynced2); for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) { Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class); long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong(); assertTrue(lastSynced2 == groupLastSynced); } }
@Test public void testInitialSyncExternalGroup() throws Exception { ExternalGroup externalGroup = idp.getGroup("a"); String[] externalId = new String[] {externalGroup.getExternalId().getString()}; String[] result = syncMBean.syncExternalUsers(externalId); assertResultMessages(result, "a", "add"); UserManager userManager = getUserManager(); Group aGroup = userManager.getAuthorizable(externalGroup.getId(), Group.class); assertNotNull(aGroup); for (ExternalIdentityRef groupRef : externalGroup.getDeclaredGroups()) { assertNull(userManager.getAuthorizable(groupRef.getId())); } }
@Test public void testSyncExternalNonExisting() { ExternalIdentityRef ref = new ExternalIdentityRef("nonExisting", idp.getName()); String[] result = syncMBean.syncExternalUsers(new String[]{ref.getString()}); assertResultMessages(result, "", "nsi"); }
@Test public void testSyncExternalLocal() { ExternalIdentityRef ref = new ExternalIdentityRef(UserConstants.DEFAULT_ANONYMOUS_ID, null); String[] result = syncMBean.syncExternalUsers(new String[]{ref.getString()}); assertResultMessages(result, UserConstants.DEFAULT_ANONYMOUS_ID, "for"); }
@Test public void testSyncExternalForeign() { ExternalIdentityRef ref = new ExternalIdentityRef(TestIdentityProvider.ID_TEST_USER, "anotherIDP"); String[] result = syncMBean.syncExternalUsers(new String[]{ref.getString()}); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for"); result = syncMBean.syncExternalUsers(new String[] {ref.getString()}); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for"); }
@Test public void testSyncExternalUserException() { ExternalIdentityRef ref = new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()); String[] result = syncMBean.syncExternalUsers(new String[] {ref.getString()}); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); }
@Test public void testSyncExternalUserThrowingHandler() { ExternalIdentityRef ref = new ExternalIdentityRef(TestIdentityProvider.ID_TEST_USER, idp.getName()); String[] result = createThrowingSyncMBean(false).syncExternalUsers(new String[]{ref.getString()}); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "ERR"); }