Search in sources :

Example 1 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class HttpBuilder method doBuild.

@Override
protected Http doBuild(AbstractConfigProducer ancestor, Element spec) {
    FilterChains filterChains;
    List<Binding> bindings = new ArrayList<>();
    AccessControl accessControl = null;
    Element filteringElem = XML.getChild(spec, "filtering");
    if (filteringElem != null) {
        filterChains = new FilterChainsBuilder().build(ancestor, filteringElem);
        bindings = readFilterBindings(filteringElem);
        Element accessControlElem = XML.getChild(filteringElem, "access-control");
        if (accessControlElem != null) {
            accessControl = buildAccessControl(ancestor, accessControlElem);
            bindings.addAll(accessControl.getBindings());
            filterChains.add(new Chain<>(FilterChains.emptyChainSpec(ACCESS_CONTROL_CHAIN_ID)));
        }
    } else {
        filterChains = new FilterChainsBuilder().newChainsInstance(ancestor);
    }
    Http http = new Http(bindings, accessControl);
    http.setFilterChains(filterChains);
    buildHttpServers(ancestor, http, spec);
    return http;
}
Also used : Binding(com.yahoo.vespa.model.container.http.Http.Binding) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Http(com.yahoo.vespa.model.container.http.Http) FilterChains(com.yahoo.vespa.model.container.http.FilterChains) AccessControl(com.yahoo.vespa.model.container.http.AccessControl)

Example 2 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method access_control_filter_chain_is_set_up.

@Test
public void access_control_filter_chain_is_set_up() throws Exception {
    Element clusterElem = DomBuilderTest.parse("  <http>", "    <filtering>", "      <access-control domain='foo' />", "    </filtering>", "  </http>");
    Http http = new HttpBuilder().build(root, clusterElem);
    root.freezeModelTopology();
    assertTrue(http.getFilterChains().hasChain(AccessControl.ACCESS_CONTROL_CHAIN_ID));
}
Also used : Element(org.w3c.dom.Element) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 3 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method read_is_disabled_and_write_is_enabled_by_default.

@Test
public void read_is_disabled_and_write_is_enabled_by_default() throws Exception {
    Element clusterElem = DomBuilderTest.parse("  <http>", "    <filtering>", "      <access-control domain='foo' />", "    </filtering>", "  </http>");
    Http http = new HttpBuilder().build(root, clusterElem);
    root.freezeModelTopology();
    assertFalse("Wrong default value for read.", http.getAccessControl().get().readEnabled);
    assertTrue("Wrong default value for write.", http.getAccessControl().get().writeEnabled);
}
Also used : Element(org.w3c.dom.Element) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 4 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method rest_api_can_be_excluded_by_excluding_one_of_its_bindings.

@Test
public void rest_api_can_be_excluded_by_excluding_one_of_its_bindings() throws Exception {
    final String restApiPath = "api/v0";
    final String notExcludedBinding = "http://*/" + restApiPath + Jersey2Servlet.BINDING_SUFFIX;
    ;
    final String excludedBinding = "https://*/" + restApiPath + Jersey2Servlet.BINDING_SUFFIX;
    ;
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", httpWithExcludedBinding(excludedBinding), "  <rest-api jersey2='true' path='" + restApiPath + "' />", "</jdisc>");
    Http http = getHttp(clusterElem);
    assertFalse("Excluded binding was not removed.", containsBinding(http.getBindings(), excludedBinding));
    assertFalse("Not all bindings of an excluded rest-api were removed.", containsBinding(http.getBindings(), notExcludedBinding));
}
Also used : Element(org.w3c.dom.Element) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 5 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method servlet_can_be_excluded_by_excluding_one_of_its_bindings.

@Test
public void servlet_can_be_excluded_by_excluding_one_of_its_bindings() throws Exception {
    final String servletPath = "servlet/path";
    final String notExcludedBinding = "https://*/" + servletPath;
    final String excludedBinding = "http://*/" + servletPath;
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", httpWithExcludedBinding(excludedBinding), "  <servlet id='foo' class='bar' bundle='baz'>", "    <path>" + servletPath + "</path>", "  </servlet>", "</jdisc>");
    Http http = getHttp(clusterElem);
    assertFalse("Excluded binding was not removed.", containsBinding(http.getBindings(), excludedBinding));
    assertFalse("Not all bindings of an excluded servlet were removed.", containsBinding(http.getBindings(), notExcludedBinding));
}
Also used : Element(org.w3c.dom.Element) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Aggregations

Http (com.yahoo.vespa.model.container.http.Http)11 Element (org.w3c.dom.Element)10 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)9 Test (org.junit.Test)9 HttpBuilder (com.yahoo.vespa.model.container.http.xml.HttpBuilder)6 AccessControl (com.yahoo.vespa.model.container.http.AccessControl)4 ContainerCluster (com.yahoo.vespa.model.container.ContainerCluster)3 Binding (com.yahoo.vespa.model.container.http.Http.Binding)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 CollectionUtil (com.yahoo.collections.CollectionUtil)2 TestUtil (com.yahoo.config.model.test.TestUtil)2 TestUtil.joinLines (com.yahoo.config.model.test.TestUtil.joinLines)2 StateHandler (com.yahoo.container.jdisc.state.StateHandler)2 Jersey2Servlet (com.yahoo.vespa.model.container.jersey.Jersey2Servlet)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2