Search in sources :

Example 1 with Binding

use of com.yahoo.vespa.model.container.http.Http.Binding 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 Binding

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

the class HttpBuilder method readFilterBindings.

private List<Binding> readFilterBindings(Element filteringSpec) {
    List<Binding> result = new ArrayList<>();
    for (Element child : XML.getChildren(filteringSpec)) {
        String tagName = child.getTagName();
        if ((tagName.equals("request-chain") || tagName.equals("response-chain"))) {
            ComponentSpecification chainId = XmlHelper.getIdRef(child);
            for (Element bindingSpec : XML.getChildren(child, "binding")) {
                String binding = XML.getValue(bindingSpec);
                result.add(new Binding(chainId, binding));
            }
        }
    }
    return result;
}
Also used : Binding(com.yahoo.vespa.model.container.http.Http.Binding) ComponentSpecification(com.yahoo.component.ComponentSpecification) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 3 with Binding

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

the class AccessControlTest method access_control_filter_chain_has_correct_handler_bindings.

@Test
public void access_control_filter_chain_has_correct_handler_bindings() throws Exception {
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", "  <search/>", "  <document-api/>", "  <handler id='custom.Handler'>", "    <binding>http://*/custom-handler/*</binding>", "  </handler>", "  <http>", "    <filtering>", "      <access-control domain='foo' />", "    </filtering>", "  </http>", "</jdisc>");
    Http http = getHttp(clusterElem);
    Set<String> foundRequiredBindings = REQUIRED_HANDLER_BINDINGS.stream().filter(requiredBinding -> containsBinding(http.getBindings(), requiredBinding)).collect(Collectors.toSet());
    Set<String> missingRequiredBindings = new HashSet<>(REQUIRED_HANDLER_BINDINGS);
    missingRequiredBindings.removeAll(foundRequiredBindings);
    assertTrue("Access control chain was not bound to: " + CollectionUtil.mkString(missingRequiredBindings, ", "), missingRequiredBindings.isEmpty());
    FORBIDDEN_HANDLER_BINDINGS.forEach(forbiddenBinding -> http.getBindings().forEach(binding -> assertFalse("Access control chain was bound to: " + binding.binding, binding.binding.contains(forbiddenBinding))));
}
Also used : StateHandler(com.yahoo.container.jdisc.state.StateHandler) ImmutableSet(com.google.common.collect.ImmutableSet) TestUtil(com.yahoo.config.model.test.TestUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Jersey2Servlet(com.yahoo.vespa.model.container.jersey.Jersey2Servlet) TestUtil.joinLines(com.yahoo.config.model.test.TestUtil.joinLines) HashSet(java.util.HashSet) Binding(com.yahoo.vespa.model.container.http.Http.Binding) ContainerCluster(com.yahoo.vespa.model.container.ContainerCluster) Element(org.w3c.dom.Element) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) CollectionUtil(com.yahoo.collections.CollectionUtil) AccessControl(com.yahoo.vespa.model.container.http.AccessControl) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest) Http(com.yahoo.vespa.model.container.http.Http) Assert.assertEquals(org.junit.Assert.assertEquals) Element(org.w3c.dom.Element) Http(com.yahoo.vespa.model.container.http.Http) HashSet(java.util.HashSet) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Aggregations

Binding (com.yahoo.vespa.model.container.http.Http.Binding)3 Element (org.w3c.dom.Element)3 AccessControl (com.yahoo.vespa.model.container.http.AccessControl)2 Http (com.yahoo.vespa.model.container.http.Http)2 ArrayList (java.util.ArrayList)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 CollectionUtil (com.yahoo.collections.CollectionUtil)1 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 TestUtil (com.yahoo.config.model.test.TestUtil)1 TestUtil.joinLines (com.yahoo.config.model.test.TestUtil.joinLines)1 StateHandler (com.yahoo.container.jdisc.state.StateHandler)1 ContainerCluster (com.yahoo.vespa.model.container.ContainerCluster)1 FilterChains (com.yahoo.vespa.model.container.http.FilterChains)1 HttpBuilder (com.yahoo.vespa.model.container.http.xml.HttpBuilder)1 Jersey2Servlet (com.yahoo.vespa.model.container.jersey.Jersey2Servlet)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1