Search in sources :

Example 1 with AccessControl

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

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

the class AccessControlTest method properties_are_set_from_xml.

@Test
public void properties_are_set_from_xml() throws Exception {
    Element clusterElem = DomBuilderTest.parse("  <http>", "    <filtering>", "      <access-control domain='my-domain'>", "        <application>my-app</application>", "        <vespa-domain>custom-vespa-domain</vespa-domain>", "      </access-control>", "    </filtering>", "  </http>");
    Http http = new HttpBuilder().build(root, clusterElem);
    root.freezeModelTopology();
    AccessControl accessControl = http.getAccessControl().get();
    assertEquals("Wrong domain.", "my-domain", accessControl.domain);
    assertEquals("Wrong application.", "my-app", accessControl.applicationId);
    assertEquals("Wrong vespa-domain.", "custom-vespa-domain", accessControl.vespaDomain.get());
}
Also used : Element(org.w3c.dom.Element) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Http(com.yahoo.vespa.model.container.http.Http) AccessControl(com.yahoo.vespa.model.container.http.AccessControl) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 3 with AccessControl

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

the class HttpBuilder method buildAccessControl.

private AccessControl buildAccessControl(AbstractConfigProducer ancestor, Element accessControlElem) {
    String application = XmlHelper.getOptionalChildValue(accessControlElem, "application").orElse(getDeployedApplicationId(ancestor).value());
    AccessControl.Builder builder = new AccessControl.Builder(accessControlElem.getAttribute("domain"), application);
    getContainerCluster(ancestor).ifPresent(cluster -> {
        builder.setHandlers(cluster.getHandlers());
        builder.setServlets(cluster.getAllServlets());
    });
    XmlHelper.getOptionalAttribute(accessControlElem, "read").ifPresent(readAttr -> builder.readEnabled(Boolean.valueOf(readAttr)));
    XmlHelper.getOptionalAttribute(accessControlElem, "write").ifPresent(writeAttr -> builder.writeEnabled(Boolean.valueOf(writeAttr)));
    Element excludeElem = XML.getChild(accessControlElem, "exclude");
    if (excludeElem != null) {
        XML.getChildren(excludeElem, "binding").stream().map(XML::getValue).forEach(builder::excludeBinding);
    }
    XmlHelper.getOptionalChildValue(accessControlElem, "vespa-domain").ifPresent(builder::vespaDomain);
    return builder.build();
}
Also used : VespaDomBuilder(com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder) Element(org.w3c.dom.Element) AccessControl(com.yahoo.vespa.model.container.http.AccessControl)

Aggregations

AccessControl (com.yahoo.vespa.model.container.http.AccessControl)3 Element (org.w3c.dom.Element)3 Http (com.yahoo.vespa.model.container.http.Http)2 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 VespaDomBuilder (com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder)1 FilterChains (com.yahoo.vespa.model.container.http.FilterChains)1 Binding (com.yahoo.vespa.model.container.http.Http.Binding)1 HttpBuilder (com.yahoo.vespa.model.container.http.xml.HttpBuilder)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1