aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/http/xml/JettyConnectorBuilder.java
blob: 4c41aaa504cd78c5d82bcf8c73b77b1410356241 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http.xml;

import com.yahoo.config.model.builder.xml.XmlHelper;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder;
import com.yahoo.vespa.model.container.component.SimpleComponent;
import com.yahoo.vespa.model.container.http.ConnectorFactory;
import com.yahoo.vespa.model.container.http.ssl.CustomSslProvider;
import com.yahoo.vespa.model.container.http.ssl.DefaultSslProvider;
import com.yahoo.vespa.model.container.http.ssl.DummySslProvider;
import org.w3c.dom.Element;

import java.util.Optional;

/**
 * @author Einar M R Rosenvinge
 * @author mortent
 */
public class JettyConnectorBuilder extends VespaDomBuilder.DomConfigProducerBuilder<ConnectorFactory>  {

    @Override
    protected ConnectorFactory doBuild(DeployState deployState, AbstractConfigProducer ancestor, Element serverSpec) {
        String name = XmlHelper.getIdString(serverSpec);
        int port = HttpBuilder.readPort(serverSpec, deployState.isHosted(), deployState.getDeployLogger());

        SimpleComponent sslProviderComponent = getSslConfigComponents(name, serverSpec);
        return new ConnectorFactory(name, port, sslProviderComponent);
    }

    SimpleComponent getSslConfigComponents(String serverName, Element serverSpec) {
        Element sslConfigurator = XML.getChild(serverSpec, "ssl");
        Element sslProviderConfigurator = XML.getChild(serverSpec, "ssl-provider");

        if (sslConfigurator != null) {
            String privateKeyFile = XML.getValue(XML.getChild(sslConfigurator, "private-key-file"));
            String certificateFile = XML.getValue(XML.getChild(sslConfigurator, "certificate-file"));
            Optional<String> caCertificateFile = XmlHelper.getOptionalChildValue(sslConfigurator, "ca-certificates-file");
            Optional<String> clientAuthentication = XmlHelper.getOptionalChildValue(sslConfigurator, "client-authentication");
            return new DefaultSslProvider(
                    serverName,
                    privateKeyFile,
                    certificateFile,
                    caCertificateFile.orElse(null),
                    clientAuthentication.orElse(null));
        } else if (sslProviderConfigurator != null) {
            String className = sslProviderConfigurator.getAttribute("class");
            String bundle = sslProviderConfigurator.getAttribute("bundle");
            return new CustomSslProvider(serverName, className, bundle);
        } else {
            return new DummySslProvider(serverName);
        }
    }
}