5c547673178b5cb7b8428fe9fd789b0d418a91fb
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.forwarding.xacml.pdp;
23
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
27 import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
28
29 /**
30  * Holds the parameters for the{@link XacmlPdpPolicyForwarder}.
31  */
32 public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
33     public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getName();
34
35     private boolean useHttps;
36     private String hostname;
37     private int port;
38     private String userName;
39     private String password;
40     private String clientAuth;
41     private boolean isManaged;
42     private String pdpGroup;
43
44     /**
45      * Construct an instance.
46      *
47      * @param builder the builder create the instance from
48      */
49     private XacmlPdpPolicyForwarderParameterGroup(final XacmlPdpPolicyForwarderParameterGroupBuilder builder) {
50         this.useHttps = builder.useHttps;
51         this.hostname = builder.hostname;
52         this.port = builder.port;
53         this.userName = builder.userName;
54         this.password = builder.password;
55         this.clientAuth = builder.clientAuth;
56         this.isManaged = builder.isManaged;
57         this.pdpGroup = builder.pdpGroup;
58     }
59
60     public boolean isUseHttps() {
61         return useHttps;
62     }
63
64     public String getHostname() {
65         return hostname;
66     }
67
68     public int getPort() {
69         return port;
70     }
71
72     public String getUserName() {
73         return userName;
74     }
75
76     public String getPassword() {
77         return password;
78     }
79
80     public String getClientAuth() {
81         return clientAuth;
82     }
83
84     public boolean isManaged() {
85         return isManaged;
86     }
87
88     public String getPdpGroup() {
89         return pdpGroup;
90     }
91
92     /**
93      * Builder for XacmlPdpPolicyForwarderParameterGroup.
94      */
95     public static class XacmlPdpPolicyForwarderParameterGroupBuilder {
96         private boolean useHttps = false;
97         private String hostname;
98         private int port;
99         private String userName;
100         private String password;
101         private String clientAuth;
102         private boolean isManaged = true;
103         private String pdpGroup;
104
105         public XacmlPdpPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
106             this.useHttps = useHttps;
107             return this;
108         }
109
110         public XacmlPdpPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
111             this.hostname = hostname;
112             return this;
113         }
114
115         public XacmlPdpPolicyForwarderParameterGroupBuilder setPort(final int port) {
116             this.port = port;
117             return this;
118         }
119
120         public XacmlPdpPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
121             this.userName = userName;
122             return this;
123         }
124
125         public XacmlPdpPolicyForwarderParameterGroupBuilder setPassword(final String password) {
126             this.password = password;
127             return this;
128         }
129
130         public XacmlPdpPolicyForwarderParameterGroupBuilder setClientAuth(final String clientAuth) {
131             this.clientAuth = clientAuth;
132             return this;
133         }
134
135         public XacmlPdpPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
136             this.isManaged = isManaged;
137             return this;
138         }
139
140         public XacmlPdpPolicyForwarderParameterGroupBuilder setPdpGroup(final String pdpGroup) {
141             this.pdpGroup = pdpGroup;
142             return this;
143         }
144
145         /**
146          * Creates a new XacmlPapServletPolicyForwarderParameterGroup instance.
147          */
148         public XacmlPdpPolicyForwarderParameterGroup build() {
149             return new XacmlPdpPolicyForwarderParameterGroup(this);
150         }
151     }
152
153     @Override
154     public GroupValidationResult validate() {
155         final GroupValidationResult validationResult = new GroupValidationResult(this);
156         if (!ParameterValidationUtils.validateStringParameter(hostname)) {
157             validationResult.setResult("hostname", ValidationStatus.INVALID,
158                     "must be a non-blank string containing hostname/ipaddress");
159         }
160         if (!ParameterValidationUtils.validateIntParameter(port)) {
161             validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
162         }
163         if (!ParameterValidationUtils.validateStringParameter(userName)) {
164             validationResult.setResult("userName", ValidationStatus.INVALID,
165                     "must be a non-blank string containing userName");
166         }
167         if (!ParameterValidationUtils.validateStringParameter(password)) {
168             validationResult.setResult("password", ValidationStatus.INVALID,
169                     "must be a non-blank string containing password");
170         }
171         if (!ParameterValidationUtils.validateStringParameter(clientAuth)) {
172             validationResult.setResult("clientAuth", ValidationStatus.INVALID,
173                     "must be a non-blank string containing clientAuth");
174         }
175         if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
176             validationResult.setResult("pdpGroup", ValidationStatus.INVALID,
177                     "must be a non-blank string containing pdpGroup");
178         }
179         return validationResult;
180     }
181
182 }