use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testServiceAnonAuth.
/**
* Test the case where topology has federation provider configured
* and service uses anonymous authentication in which case we should
* add AnonymousFilter to the filter chain.
* @since 1.1.0
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @throws URISyntaxException
* @throws TransformerException
*/
@Test(timeout = MEDIUM_TIMEOUT)
public void testServiceAnonAuth() throws IOException, SAXException, ParserConfigurationException, URISyntaxException, TransformerException {
LOG_ENTER();
final GatewayConfig config = new GatewayTestConfig();
((GatewayTestConfig) config).setXForwardedEnabled(false);
final File targetDir = new File(System.getProperty("user.dir"), "target");
final File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
final File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
final DefaultGatewayServices srvcs = new DefaultGatewayServices();
final Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
final Topology federationTopology = new Topology();
final Topology authenticationTopology = new Topology();
federationTopology.setName("test-cluster");
authenticationTopology.setName("test-cluster");
final Service service = new Service();
service.setRole("RANGER");
service.addUrl("http://localhost:50070/");
federationTopology.addService(service);
authenticationTopology.addService(service);
/* Add federation provider to first topology */
final Provider provider = new Provider();
provider.setRole("federation");
provider.setName("SSOCookieProvider");
provider.setEnabled(true);
Param param = new Param();
param.setName("sso.authentication.provider.url");
param.setValue("https://www.local.com:8443/gateway/knoxsso/api/v1/websso");
provider.addParam(param);
federationTopology.addProvider(provider);
/* Add authentication provider to second topology */
final Provider provider2 = new Provider();
provider2.setRole("authentication");
provider2.setName("ShiroProvider");
provider2.setEnabled(true);
Param param2 = new Param();
param2.setName("contextConfigLocation");
param2.setValue("classpath:app-context-security.xml");
provider2.addParam(param2);
authenticationTopology.addProvider(provider2);
final Provider asserter = new Provider();
asserter.setRole("identity-assertion");
asserter.setName("Default");
asserter.setEnabled(true);
federationTopology.addProvider(asserter);
Provider authorizer = new Provider();
authorizer.setRole("authorization");
authorizer.setName("AclsAuthz");
authorizer.setEnabled(true);
federationTopology.addProvider(authorizer);
authenticationTopology.addProvider(authorizer);
final EnterpriseArchive war = DeploymentFactory.createDeployment(config, federationTopology);
final EnterpriseArchive war2 = DeploymentFactory.createDeployment(config, federationTopology);
final Document web = XmlUtils.readXml(war.get("%2F/WEB-INF/web.xml").getAsset().openStream());
final Document web2 = XmlUtils.readXml(war2.get("%2F/WEB-INF/web.xml").getAsset().openStream());
/* Make sure AnonymousAuthFilter is added to the chain */
final Document gateway = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(gateway, hasXPath("/gateway/resource[1]/pattern", equalTo("/ranger/service/public/**")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.AnonymousAuthFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("rewrite")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/role", equalTo("authorization")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("dispatch")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
final Document gateway2 = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(gateway2, hasXPath("/gateway/resource[1]/pattern", equalTo("/ranger/service/public/**")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("authentication")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.AnonymousAuthFilter")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("rewrite")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[3]/role", equalTo("authorization")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("dispatch")));
assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[4]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
LOG_EXIT();
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class ServiceParameterPropertyInterpreter method interpret.
@Override
public void interpret(String token, String value) throws InterpretException {
if (token == null || token.isEmpty()) {
throw new InterpretException(gatewayResources.serviceParameterNameIsRequiredError());
}
if (value == null || value.isEmpty()) {
throw new InterpretException(gatewayResources.serviceParameterValueIsRequiredError());
}
Param param = new Param();
param.setName(token);
param.setValue(value);
service.addParam(param);
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testSimpleTopology.
@Test(timeout = MEDIUM_TIMEOUT)
public void testSimpleTopology() throws IOException, SAXException, ParserConfigurationException, URISyntaxException, TransformerException {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
// Testing without x-forwarded headers filter
((GatewayTestConfig) config).setXForwardedEnabled(false);
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/webhdfs");
topology.addService(service);
Provider provider = new Provider();
provider.setRole("authentication");
provider.setName("ShiroProvider");
provider.setEnabled(true);
Param param = new Param();
param.setName("contextConfigLocation");
param.setValue("classpath:app-context-security.xml");
provider.addParam(param);
topology.addProvider(provider);
Provider asserter = new Provider();
asserter.setRole("identity-assertion");
asserter.setName("Default");
asserter.setEnabled(true);
topology.addProvider(asserter);
Provider authorizer = new Provider();
authorizer.setRole("authorization");
authorizer.setName("AclsAuthz");
authorizer.setEnabled(true);
topology.addProvider(authorizer);
EnterpriseArchive war = DeploymentFactory.createDeployment(config, topology);
// File dir = new File( System.getProperty( "user.dir" ) );
// File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war" );
Document web = XmlUtils.readXml(war.get("%2F/WEB-INF/web.xml").getAsset().openStream());
assertThat(web, hasXPath("/web-app"));
assertThat(web, hasXPath("/web-app/servlet"));
assertThat(web, hasXPath("/web-app/servlet/servlet-name"));
assertThat(web, hasXPath("/web-app/servlet/servlet-name", equalTo("test-cluster-knox-gateway-servlet")));
assertThat(web, hasXPath("/web-app/servlet/servlet-class", equalTo("org.apache.knox.gateway.GatewayServlet")));
assertThat(web, hasXPath("/web-app/servlet/init-param/param-name", equalTo("gatewayDescriptorLocation")));
assertThat(web, hasXPath("/web-app/servlet/init-param/param-value", equalTo("/WEB-INF/gateway.xml")));
assertThat(web, hasXPath("/web-app/servlet-mapping/servlet-name", equalTo("test-cluster-knox-gateway-servlet")));
assertThat(web, hasXPath("/web-app/servlet-mapping/url-pattern", equalTo("/*")));
Document gateway = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
assertThat(gateway, hasXPath("/gateway/resource[1]/pattern", equalTo("/webhdfs/v1/?**")));
// assertThat( gateway, hasXPath( "/gateway/resource[1]/target", equalTo( "http://localhost:50070/webhdfs/v1/?{**}" ) ) );
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.ResponseCookieFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.shiro.web.servlet.ShiroFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.ShiroSubjectIdentityAdapter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("rewrite")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[5]/role", equalTo("identity-assertion")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[5]/class", equalTo("org.apache.knox.gateway.identityasserter.filter.IdentityAsserterFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/role", equalTo("authorization")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/name", equalTo("AclsAuthz")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[7]/role", equalTo("dispatch")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[7]/name", equalTo("webhdfs")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[7]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/pattern", equalTo("/webhdfs/v1/**?**")));
// assertThat( gateway, hasXPath( "/gateway/resource[2]/target", equalTo( "http://localhost:50070/webhdfs/v1/{path=**}?{**}" ) ) );
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[1]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.ResponseCookieFilter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[2]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[2]/class", equalTo("org.apache.shiro.web.servlet.ShiroFilter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[3]/role", equalTo("authentication")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.ShiroSubjectIdentityAdapter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[4]/role", equalTo("rewrite")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[4]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[5]/role", equalTo("identity-assertion")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[5]/class", equalTo("org.apache.knox.gateway.identityasserter.filter.IdentityAsserterFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/role", equalTo("authorization")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/name", equalTo("AclsAuthz")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[6]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[7]/role", equalTo("dispatch")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[7]/name", equalTo("webhdfs")));
assertThat(gateway, hasXPath("/gateway/resource[2]/filter[7]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
LOG_EXIT();
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testGenericProviderDeploymentContributor.
@Test(timeout = MEDIUM_TIMEOUT)
public void testGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException, TransformerException {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
// ((GatewayTestConfig) config).setDeploymentDir( "clusters" );
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/test-service-url");
topology.addService(service);
Provider provider = new Provider();
provider.setRole("federation");
provider.setName("HeaderPreAuth");
provider.setEnabled(true);
Param param = new Param();
param.setName("filter");
param.setValue("org.opensource.ExistingFilter");
provider.addParam(param);
param = new Param();
param.setName("test-param-name");
param.setValue("test-param-value");
provider.addParam(param);
topology.addProvider(provider);
EnterpriseArchive war = DeploymentFactory.createDeployment(config, topology);
Document gateway = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
// dump( gateway );
// by default the first filter will be the X-Forwarded header filter
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("xforwardedheaders")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/name", equalTo("XForwardedHeaderFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.XForwardedHeaderFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("federation")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/name", equalTo("HeaderPreAuth")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.knox.gateway.preauth.filter.HeaderPreAuthFederationFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/param[1]/name", equalTo("filter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/param[1]/value", equalTo("org.opensource.ExistingFilter")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/param[2]/name", equalTo("test-param-name")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/param[2]/value", equalTo("test-param-value")));
// testing for the adding of missing identity assertion provider - since it isn't explicitly added above
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("identity-assertion")));
assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/name", equalTo("Default")));
LOG_EXIT();
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testInvalidGenericProviderDeploymentContributor.
@Test(timeout = LONG_TIMEOUT)
public void testInvalidGenericProviderDeploymentContributor() throws ParserConfigurationException, SAXException, IOException, TransformerException {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/test-service-url");
topology.addService(service);
Provider provider = new Provider();
provider.setRole("authentication");
provider.setName("generic");
provider.setEnabled(true);
// = new ProviderParam();
Param param;
// Missing filter param.
// param.setName( "filter" );
// param.setValue( "org.opensource.ExistingFilter" );
// provider.addParam( param );
param = new Param();
param.setName("test-param-name");
param.setValue("test-param-value");
provider.addParam(param);
topology.addProvider(provider);
Enumeration<Appender> appenders = NoOpAppender.setUp();
try {
DeploymentFactory.createDeployment(config, topology);
fail("Should have throws IllegalArgumentException");
} catch (DeploymentException e) {
// Expected.
} finally {
NoOpAppender.tearDown(appenders);
}
LOG_EXIT();
}
Aggregations