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