ExternalLoginModule extends AbstractLoginModule { @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> opts) { super.initialize(subject, callbackHandler, sharedState, opts); if (osgiConfig != null) { options = ConfigurationParameters.of(osgiConfig, options); } Whiteboard whiteboard = getWhiteboard(); if (whiteboard == null) { log.error("External login module needs whiteboard. Will not be used for login."); return; } String idpName = options.getConfigValue(PARAM_IDP_NAME, ""); if (idpName.isEmpty()) { log.error("External login module needs IPD name. Will not be used for login."); } else { if (idpManager == null) { idpManager = WhiteboardUtils.getService(whiteboard, ExternalIdentityProviderManager.class); } if (idpManager == null) { log.error("External login module needs IDPManager. Will not be used for login."); } else { idp = idpManager.getProvider(idpName); if (idp == null) { log.error("No IDP found with name {}. Will not be used for login.", idpName); } } } String syncHandlerName = options.getConfigValue(PARAM_SYNC_HANDLER_NAME, ""); if (syncHandlerName.isEmpty()) { log.error("External login module needs SyncHandler name. Will not be used for login."); } else { if (syncManager == null) { syncManager = WhiteboardUtils.getService(whiteboard, SyncManager.class); } if (syncManager == null) { log.error("External login module needs SyncManager. Will not be used for login."); } else { syncHandler = syncManager.getSyncHandler(syncHandlerName); if (syncHandler == null) { log.error("No SyncHandler found with name {}. Will not be used for login.", syncHandlerName); } } } if (idp instanceof CredentialsSupport) { credentialsSupport = (CredentialsSupport) idp; } else { log.debug("No 'SupportedCredentials' configured. Using default implementation supporting 'SimpleCredentials'."); } } @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 testInitializEmptyIdpName() { wb.register(ExternalIdentityProviderManager.class, extIPMgr, Collections.emptyMap()); loginModule.initialize(new Subject(), createCallbackHandler(wb, null, null, null), Collections.emptyMap(), Collections.singletonMap(PARAM_IDP_NAME, "")); verify(extIPMgr, never()).getProvider(""); }
@Test public void testInitializEmptySyncHanderName() { wb.register(SyncManager.class, syncManager, Collections.emptyMap()); loginModule.initialize(new Subject(), createCallbackHandler(wb, null, null, null), Collections.emptyMap(), Collections.singletonMap(PARAM_SYNC_HANDLER_NAME, "")); verify(syncManager, never()).getSyncHandler(""); }