Search in sources :

Example 1 with CrossSiteOriginFilter

use of com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter in project dolphin-platform by canoo.

the class CorsModule method initialize.

@Override
public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final PlatformConfiguration configuration = coreComponents.getConfiguration();
    final List<String> endpointList = configuration.getListProperty(CORS_ENDPOINTS_URL_MAPPINGS, CORS_ENDPOINTS_URL_MAPPINGS_DEFAULT_VALUE);
    final String[] endpoints = endpointList.toArray(new String[endpointList.size()]);
    final CrossSiteOriginFilter filter = new CrossSiteOriginFilter(configuration);
    final FilterRegistration.Dynamic createdFilter = servletContext.addFilter(CORS_FILTER, filter);
    createdFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, endpoints);
}
Also used : CrossSiteOriginFilter(com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter) PlatformConfiguration(com.canoo.platform.core.PlatformConfiguration) ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) FilterRegistration(javax.servlet.FilterRegistration)

Example 2 with CrossSiteOriginFilter

use of com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter in project dolphin-platform by canoo.

the class CrossSiteOriginFilterTest method testCommaSeparatedStringWithValidList.

@Test
public void testCommaSeparatedStringWithValidList() {
    final CrossSiteOriginFilter crossSiteOriginFilter = new CrossSiteOriginFilter(new ServerConfiguration());
    final String commaSeparatedList = crossSiteOriginFilter.getAsCommaSeparatedList(Arrays.asList("origin", "authorization", "accept"));
    assertEquals("origin,authorization,accept", commaSeparatedList);
}
Also used : CrossSiteOriginFilter(com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter) ServerConfiguration(com.canoo.dp.impl.server.config.ServerConfiguration) Test(org.testng.annotations.Test)

Example 3 with CrossSiteOriginFilter

use of com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter in project dolphin-platform by canoo.

the class CrossSiteOriginFilterTest method testCommaSeparatedList.

@Test(expectedExceptions = NullPointerException.class)
public void testCommaSeparatedList() {
    final CrossSiteOriginFilter crossSiteOriginFilter = new CrossSiteOriginFilter(new ServerConfiguration());
    crossSiteOriginFilter.getAsCommaSeparatedList(null);
}
Also used : CrossSiteOriginFilter(com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter) ServerConfiguration(com.canoo.dp.impl.server.config.ServerConfiguration) Test(org.testng.annotations.Test)

Aggregations

CrossSiteOriginFilter (com.canoo.dp.impl.server.servlet.CrossSiteOriginFilter)3 ServerConfiguration (com.canoo.dp.impl.server.config.ServerConfiguration)2 Test (org.testng.annotations.Test)2 PlatformConfiguration (com.canoo.platform.core.PlatformConfiguration)1 DispatcherType (javax.servlet.DispatcherType)1 FilterRegistration (javax.servlet.FilterRegistration)1 ServletContext (javax.servlet.ServletContext)1