Update for SNI Chcecking
[policy/apex-pdp.git] / plugins / plugins-event / plugins-event-carrier / plugins-event-carrier-restserver / src / main / java / org / onap / policy / apex / plugins / event / carrier / restserver / RestServerCarrierTechnologyParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019,2023 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.plugins.event.carrier.restserver;
24
25 import lombok.AccessLevel;
26 import lombok.Getter;
27 import lombok.Setter;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
30 import org.onap.policy.common.parameters.BeanValidationResult;
31 import org.onap.policy.common.parameters.ValidationStatus;
32 import org.onap.policy.models.base.Validated;
33
34 /**
35  * Apex parameters for REST as an event carrier technology with Apex as a REST client.
36  *
37  * <p>The parameters for this plugin are:
38  * <ol>
39  * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
40  * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
41  * only on REST server event inputs.
42  * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
43  * event inputs in standalone mode.
44  * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
45  * inputs in standalone mode.
46  * </ol>
47  *
48  * @author Liam Fallon (liam.fallon@ericsson.com)
49  */
50 @Getter
51 public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
52     // @formatter:off
53     private static final int MIN_USER_PORT =  1024;
54     private static final int MAX_USER_PORT = 65535;
55
56     /** The label of this carrier technology. */
57     public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
58
59     /** The producer plugin class for the REST carrier technology. */
60     public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getName();
61
62     /** The consumer plugin class for the REST carrier technology. */
63     public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getName();
64
65     // REST server parameters
66     @Setter(AccessLevel.PACKAGE)
67     private boolean standalone = false;
68     @Setter(AccessLevel.PACKAGE)
69     private String  host       = null;
70     @Setter(AccessLevel.PACKAGE)
71     private int     port       = -1;
72     private String userName;
73     private String password;
74     private boolean https;
75     private boolean sniHostCheck;
76     private boolean aaf;
77     // @formatter:on
78
79     /**
80      * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
81      * service.
82      */
83     public RestServerCarrierTechnologyParameters() {
84         super();
85
86         // Set the carrier technology properties for the web socket carrier technology
87         this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
88         this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
89         this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
90     }
91
92     /**
93      * {@inheritDoc}.
94      */
95     @Override
96     public BeanValidationResult validate() {
97         final BeanValidationResult result = super.validate();
98
99         // Check if host is defined, it is only defined on REST server consumers
100         if (standalone) {
101             if (StringUtils.isBlank(host)) {
102                 result.addResult("host", host, ValidationStatus.INVALID, Validated.IS_BLANK);
103             }
104
105             // Check if port is defined, it is only defined on REST server consumers
106             if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
107                 result.addResult("port", port, ValidationStatus.INVALID, "must be between 1024 and 65535");
108             }
109         } else {
110             if (host != null) {
111                 result.addResult("host", host, ValidationStatus.INVALID, "should be specified only in standalone mode");
112             }
113             if (port != -1) {
114                 result.addResult("port", port, ValidationStatus.INVALID, "should be specified only in standalone mode");
115             }
116         }
117
118         return result;
119     }
120 }