Search in sources :

Example 86 with GatewayConfig

use of org.apache.knox.gateway.config.GatewayConfig 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();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 87 with GatewayConfig

use of org.apache.knox.gateway.config.GatewayConfig 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();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 88 with GatewayConfig

use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.

the class DeploymentFactoryFuncTest method testDeploymentWithServicesAndApplications.

@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithServicesAndApplications() throws Exception {
    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();
    URL serviceUrl = TestUtils.getResourceUrl(DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml");
    File serviceFile = new File(serviceUrl.toURI());
    File appsDir = serviceFile.getParentFile().getParentFile();
    ((GatewayTestConfig) config).setGatewayApplicationsDir(appsDir.getAbsolutePath());
    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-topology");
    Application app;
    topology.setName("test-cluster");
    Service service = new Service();
    service.setRole("WEBHDFS");
    service.addUrl("http://localhost:50070/test-service-url");
    topology.addService(service);
    app = new Application();
    app.setName("minimal-test-app");
    app.addUrl("/minimal-test-app-path-one");
    topology.addApplication(app);
    app.setName("minimal-test-app");
    app.addUrl("/minimal-test-app-path-two");
    topology.addApplication(app);
    EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
    assertThat(archive, notNullValue());
    Document doc;
    org.jboss.shrinkwrap.api.Node node;
    node = archive.get("META-INF/topology.xml");
    assertThat("Find META-INF/topology.xml", node, notNullValue());
    doc = XmlUtils.readXml(node.getAsset().openStream());
    assertThat("Parse META-INF/topology.xml", doc, notNullValue());
    node = archive.get("%2F");
    assertThat("Find %2F", node, notNullValue());
    node = archive.get("%2F/WEB-INF/gateway.xml");
    assertThat("Find %2F/WEB-INF/gateway.xml", node, notNullValue());
    doc = XmlUtils.readXml(node.getAsset().openStream());
    assertThat("Parse %2F/WEB-INF/gateway.xml", doc, notNullValue());
    WebArchive war = archive.getAsType(WebArchive.class, "%2Fminimal-test-app-path-one");
    assertThat("Find %2Fminimal-test-app-path-one", war, notNullValue());
    node = war.get("/WEB-INF/gateway.xml");
    assertThat("Find %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", node, notNullValue());
    doc = XmlUtils.readXml(node.getAsset().openStream());
    assertThat("Parse %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", doc, notNullValue());
    war = archive.getAsType(WebArchive.class, "%2Fminimal-test-app-path-two");
    assertThat("Find %2Fminimal-test-app-path-two", war, notNullValue());
    node = war.get("/WEB-INF/gateway.xml");
    assertThat("Find %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", node, notNullValue());
    doc = XmlUtils.readXml(node.getAsset().openStream());
    assertThat("Parse %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", doc, notNullValue());
    LOG_EXIT();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) URL(java.net.URL) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) Application(org.apache.knox.gateway.topology.Application) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 89 with GatewayConfig

use of org.apache.knox.gateway.config.GatewayConfig 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();
}
Also used : NoOpAppender(org.apache.knox.test.log.NoOpAppender) Appender(org.apache.log4j.Appender) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 90 with GatewayConfig

use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.

the class RemoteConfigurationMonitorTest method testZooKeeperConfigMonitorSASLNodesExistWithAcceptableACL.

@Test
public void testZooKeeperConfigMonitorSASLNodesExistWithAcceptableACL() throws Exception {
    final String configMonitorName = "zkConfigClient";
    final String alias = "zkPass";
    // Setup the base GatewayConfig mock
    GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gc.getGatewayProvidersConfigDir()).andReturn(providersDir.getAbsolutePath()).anyTimes();
    EasyMock.expect(gc.getGatewayDescriptorsDir()).andReturn(descriptorsDir.getAbsolutePath()).anyTimes();
    EasyMock.expect(gc.getRemoteRegistryConfigurationNames()).andReturn(Collections.singletonList(configMonitorName)).anyTimes();
    final String registryConfig = GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString() + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" + ZK_USERNAME + ";" + GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=Digest;" + GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS + "=" + alias;
    EasyMock.expect(gc.getRemoteRegistryConfiguration(configMonitorName)).andReturn(registryConfig).anyTimes();
    EasyMock.expect(gc.getRemoteConfigurationMonitorClientName()).andReturn(configMonitorName).anyTimes();
    EasyMock.replay(gc);
    AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(alias)).andReturn(ZK_PASSWORD.toCharArray()).anyTimes();
    EasyMock.replay(aliasService);
    RemoteConfigurationRegistryClientService clientService = (new ZooKeeperClientServiceProvider()).newInstance();
    clientService.setAliasService(aliasService);
    clientService.init(gc, Collections.emptyMap());
    clientService.start();
    RemoteConfigurationMonitorFactory.setClientService(clientService);
    RemoteConfigurationMonitor cm = RemoteConfigurationMonitorFactory.get(gc);
    assertNotNull("Failed to load RemoteConfigurationMonitor", cm);
    List<ACL> acls = Arrays.asList(ANY_AUTHENTICATED_USER_ALL);
    client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath(PATH_KNOX);
    client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath(PATH_KNOX_CONFIG);
    client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath(PATH_KNOX_PROVIDERS);
    client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath(PATH_KNOX_DESCRIPTORS);
    // Check that the config nodes really do exist (the monitor will NOT create them if they're present)
    assertNotNull(client.checkExists().forPath(PATH_KNOX));
    assertNotNull(client.checkExists().forPath(PATH_KNOX_CONFIG));
    assertNotNull(client.checkExists().forPath(PATH_KNOX_PROVIDERS));
    assertNotNull(client.checkExists().forPath(PATH_KNOX_DESCRIPTORS));
    try {
        cm.start();
    } catch (Exception e) {
        fail("Failed to start monitor: " + e.getMessage());
    }
    // Test auth violation
    clientService.get(configMonitorName).createEntry("/auth_test/child_node/test1");
    assertNull("Creation should have been prevented since write access is not granted to the test client.", client.checkExists().forPath("/auth_test/child_node/test1"));
    assertTrue("Creation should have been prevented since write access is not granted to the test client.", client.getChildren().forPath("/auth_test/child_node").isEmpty());
    // Validate the expected ACLs on the Knox config znodes (make sure the monitor didn't change them)
    List<ACL> expectedACLs = Collections.singletonList(SASL_TESTUSER_ALL);
    validateKnoxConfigNodeACLs(expectedACLs, client.getACL().forPath(PATH_KNOX));
    validateKnoxConfigNodeACLs(expectedACLs, client.getACL().forPath(PATH_KNOX_CONFIG));
    validateKnoxConfigNodeACLs(expectedACLs, client.getACL().forPath(PATH_KNOX_PROVIDERS));
    validateKnoxConfigNodeACLs(expectedACLs, client.getACL().forPath(PATH_KNOX_DESCRIPTORS));
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) ZooKeeperClientServiceProvider(org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) ACL(org.apache.zookeeper.data.ACL) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Aggregations

GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)90 Test (org.junit.Test)67 File (java.io.File)31 HashMap (java.util.HashMap)24 GatewayConfigImpl (org.apache.knox.gateway.config.impl.GatewayConfigImpl)19 Topology (org.apache.knox.gateway.topology.Topology)17 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 AliasService (org.apache.knox.gateway.services.security.AliasService)12 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)11 IOException (java.io.IOException)9 Service (org.apache.knox.gateway.topology.Service)9 Document (org.w3c.dom.Document)9 ArrayList (java.util.ArrayList)8 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)8 MasterService (org.apache.knox.gateway.services.security.MasterService)8 TopologyService (org.apache.knox.gateway.services.topology.TopologyService)8 KeystoreService (org.apache.knox.gateway.services.security.KeystoreService)7 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)7 List (java.util.List)6