private static void append(@NotNull List<String> list, @NotNull SyncResult r) { if (r instanceof ErrorSyncResult) { ((ErrorSyncResult) r).append(list); } else { append(list, r.getIdentity(), getOperationFromStatus(r.getStatus()), null); } }
@Test public void testGetIdentityFromNull() { SyncResult res = new DefaultSyncResultImpl(null, SyncResult.Status.NOP); assertNull(res.getIdentity()); }
@Test public void testSyncAutoMembership() throws Exception { Group gr = createTestGroup(); syncConfig.user().setAutoMembership(gr.getID()); SyncResult result = syncCtx.sync(idp.listUsers().next()); assertEquals(SyncResult.Status.ADD, result.getStatus()); Authorizable a = userManager.getAuthorizable(result.getIdentity().getId()); assertTrue(gr.isDeclaredMember(a)); }
private void sync(@NotNull String id, boolean isGroup) throws Exception { ctx = sh.createContext(idp, userManager, valueFactory); ExternalIdentity exIdentity = (isGroup) ? idp.getGroup(id) : idp.getUser(id); assertNotNull(exIdentity); SyncResult res = ctx.sync(exIdentity); assertEquals(idp.getName(), res.getIdentity().getExternalIdRef().getProviderName()); assertSame(SyncResult.Status.ADD, res.getStatus()); r.commit(); }
@Test public void testSyncExternalToForeignLocalGroup() throws Exception { ExternalGroup external = idp.listGroups().next(); syncCtx.sync(external); Group gr = userManager.getAuthorizable(external.getId(), Group.class); setExternalID(gr, "differentIDP"); SyncResult result = syncCtx.sync(external); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(external.getExternalId(), si.getExternalIdRef()); }
@Test public void testSyncExternalForeignLocalUser() throws Exception { ExternalUser external = idp.listUsers().next(); syncCtx.sync(external); User u = userManager.getAuthorizable(external.getId(), User.class); setExternalID(u, "differentIDP"); SyncResult result = syncCtx.sync(external); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(external.getExternalId(), si.getExternalIdRef()); }
@Test public void testSyncExternalToExistingLocalGroup() throws Exception { ExternalGroup external = idp.listGroups().next(); syncCtx.sync(external); Group gr = userManager.getAuthorizable(external.getId(), Group.class); gr.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); SyncResult result = syncCtx.sync(external); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(external.getExternalId(), si.getExternalIdRef()); }
@Test public void testSyncExternalToExistingLocalUser() throws Exception { ExternalUser external = idp.listUsers().next(); syncCtx.sync(external); User u = userManager.getAuthorizable(external.getId(), User.class); u.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); SyncResult result = syncCtx.sync(external); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(external.getExternalId(), si.getExternalIdRef()); }
@Test public void testSyncByForeignUserId() throws Exception { SyncResult result = syncCtx.sync(getTestUser().getID()); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertNull(si.getExternalIdRef()); assertFalse(si.isGroup()); }
@Test public void testSyncByForeignGroupId() throws Exception { SyncResult result = syncCtx.sync(createTestGroup().getID()); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertNull(si.getExternalIdRef()); assertTrue(si.isGroup()); }
@Test public void testSyncByForeignId2() throws Exception { User u = userManager.getAuthorizable(getTestUser().getID(), User.class); setExternalID(u, "differentIDP"); SyncResult result = syncCtx.sync(u.getID()); assertEquals(SyncResult.Status.FOREIGN, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); assertEquals(DefaultSyncContext.getIdentityRef(u), si.getExternalIdRef()); }
private void assertRepExternalId(@NotNull SyncResult result) throws Exception { assertSame(SyncResult.Status.ADD, result.getStatus()); SyncedIdentity si = result.getIdentity(); assertNotNull(si); Authorizable authorizable = userManager.getAuthorizable(si.getId()); assertNotNull(authorizable); Tree userTree = r.getTree(authorizable.getPath()); assertTrue(userTree.hasProperty(DefaultSyncContext.REP_EXTERNAL_ID)); PropertyState ps = userTree.getProperty(DefaultSyncContext.REP_EXTERNAL_ID); assertNotNull(ps); assertFalse(ps.isArray()); assertSame(Type.STRING, ps.getType()); assertEquals(si.getExternalIdRef(), ExternalIdentityRef.fromString(ps.getValue(Type.STRING))); }
@Test public void testUniqueConstraintNonUserNode() throws Exception { try { SyncResult res = syncCtx.sync(idp.getUser(USER_ID)); Tree nonUserTree = r.getTree("/"); nonUserTree.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString()); r.commit(); fail("Duplicate value for rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(30, e.getCode()); } finally { r.refresh(); } } }
@Test public void testUniqueConstraint() throws Exception { SyncResult res = syncCtx.sync(idp.getUser(USER_ID)); try { Tree t = r.getTree(getTestUser().getPath()); t.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString()); r.commit(); fail("Duplicate value for rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(30, e.getCode()); } finally { r.refresh(); } }
@Test public void testUniqueConstraintSubsequentCommit() throws Exception { SyncResult res = syncCtx.sync(idp.getUser(USER_ID)); r.commit(); try { Tree t = r.getTree(getTestUser().getPath()); t.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString()); r.commit(); fail("Duplicate value for rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(30, e.getCode()); } finally { r.refresh(); } }
@Test public void testSyncGroupsForeign() throws Exception { // sync user from foreign IDP into the repository SyncResult res = sync(foreignIDP, "a", true); assertNotNull(getUserManager().getAuthorizable("a")); assertEquals(foreignIDP.getGroup("a").getExternalId(), res.getIdentity().getExternalIdRef()); // syncUsers with testIDP must detect the foreign status String[] result = syncMBean.syncUsers(new String[]{"a"}, false); assertResultMessages(result, "a", "for"); assertNotNull(getUserManager().getAuthorizable("a")); // same expected with 'purge' set to true result = syncMBean.syncUsers(new String[] {"a"}, true); assertResultMessages(result, "a", "for"); assertNotNull(getUserManager().getAuthorizable("a")); }
@Test public void testSyncUsersForeign() throws Exception { // sync user from foreign IDP into the repository 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()); // syncUsers with testIDP must detect the foreign status 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)); // same expected with 'purge' set to true 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 testLostMembershipWithExpirationSet() throws Exception { long expTime = 2; syncConfig.user().setMembershipNestingDepth(1).setMembershipExpirationTime(expTime).setExpirationTime(expTime); Group gr = createTestGroup(); setExternalID(gr, idp.getName()); SyncResult result = syncCtx.sync(idp.listUsers().next()); User user = (User) userManager.getAuthorizable(result.getIdentity().getId()); gr.addMember(user); root.commit(); waitUntilExpired(user, root, expTime); DefaultSyncContext newCtx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory); result = newCtx.sync(user.getID()); root.commit(); assertSame(SyncResult.Status.UPDATE, result.getStatus()); gr = (Group) userManager.getAuthorizable(gr.getID()); assertFalse(gr.isDeclaredMember(userManager.getAuthorizable(user.getID()))); }
@Test public void testSyncForeignExternalGroup() throws Exception { ExternalGroup foreign = new TestIdentityProvider.ForeignExternalGroup(); SyncResult res = syncContext.sync(foreign); assertNotNull(res); assertSame(SyncResult.Status.FOREIGN, res.getStatus()); // expect {@code SyncedIdentity} in accordance with {@code sync(String userId)}, // where the authorizable is found to be linked to a different IDP. SyncedIdentity si = res.getIdentity(); assertNotNull(si); assertEquals(foreign.getId(), si.getId()); ExternalIdentityRef ref = si.getExternalIdRef(); assertNotNull(ref); assertEquals(foreign.getExternalId(), ref); assertTrue(si.isGroup()); assertEquals(-1, si.lastSynced()); assertFalse(r.hasPendingChanges()); }
@Test public void testSyncForeignExternalGroup() throws Exception { ExternalIdentity foreign = new TestIdentityProvider.ForeignExternalGroup(); SyncResult res = syncCtx.sync(foreign); assertNotNull(res); assertSame(SyncResult.Status.FOREIGN, res.getStatus()); // expect {@code SyncedIdentity} in accordance with {@code sync(String userId)}, // where the authorizable is found to be linked to a different IDP. SyncedIdentity si = res.getIdentity(); assertNotNull(si); assertEquals(foreign.getId(), si.getId()); ExternalIdentityRef ref = si.getExternalIdRef(); assertNotNull(ref); assertEquals(foreign.getExternalId(), ref); assertTrue(si.isGroup()); assertEquals(-1, si.lastSynced()); assertFalse(root.hasPendingChanges()); }