/** * Tests if the given {@link ExternalIdentityRef} refers to the same IDP * as associated with this context instance. * * @param ref The {@link ExternalIdentityRef} to be tested. * @return {@code true} if {@link ExternalIdentityRef#getProviderName()} refers * to the IDP associated with this context instance. */ protected boolean isSameIDP(@NotNull ExternalIdentityRef ref) { return idp.getName().equals(ref.getProviderName()); } }
/** * Checks if the given authorizable was synced from the same IDP by comparing the IDP name of the * {@value #REP_EXTERNAL_ID} property. * * @param auth the authorizable. * @return {@code true} if same IDP. */ protected boolean isSameIDP(@Nullable Authorizable auth) throws RepositoryException { ExternalIdentityRef ref = getIdentityRef(auth); return ref != null && idp.getName().equals(ref.getProviderName()); }
private List<SyncResult> syncUser(@NotNull String userId, boolean includeIdpName, @NotNull List<SyncResult> results, @NotNull List<String> list) { try { results.add(context.sync(userId)); } catch (SyncException e) { log.warn(ERROR_SYNC_USER, userId, e); results.add(new ErrorSyncResult(userId, ((includeIdpName) ? idp.getName() : null), e)); } return commit(list, results, batchSize); }
@Nullable @Override public ExternalIdentityProvider getProvider(@NotNull String name) { if (name.equals(idp.getName())) { return idp; } else { return null; } } };
private AppConfigurationEntry asConfigurationEntry() { return new AppConfigurationEntry( ExternalLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, ImmutableMap.<String, String>of( SyncHandlerMapping.PARAM_SYNC_HANDLER_NAME, sh.getName(), SyncHandlerMapping.PARAM_IDP_NAME, idp.getName() )); } }
@Override protected void beforeSuite() throws Exception { super.beforeSuite(); bean = new SyncMBeanImpl(getContentRepository(), getSecurityProvider(), syncManager, "default", idpManager, idp.getName()); }
@Override protected void beforeSuite() throws Exception { super.beforeSuite(); SynchronizationMBean bean = new SyncMBeanImpl(getContentRepository(), getSecurityProvider(), syncManager, "default", idpManager, idp.getName()); bean.syncAllExternalUsers(); }
@Override protected void beforeSuite() throws Exception { super.beforeSuite(); bean = new SyncMBeanImpl(getContentRepository(), getSecurityProvider(), syncManager, "default", idpManager, idp.getName()); bean.syncAllExternalUsers(); }
@Before public void before() throws Exception { super.before(); testIdpReg = whiteboard.register(ExternalIdentityProvider.class, idp, Collections.<String, Object>emptyMap()); setSyncConfig(syncConfig); options.put(ExternalLoginModule.PARAM_SYNC_HANDLER_NAME, syncConfig.getName()); options.put(ExternalLoginModule.PARAM_IDP_NAME, idp.getName()); }
private static void registerSyncHandlerMapping(@NotNull OsgiContext ctx, @NotNull ExternalSetup setup) { String syncHandlerName = setup.sc.getName(); Map<String, Object> props = ImmutableMap.of( DefaultSyncConfigImpl.PARAM_NAME, syncHandlerName, DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP, setup.sc.user().getDynamicMembership(), DefaultSyncConfigImpl.PARAM_USER_AUTO_MEMBERSHIP, setup.sc.user().getAutoMembership()); ctx.registerService(SyncHandler.class, setup.sh, props); Map<String, String> mappingProps = ImmutableMap.of( SyncHandlerMapping.PARAM_IDP_NAME, setup.idp.getName(), SyncHandlerMapping.PARAM_SYNC_HANDLER_NAME, syncHandlerName); ctx.registerService(SyncHandlerMapping.class, new SyncHandlerMapping() {}, mappingProps); }
@Test public void testListOrphanedUsers() throws Exception { syncMBean.syncAllExternalUsers(); String[] result = syncMBean.listOrphanedUsers(); assertEquals(0, result.length); sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); result = syncMBean.listOrphanedUsers(); assertEquals(2, result.length); assertEquals(ImmutableSet.of("thirdUser", "g"), ImmutableSet.copyOf(result)); }
@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 testSyncAllUsersPurgeFalse() throws Exception { // first sync external user|group into the repo that does't exist on the IDP (anymore) sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); // syncAll with purge = false 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 { // first sync external user|group into the repo that does't exist on the IDP (anymore) sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); // syncAll with purge = true 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 testInvalidSyncHandlerName() { SyncMBeanImpl syncMBean = createSyncMBeanImpl("invalid", idp.getName()); assertEquals("invalid", syncMBean.getSyncHandlerName()); // calling any sync-operation must fail due to the invalid configuration try { syncMBean.syncAllExternalUsers(); fail("syncAllExternalUsers with invalid SyncHandlerName must fail"); } catch (IllegalArgumentException e) { //success } }
@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"); }
@Test public void testSyncForeignExternalUserSaveError() throws Exception { Root r = preventRootCommit(delegatee);; String[] result = delegatee.syncExternalUsers(new String[] {new ExternalIdentityRef(TestIdentityProvider.ID_TEST_USER, foreignIDP.getName()).getString()}); assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for"); assertFalse(r.hasPendingChanges()); }
@Test public void testSyncThrowingExternalUserSaveError() throws Exception { Root r = preventRootCommit(delegatee);; String[] result = delegatee.syncExternalUsers(new String[] {new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString()}); assertResultMessages(result, TestIdentityProvider.ID_EXCEPTION, "ERR"); assertFalse(r.hasPendingChanges()); }
@Test public void testPurgeOrphanedUsersException() 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.purgeOrphanedUsers(); assertEquals(0, result.length); }
@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"); }