ExternalLoginModule extends AbstractLoginModule { private void validateUser(@NotNull String id) throws SyncException { Root root = getRootOrThrow(); UserManager userManager = getUsermanagerOrThrow(); SyncContext context = syncHandler.createContext(idp, userManager, new ValueFactoryImpl(root, NamePathMapper.DEFAULT)); try { DebugTimer timer = new DebugTimer(); context = syncHandler.createContext(idp, userManager, new ValueFactoryImpl(root, NamePathMapper.DEFAULT)); context.sync(id); timer.mark("sync"); root.commit(); timer.mark("commit"); debug("validateUser({}) {}", id, timer.getString()); } catch (CommitFailedException e) { throw new SyncException("User synchronization failed during commit.", e); } finally { context.close(); } } @SuppressWarnings("UnusedDeclaration")  ExternalLoginModule();  ExternalLoginModule(ConfigurationParameters osgiConfig); @Override void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> opts); @Override boolean login(); @Override boolean commit(); @Override boolean abort(); @Override boolean logout(); void setSyncManager(@NotNull SyncManager syncManager); void setIdpManager(@NotNull ExternalIdentityProviderManager idpManager); static final String PARAM_IDP_NAME; static final String PARAM_SYNC_HANDLER_NAME; }
@Test public void testValidateUser() throws Exception { when(extIPMgr.getProvider(DEFAULT_IDP_NAME)).thenReturn(new TestIdentityProvider()); when(syncManager.getSyncHandler("syncHandler")).thenReturn(new DefaultSyncHandler(new DefaultSyncConfigImpl().setName("syncHandler"))); wb.register(ExternalIdentityProviderManager.class, extIPMgr, Collections.emptyMap()); wb.register(SyncManager.class, syncManager, Collections.emptyMap()); Map<String,Object> sharedState = Maps.newHashMap(); sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin("local")); User u = getUserManager(root).createUser("local", null); u.setProperty(REP_EXTERNAL_ID, getValueFactory().createValue("local;"+TestIdentityProvider.DEFAULT_IDP_NAME)); root.commit(); CallbackHandler cbh = createCallbackHandler(wb, getContentRepository(), getSecurityProvider(), null); loginModule.initialize(new Subject(), cbh, sharedState, ImmutableMap.of(PARAM_IDP_NAME, DEFAULT_IDP_NAME, PARAM_SYNC_HANDLER_NAME, "syncHandler")); assertFalse(loginModule.login()); root.refresh(); assertNull(getUserManager(root).getAuthorizable("local")); assertFalse(loginModule.commit()); assertFalse(loginModule.logout()); }