Search in sources :

Example 1 with Provider

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

the class EncryptUriDeploymentContributorTest method testDeployment.

@Test
public void testDeployment() throws IOException {
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-acrhive");
    Provider provider = new Provider();
    provider.setEnabled(true);
    provider.setName(EncryptUriDeploymentContributor.PROVIDER_ROLE_NAME);
    Topology topology = new Topology();
    topology.setName("Sample");
    DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
    EasyMock.expect(context.getWebArchive()).andReturn(webArchive).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();
    UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(encEnvironment.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).anyTimes();
    EncryptUriDeploymentContributor contributor = new EncryptUriDeploymentContributor();
    contributor.setAliasService(as);
    assertThat(contributor.getRole(), is(EncryptUriDeploymentContributor.PROVIDER_ROLE_NAME));
    assertThat(contributor.getName(), is(EncryptUriDeploymentContributor.PROVIDER_IMPL_NAME));
    // Just make sure it doesn't blow up.
    contributor.contributeFilter(null, null, null, null, null);
    // 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);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) DeploymentContext(org.apache.knox.gateway.deploy.DeploymentContext) GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) 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 2 with Provider

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

the class SecureQueryDeploymentContributorTest method testDeployment.

@Test
public void testDeployment() throws IOException {
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-acrhive");
    // UrlRewriteRulesDescriptorImpl rewriteRules = new UrlRewriteRulesDescriptorImpl();
    Map<String, String> providerParams = new HashMap<>();
    // providerParams.put( "test-host-external", "test-host-internal" );
    Provider provider = new Provider();
    provider.setEnabled(true);
    provider.setName("secure-query");
    provider.setParams(providerParams);
    Topology topology = new Topology();
    topology.setName("Sample");
    DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
    // EasyMock.expect( context.getDescriptor( "rewrite" ) ).andReturn( rewriteRules ).anyTimes();
    EasyMock.expect(context.getWebArchive()).andReturn(webArchive).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();
    UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock(UrlRewriteEnvironment.class);
    EasyMock.expect(encEnvironment.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(gatewayServices).anyTimes();
    SecureQueryDeploymentContributor contributor = new SecureQueryDeploymentContributor();
    contributor.setAliasService(as);
    assertThat(contributor.getRole(), is("secure-query"));
    assertThat(contributor.getName(), is("default"));
    // Just make sure it doesn't blow up.
    contributor.contributeFilter(null, null, null, null, null);
    // Just make sure it doesn't blow up.
    contributor.initializeContribution(context);
    contributor.contributeProvider(context, provider);
    // HostmapFunctionDescriptor funcDesc = rewriteRules.getFunction( "hostmap" );
    // assertThat( funcDesc.config(), is( "/WEB-INF/hostmap.txt" ) );
    // 
    // Node node = webArchive.get( "/WEB-INF/hostmap.txt" );
    // String asset = IOUtils.toString( node.getAsset().openStream() );
    // assertThat( asset, containsString( "test-host-external=test-host-internal" ) );
    // Just make sure it doesn't blow up.
    contributor.finalizeContribution(context);
}
Also used : UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Topology(org.apache.knox.gateway.topology.Topology) Provider(org.apache.knox.gateway.topology.Provider) DeploymentContext(org.apache.knox.gateway.deploy.DeploymentContext) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) CryptoService(org.apache.knox.gateway.services.security.CryptoService) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) Test(org.junit.Test)

Example 3 with Provider

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

the class DeploymentContextImpl method contributeFilter.

@Override
public void contributeFilter(Service service, ResourceDescriptor resource, String role, String name, List<FilterParamDescriptor> params) {
    ProviderDeploymentContributor contributor = DeploymentFactory.getProviderContributor(providers, role, name);
    Provider provider = getTopology().getProvider(role, name);
    if (provider == null) {
        provider = new Provider();
        provider.setRole(role);
        provider.setName(name);
        provider.setEnabled(true);
    }
    if (provider.isEnabled()) {
        contributor.contributeFilter(this, provider, service, resource, params);
    }
}
Also used : Provider(org.apache.knox.gateway.topology.Provider)

Example 4 with Provider

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

the class DeploymentFactory method contributeProviders.

private static void contributeProviders(DeploymentContext context, Topology topology, Map<String, List<ProviderDeploymentContributor>> providers) {
    for (Provider provider : topology.getProviders()) {
        ProviderDeploymentContributor contributor = getProviderContributor(providers, provider.getRole(), provider.getName());
        if (contributor != null && provider.isEnabled()) {
            try {
                log.contributeProvider(provider.getName(), provider.getRole());
                contributor.contributeProvider(context, provider);
            } catch (Exception e) {
                // Maybe it makes sense to throw exception
                log.failedToContributeProvider(provider.getName(), provider.getRole(), e);
                throw new DeploymentException("Failed to contribute provider.", e);
            }
        }
    }
}
Also used : IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Provider(org.apache.knox.gateway.topology.Provider)

Example 5 with Provider

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

the class DeploymentFactory method addMissingDefaultProviders.

private static void addMissingDefaultProviders(Topology topology) {
    Collection<Provider> providers = topology.getProviders();
    HashMap<String, String> providerMap = new HashMap<>();
    for (Provider provider : providers) {
        providerMap.put(provider.getRole(), provider.getName());
    }
    // work fine at actual server runtime.
    if (PROVIDER_CONTRIBUTOR_MAP.get("identity-assertion") != null) {
        // check for required providers and add the defaults if missing
        if (!providerMap.containsKey("identity-assertion")) {
            Provider idassertion = new Provider();
            idassertion.setRole("identity-assertion");
            idassertion.setName("Default");
            idassertion.setEnabled(true);
            providers.add(idassertion);
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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