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);
}
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);
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations