Rework SslHandlerFactory
[netconf.git] / transport / transport-tls / src / main / java / org / opendaylight / netconf / transport / tls / FixedSslHandlerFactory.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.transport.tls;
9
10 import static java.util.Objects.requireNonNull;
11
12 import io.netty.handler.ssl.SslContext;
13 import java.net.SocketAddress;
14 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tls.client.rev231228.TlsClientGrouping;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tls.server.rev231228.TlsServerGrouping;
17
18 public final class FixedSslHandlerFactory extends SslHandlerFactory {
19     private final SslContext sslContext;
20
21     public FixedSslHandlerFactory(final SslContext sslContext) {
22         this.sslContext = requireNonNull(sslContext);
23     }
24
25     public FixedSslHandlerFactory(final TlsClientGrouping clientParams) throws UnsupportedConfigurationException {
26         this(createSslContext(clientParams));
27     }
28
29     public FixedSslHandlerFactory(final TlsServerGrouping serverParams) throws UnsupportedConfigurationException {
30         this(createSslContext(serverParams));
31     }
32
33     @Override
34     protected SslContext getSslContext(final SocketAddress remoteAddress) {
35         return sslContext;
36     }
37 }