Search in sources :

Example 21 with Provider

use of org.apache.knox.gateway.topology.Provider in project knox by apache.

the class TopologyRulesModuleTest method testParseSimpleTopologyXmlInKnoxFormat.

@Test
public void testParseSimpleTopologyXmlInKnoxFormat() throws IOException, SAXException, URISyntaxException {
    Digester digester = loader.newDigester();
    String name = "org/apache/knox/gateway/topology/xml/simple-topology-knox-format.xml";
    URL url = ClassLoader.getSystemResource(name);
    assertThat("Failed to find URL for resource " + name, url, notNullValue());
    File file = new File(url.getFile());
    TopologyBuilder topologyBuilder = digester.parse(url);
    Topology topology = topologyBuilder.build();
    assertThat("Failed to parse resource " + name, topology, notNullValue());
    topology.setTimestamp(file.lastModified());
    assertThat(topology.getName(), is("topology"));
    assertThat(topology.getTimestamp(), is(file.lastModified()));
    assertThat(topology.getServices().size(), is(3));
    Service comp = topology.getServices().iterator().next();
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("WEBHDFS"));
    assertThat(comp.getVersion().toString(), is("2.4.0"));
    assertThat(comp.getUrls().size(), is(2));
    assertThat(comp.getUrls(), hasItem("http://host1:80/webhdfs"));
    assertThat(comp.getUrls(), hasItem("http://host2:80/webhdfs"));
    Provider provider = topology.getProviders().iterator().next();
    assertThat(provider, notNullValue());
    assertThat(provider.isEnabled(), is(true));
    assertThat(provider.getRole(), is("authentication"));
    assertThat(provider.getParams().size(), is(5));
    Service service = topology.getService("WEBHDFS", "webhdfs", new Version(2, 4, 0));
    assertEquals(comp, service);
    comp = topology.getService("RESOURCEMANAGER", null, new Version("2.5.0"));
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("RESOURCEMANAGER"));
    assertThat(comp.getVersion().toString(), is("2.5.0"));
    assertThat(comp.getUrl(), is("http://host1:8088/ws"));
    comp = topology.getService("HIVE", "hive", null);
    assertThat(comp, notNullValue());
    assertThat(comp.getRole(), is("HIVE"));
    assertThat(comp.getName(), is("hive"));
    assertThat(comp.getUrl(), is("http://host2:10001/cliservice"));
}
Also used : TopologyBuilder(org.apache.knox.gateway.topology.builder.TopologyBuilder) Version(org.apache.knox.gateway.topology.Version) Digester(org.apache.commons.digester3.Digester) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) File(java.io.File) URL(java.net.URL) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Example 22 with Provider

use of org.apache.knox.gateway.topology.Provider in project knox by apache.

the class DeploymentFactory method collectTopologyProviders.

private static void collectTopologyProviders(Topology topology, Map<String, List<ProviderDeploymentContributor>> defaults) {
    for (Provider provider : topology.getProviders()) {
        String name = provider.getName();
        if (name != null) {
            String role = provider.getRole();
            Map<String, ProviderDeploymentContributor> nameMap = PROVIDER_CONTRIBUTOR_MAP.get(role);
            if (nameMap != null) {
                ProviderDeploymentContributor contributor = nameMap.get(name);
                // If there isn't a contributor with this role/name try to find a "*" contributor.
                if (contributor == null) {
                    nameMap = PROVIDER_CONTRIBUTOR_MAP.get("*");
                    if (nameMap != null) {
                        contributor = nameMap.get(name);
                    }
                }
                if (contributor != null) {
                    List list = defaults.get(role);
                    if (list == null) {
                        list = new ArrayList(1);
                        defaults.put(role, list);
                    }
                    if (!list.contains(contributor)) {
                        list.add(contributor);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Provider(org.apache.knox.gateway.topology.Provider)

Example 23 with Provider

use of org.apache.knox.gateway.topology.Provider in project knox by apache.

the class ShiroDeploymentContributorTest method testDeployment.

@Test
public void testDeployment() throws IOException {
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-archive");
    Map<String, String> providerParams = new HashMap<>();
    Provider provider = new Provider();
    provider.setEnabled(true);
    provider.setName("shiro");
    provider.setParams(providerParams);
    Topology topology = new Topology();
    topology.setName("Sample");
    DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
    EasyMock.expect(context.getWebArchive()).andReturn(webArchive).anyTimes();
    EasyMock.expect(context.getWebAppDescriptor()).andReturn(Descriptors.create(WebAppDescriptor.class)).anyTimes();
    EasyMock.expect(context.getTopology()).andReturn(topology).anyTimes();
    EasyMock.replay(context);
    AliasService as = EasyMock.createNiceMock(AliasService.class);
    CryptoService cryptoService = new DefaultCryptoService();
    ((DefaultCryptoService) cryptoService).setAliasService(as);
    GatewayServices gatewayServices = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(gatewayServices.getService(GatewayServices.CRYPTO_SERVICE)).andReturn(cryptoService).anyTimes();
    ShiroDeploymentContributor contributor = new ShiroDeploymentContributor();
    assertThat(contributor.getRole(), is("authentication"));
    assertThat(contributor.getName(), is("ShiroProvider"));
    // Just make sure it doesn't blow up.
    contributor.initializeContribution(context);
    contributor.contributeProvider(context, provider);
    // Just make sure it doesn't blow up.
    contributor.finalizeContribution(context);
    assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isHttpOnly(), is(true));
    assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isSecure(), is(true));
}
Also used : DeploymentContext(org.apache.knox.gateway.deploy.DeploymentContext) GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) CryptoService(org.apache.knox.gateway.services.security.CryptoService) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Topology(org.apache.knox.gateway.topology.Topology) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Example 24 with Provider

use of org.apache.knox.gateway.topology.Provider in project knox by apache.

the class WebAppSecContributor method contributeFilter.

@Override
public void contributeFilter(DeploymentContext context, Provider provider, Service service, ResourceDescriptor resource, List<FilterParamDescriptor> params) {
    Provider webappsec = context.getTopology().getProvider(ROLE, NAME);
    if (webappsec != null && webappsec.isEnabled()) {
        Map<String, String> map = provider.getParams();
        if (params == null) {
            params = new ArrayList<FilterParamDescriptor>();
        }
        Map<String, String> providerParams = provider.getParams();
        // CORS support
        String corsEnabled = map.get(CORS_ENABLED);
        if (corsEnabled != null && "true".equals(corsEnabled)) {
            provisionConfig(resource, providerParams, params, "cors.");
            resource.addFilter().name(getName() + CORS_SUFFIX).role(getRole()).impl(CORS_FILTER_CLASSNAME).params(params);
        }
        // CRSF
        params = new ArrayList<FilterParamDescriptor>();
        String csrfEnabled = map.get(CSRF_ENABLED);
        if (csrfEnabled != null && "true".equals(csrfEnabled)) {
            provisionConfig(resource, providerParams, params, "csrf.");
            resource.addFilter().name(getName() + CSRF_SUFFIX).role(getRole()).impl(CSRF_FILTER_CLASSNAME).params(params);
        }
        // X-Frame-Options - clickjacking protection
        params = new ArrayList<FilterParamDescriptor>();
        String xframeOptionsEnabled = map.get(XFRAME_OPTIONS_ENABLED);
        if (xframeOptionsEnabled != null && "true".equals(xframeOptionsEnabled)) {
            provisionConfig(resource, providerParams, params, "xframe.");
            resource.addFilter().name(getName() + XFRAME_OPTIONS_SUFFIX).role(getRole()).impl(XFRAME_OPTIONS_FILTER_CLASSNAME).params(params);
        }
        // X-XSS-Protection - browser xss protection
        params = new ArrayList<FilterParamDescriptor>();
        String xssProtectionEnabled = map.get(XSS_PROTECTION_ENABLED);
        if (xssProtectionEnabled != null && "true".equals(xssProtectionEnabled)) {
            provisionConfig(resource, providerParams, params, "xss.");
            resource.addFilter().name(getName() + XSS_PROTECTION_SUFFIX).role(getRole()).impl(XSS_PROTECTION_FILTER_CLASSNAME).params(params);
        }
        // HTTP Strict-Transport-Security
        params = new ArrayList<FilterParamDescriptor>();
        String strictTranportEnabled = map.get(STRICT_TRANSPORT_ENABLED);
        if (strictTranportEnabled != null && "true".equals(strictTranportEnabled)) {
            provisionConfig(resource, providerParams, params, "strict.");
            resource.addFilter().name(getName() + STRICT_TRANSPORT_SUFFIX).role(getRole()).impl(STRICT_TRANSPORT_FILTER_CLASSNAME).params(params);
        }
    }
}
Also used : FilterParamDescriptor(org.apache.knox.gateway.descriptor.FilterParamDescriptor) Provider(org.apache.knox.gateway.topology.Provider)

Example 25 with Provider

use of org.apache.knox.gateway.topology.Provider in project knox by apache.

the class HaProviderDeploymentContributorTest method createHaProvider.

private static Provider createHaProvider(Map<String, String> params) {
    Provider provider = EasyMock.createNiceMock(Provider.class);
    EasyMock.expect(provider.getRole()).andReturn("ha").anyTimes();
    EasyMock.expect(provider.getName()).andReturn("HaProvider").anyTimes();
    EasyMock.expect(provider.getParams()).andReturn(params).anyTimes();
    EasyMock.replay(provider);
    return provider;
}
Also used : Provider(org.apache.knox.gateway.topology.Provider)

Aggregations

Provider (org.apache.knox.gateway.topology.Provider)30 Topology (org.apache.knox.gateway.topology.Topology)20 Test (org.junit.Test)20 Service (org.apache.knox.gateway.topology.Service)17 HashMap (java.util.HashMap)14 DeploymentContext (org.apache.knox.gateway.deploy.DeploymentContext)10 File (java.io.File)9 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)9 Param (org.apache.knox.gateway.topology.Param)7 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)6 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)5 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)5 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)5 URL (java.net.URL)4 HashSet (java.util.HashSet)4 Digester (org.apache.commons.digester3.Digester)4 HaDescriptor (org.apache.knox.gateway.ha.provider.HaDescriptor)4 TopologyBuilder (org.apache.knox.gateway.topology.builder.TopologyBuilder)4 FilterParamDescriptor (org.apache.knox.gateway.descriptor.FilterParamDescriptor)3 GatewayServices (org.apache.knox.gateway.services.GatewayServices)3