use of pl.edu.icm.unity.engine.api.config.UnityServerConfiguration in project unity by unity-idm.
the class TestUnityConfig method authenticationFlowsAreCorrectlyLoaded.
@Test
public void authenticationFlowsAreCorrectlyLoaded() throws ConfigurationException, IOException {
Environment env = mock(Environment.class);
ConfigurationLocationProvider locProvider = mock(ConfigurationLocationProvider.class);
Mockito.when(locProvider.getConfigurationLocation()).thenReturn("src/test/resources/testAuthenticatorsSpec.conf");
UnityServerConfiguration config = new UnityServerConfiguration(env, locProvider);
List<String> endpointAuth = config.getEndpointAuth("endpoints.1.");
assertThat(endpointAuth.size(), is(4));
assertThat(endpointAuth.get(0), is("a1"));
assertThat(endpointAuth.get(1), is("a2"));
assertThat(endpointAuth.get(2), is("a3"));
assertThat(endpointAuth.get(3), is("a4"));
}
use of pl.edu.icm.unity.engine.api.config.UnityServerConfiguration in project unity by unity-idm.
the class TestUserImportService method importSerivceInvokesAllImporters.
@Test
public void importSerivceInvokesAllImporters() throws InterruptedException {
// given
RemoteAuthnResultTranslator verificatorUtil = mock(RemoteAuthnResultTranslator.class);
UnityServerConfiguration mainCfg = mock(UnityServerConfiguration.class);
when(mainCfg.getSortedListKeys(UnityServerConfiguration.IMPORT_PFX)).thenReturn(Lists.newArrayList("key1", "key2"));
when(mainCfg.getValue(UnityServerConfiguration.IMPORT_PFX + "key1")).thenReturn("f1");
when(mainCfg.getValue(UnityServerConfiguration.IMPORT_PFX + "key2")).thenReturn("f2");
ConfigurationLoader cfgLoader = mock(ConfigurationLoader.class);
when(cfgLoader.getProperties("f1")).thenReturn(getCfgProperties());
when(cfgLoader.getProperties("f2")).thenReturn(getCfgProperties());
UserImportSPIFactory factory = mock(UserImportSPIFactory.class);
UserImportSPI importer = mock(UserImportSPI.class);
when(importer.importUser("id", "type")).thenReturn(null);
when(factory.getInstance(any(), any())).thenReturn(importer);
when(factory.getName()).thenReturn("mockI");
List<UserImportSPIFactory> importersF = new ArrayList<>();
importersF.add(factory);
CacheProvider cp = new CacheProvider();
// when
UserImportServiceImpl impl = new UserImportServiceImpl(mainCfg, importersF, cp, verificatorUtil, cfgLoader);
List<ImportResult> importUser = impl.importUser(Lists.newArrayList(UserImportSpec.withAllImporters("id", "type")));
// then
assertThat(importUser.size(), is(2));
assertThat(importUser.get(0).importerKey, is("key1"));
assertThat(importUser.get(0).authenticationResult.getStatus(), is(Status.notApplicable));
assertThat(importUser.get(1).importerKey, is("key2"));
verify(factory, times(2)).getInstance(getCfgProperties(), "idp");
verify(importer, times(2)).importUser("id", "type");
}
use of pl.edu.icm.unity.engine.api.config.UnityServerConfiguration in project unity by unity-idm.
the class SamlAuthVaadinEndpoint method getServletContextHandlerOverridable.
@Override
protected ServletContextHandler getServletContextHandlerOverridable() {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(description.getEndpoint().getContextAddress());
String samlPublicEntryPointUrl = getServletUrl(publicEntryPointPath);
Servlet samlParseServlet = getSamlParseServlet(samlPublicEntryPointUrl, getServletUrl(SAML_ENTRY_SERVLET_PATH));
ServletHolder samlParseHolder = createServletHolder(samlParseServlet, true);
context.addServlet(samlParseHolder, publicEntryPointPath + "/*");
context.addFilter(new FilterHolder(remoteAuthnResponseProcessingFilter), "/*", EnumSet.of(DispatcherType.REQUEST));
Filter samlGuardFilter = new SamlGuardFilter(new ErrorHandler(aTypeSupport, freemarkerHandler));
context.addFilter(new FilterHolder(samlGuardFilter), SAML_ENTRY_SERVLET_PATH, EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
ServletHolder routingServletHolder = createServletHolder(new RoutingServlet(SAML_CONSENT_DECIDER_SERVLET_PATH), true);
context.addServlet(routingServletHolder, SAML_ENTRY_SERVLET_PATH + "/*");
Servlet samlConsentDeciderServlet = dispatcherServletFactory.getInstance(SAML_UI_SERVLET_PATH, AUTHENTICATION_PATH, description.getEndpoint());
ServletHolder samlConsentDeciderHolder = createServletHolder(samlConsentDeciderServlet, true);
context.addServlet(samlConsentDeciderHolder, SAML_CONSENT_DECIDER_SERVLET_PATH + "/*");
String sloAsyncURL = getServletUrl(SAML_SLO_ASYNC_SERVLET_PATH);
Servlet samlSLOAsyncServlet = getSLOAsyncServlet(sloAsyncURL);
ServletHolder samlSLOAsyncHolder = createServletHolder(samlSLOAsyncServlet, true);
context.addServlet(samlSLOAsyncHolder, SAML_SLO_ASYNC_SERVLET_PATH + "/*");
String sloSyncURL = getServletUrl(SAML_SLO_SOAP_SERVLET_PATH);
Servlet samlSLOSyncServlet = getSLOSyncServlet(sloSyncURL);
ServletHolder samlSLOSyncHolder = createServletHolder(samlSLOSyncServlet, true);
context.addServlet(samlSLOSyncHolder, SAML_SLO_SOAP_SERVLET_PATH + "/*");
SessionManagement sessionMan = applicationContext.getBean(SessionManagement.class);
LoginToHttpSessionBinder sessionBinder = applicationContext.getBean(LoginToHttpSessionBinder.class);
UnityServerConfiguration config = applicationContext.getBean(UnityServerConfiguration.class);
RememberMeProcessor remeberMeProcessor = applicationContext.getBean(RememberMeProcessor.class);
context.addFilter(new FilterHolder(new HiddenResourcesFilter(Collections.unmodifiableList(Arrays.asList(AUTHENTICATION_PATH, SAML_CONSENT_DECIDER_SERVLET_PATH, SAML_UI_SERVLET_PATH)))), "/*", EnumSet.of(DispatcherType.REQUEST));
authnFilter = new AuthenticationFilter(Arrays.asList(SAML_ENTRY_SERVLET_PATH), AUTHENTICATION_PATH, description.getRealm(), sessionMan, sessionBinder, remeberMeProcessor);
context.addFilter(new FilterHolder(authnFilter), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
proxyAuthnFilter = new ProxyAuthenticationFilter(authenticationFlows, description.getEndpoint().getContextAddress(), genericEndpointProperties.getBooleanValue(VaadinEndpointProperties.AUTO_LOGIN), description.getRealm());
context.addFilter(new FilterHolder(proxyAuthnFilter), AUTHENTICATION_PATH + "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
contextSetupFilter = new InvocationContextSetupFilter(config, description.getRealm(), null, getAuthenticationFlows());
context.addFilter(new FilterHolder(contextSetupFilter), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
EndpointRegistrationConfiguration registrationConfiguration = genericEndpointProperties.getRegistrationConfiguration();
authenticationServlet = new UnityVaadinServlet(applicationContext, AuthenticationUI.class.getSimpleName(), description, authenticationFlows, registrationConfiguration, properties, getBootstrapHandler4Authn(SAML_ENTRY_SERVLET_PATH));
CancelHandler cancelHandler = new SamlAuthnCancelHandler(freemarkerHandler, aTypeSupport, idpStatisticReporterFactory, description.getEndpoint());
authenticationServlet.setCancelHandler(cancelHandler);
ServletHolder authnServletHolder = createVaadinServletHolder(authenticationServlet, true);
context.addServlet(authnServletHolder, AUTHENTICATION_PATH + "/*");
context.addServlet(authnServletHolder, VAADIN_RESOURCES);
theServlet = new UnityVaadinServlet(applicationContext, uiBeanName, description, authenticationFlows, registrationConfiguration, properties, getBootstrapHandler(SAML_ENTRY_SERVLET_PATH));
context.addServlet(createVaadinServletHolder(theServlet, false), uiServletPath + "/*");
if (samlProperties.getBooleanValue(SamlIdpProperties.PUBLISH_METADATA)) {
Servlet metadataServlet = getMetadataServlet(samlPublicEntryPointUrl, sloAsyncURL, sloSyncURL);
context.addServlet(createServletHolder(metadataServlet, true), SAML_META_SERVLET_PATH + "/*");
}
return context;
}
use of pl.edu.icm.unity.engine.api.config.UnityServerConfiguration in project unity by unity-idm.
the class MockGroovyBindingProvider method getBinding.
public static Binding getBinding(PersistableEvent event) {
MessageSource unityMessageSource = mock(MessageSource.class, withSettings().verboseLogging());
UnityServerConfiguration config = mock(UnityServerConfiguration.class, withSettings().verboseLogging());
BulkProcessingManagement bulkProcessingManagement = mock(BulkProcessingManagement.class, withSettings().verboseLogging());
PreferencesManagement preferencesManagement = mock(PreferencesManagement.class, withSettings().verboseLogging());
UserImportManagement userImportManagement = mock(UserImportManagement.class, withSettings().verboseLogging());
AttributeTypeSupport attributeTypeSupport = mock(AttributeTypeSupport.class, withSettings().verboseLogging());
IdentityTypeSupport identityTypeSupport = mock(IdentityTypeSupport.class, withSettings().verboseLogging());
IdentityTypesManagement identityTypesManagement = mock(IdentityTypesManagement.class, withSettings().verboseLogging());
AttributeClassManagement attributeClassManagement = mock(AttributeClassManagement.class, withSettings().verboseLogging());
AttributesManagement attributesManagement = mock(AttributesManagement.class, withSettings().verboseLogging());
AttributeTypeManagement attributeTypeManagement = mock(AttributeTypeManagement.class, withSettings().verboseLogging());
AuthenticatorManagement authenticatorManagement = mock(AuthenticatorManagement.class, withSettings().verboseLogging());
CredentialManagement credentialManagement = mock(CredentialManagement.class, withSettings().verboseLogging());
CredentialRequirementManagement credentialRequirementManagement = mock(CredentialRequirementManagement.class, withSettings().verboseLogging());
EndpointManagement endpointManagement = mock(EndpointManagement.class, withSettings().verboseLogging());
EnquiryManagement enquiryManagement = mock(EnquiryManagement.class, withSettings().verboseLogging());
EntityCredentialManagement entityCredentialManagement = mock(EntityCredentialManagement.class, withSettings().verboseLogging());
EntityManagement entityManagement = mock(EntityManagement.class, withSettings().verboseLogging());
GroupsManagement groupsManagement = mock(GroupsManagement.class, withSettings().verboseLogging());
InvitationManagement invitationManagement = mock(InvitationManagement.class, withSettings().verboseLogging());
MessageTemplateManagement messageTemplateManagement = mock(MessageTemplateManagement.class, withSettings().verboseLogging());
NotificationsManagement notificationsManagement = mock(NotificationsManagement.class, withSettings().verboseLogging());
RealmsManagement realmsManagement = mock(RealmsManagement.class, withSettings().verboseLogging());
TokensManagement tokensManagement = mock(TokensManagement.class, withSettings().verboseLogging());
RegistrationsManagement registrationsManagement = mock(RegistrationsManagement.class, withSettings().verboseLogging());
TranslationProfileManagement translationProfileManagement = mock(TranslationProfileManagement.class, withSettings().verboseLogging());
GroupDelegationConfigGenerator groupDelegationConfigGenerator = mock(GroupDelegationConfigGenerator.class, withSettings().verboseLogging());
SessionManagement sessionManagement = mock(SessionManagement.class, withSettings().verboseLogging());
RegistrationFormTranslationActionGenerator regTranslationActionGenerator = mock(RegistrationFormTranslationActionGenerator.class, withSettings().verboseLogging());
ApplicationContext applicationContext = mock(ApplicationContext.class, withSettings().verboseLogging());
Binding binding = new Binding();
binding.setVariable("config", config);
binding.setVariable("attributeClassManagement", attributeClassManagement);
binding.setVariable("attributesManagement", attributesManagement);
binding.setVariable("attributeTypeManagement", attributeTypeManagement);
binding.setVariable("authenticatorManagement", authenticatorManagement);
binding.setVariable("bulkProcessingManagement", bulkProcessingManagement);
binding.setVariable("credentialManagement", credentialManagement);
binding.setVariable("credentialRequirementManagement", credentialRequirementManagement);
binding.setVariable("endpointManagement", endpointManagement);
binding.setVariable("enquiryManagement", enquiryManagement);
binding.setVariable("entityCredentialManagement", entityCredentialManagement);
binding.setVariable("entityManagement", entityManagement);
binding.setVariable("groupsManagement", groupsManagement);
binding.setVariable("identityTypesManagement", identityTypesManagement);
binding.setVariable("invitationManagement", invitationManagement);
binding.setVariable("messageTemplateManagement", messageTemplateManagement);
binding.setVariable("notificationsManagement", notificationsManagement);
binding.setVariable("preferencesManagement", preferencesManagement);
binding.setVariable("realmsManagement", realmsManagement);
binding.setVariable("registrationsManagement", registrationsManagement);
binding.setVariable("translationProfileManagement", translationProfileManagement);
binding.setVariable("userImportManagement", userImportManagement);
binding.setVariable("msgSrc", unityMessageSource);
binding.setVariable("attributeTypeSupport", attributeTypeSupport);
binding.setVariable("identityTypeSupport", identityTypeSupport);
binding.setVariable("groupDelegationConfigGenerator", groupDelegationConfigGenerator);
binding.setVariable("sessionManagement", sessionManagement);
binding.setVariable("isColdStart", true);
binding.setVariable("event", event.getTrigger());
binding.setVariable("context", event.getContents());
binding.setVariable("regTranslationActionGenerator", regTranslationActionGenerator);
binding.setVariable("log", LOG);
binding.setVariable("applicationContext", applicationContext);
binding.setVariable("tokensManagement", tokensManagement);
return binding;
}
use of pl.edu.icm.unity.engine.api.config.UnityServerConfiguration in project unity by unity-idm.
the class TestUserImportService method importSerivceLoadsConfiguredHandlerAndInvokesIt.
@Test
public void importSerivceLoadsConfiguredHandlerAndInvokesIt() throws InterruptedException {
// given
RemoteAuthnResultTranslator verificatorUtil = mock(RemoteAuthnResultTranslator.class);
UnityServerConfiguration mainCfg = mock(UnityServerConfiguration.class);
when(mainCfg.getSortedListKeys(UnityServerConfiguration.IMPORT_PFX)).thenReturn(Lists.newArrayList("key"));
when(mainCfg.getValue(UnityServerConfiguration.IMPORT_PFX + "key")).thenReturn("f");
ConfigurationLoader cfgLoader = mock(ConfigurationLoader.class);
when(cfgLoader.getProperties("f")).thenReturn(getCfgProperties());
UserImportSPIFactory factory = mock(UserImportSPIFactory.class);
UserImportSPI importer = mock(UserImportSPI.class);
when(importer.importUser("id", "type")).thenReturn(null);
when(factory.getInstance(any(), any())).thenReturn(importer);
when(factory.getName()).thenReturn("mockI");
List<UserImportSPIFactory> importersF = new ArrayList<>();
importersF.add(factory);
CacheProvider cp = new CacheProvider();
// when
UserImportServiceImpl impl = new UserImportServiceImpl(mainCfg, importersF, cp, verificatorUtil, cfgLoader);
List<ImportResult> importUser = impl.importUser(Lists.newArrayList(new UserImportSpec("key", "id", "type")));
// then
assertThat(importUser.size(), is(1));
assertThat(importUser.get(0).authenticationResult.getStatus(), is(Status.notApplicable));
assertThat(importUser.get(0).importerKey, is("key"));
verify(factory).getInstance(getCfgProperties(), "idp");
verify(importer).importUser("id", "type");
// again - should cache negative resolve
// just to have nice 'never'below
reset(importer);
List<ImportResult> importUser2 = impl.importUser(Lists.newArrayList(new UserImportSpec("key", "id", "type")));
assertThat(importUser2.size(), is(1));
assertThat(importUser2.get(0).authenticationResult.getStatus(), is(Status.notApplicable));
verify(importer, never()).importUser("id", "type");
// again - should expire negative resolve cache
Thread.sleep(1001);
List<ImportResult> importUser3 = impl.importUser(Lists.newArrayList(new UserImportSpec("key", "id", "type")));
assertThat(importUser3.size(), is(1));
assertThat(importUser3.get(0).authenticationResult.getStatus(), is(Status.notApplicable));
verify(importer).importUser("id", "type");
}
Aggregations