e72e64ae87d1444ead9ffcfb3548aac3b03b2d7f
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.forwarding.xacml.pdp;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ValidationStatus;
25 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
26 import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
27
28 /**
29  * Holds the parameters for the{@link XacmlPdpPolicyForwarder}
30  */
31 public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
32
33     public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getCanonicalName();
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     public boolean isUseHttps() {
45         return useHttps;
46     }
47
48     public String getHostname() {
49         return hostname;
50     }
51
52     public int getPort() {
53         return port;
54     }
55
56     public String getUserName() {
57         return userName;
58     }
59
60     public String getPassword() {
61         return password;
62     }
63
64     public String getClientAuth() {
65         return clientAuth;
66     }
67
68     public boolean isManaged() {
69         return isManaged;
70     }
71
72     public String getPdpGroup() {
73         return pdpGroup;
74     }
75
76     /**
77      * Builder for XacmlPdpPolicyForwarderParameterGroup.
78      */
79     public static class XacmlPdpPolicyForwarderParameterGroupBuilder {
80         private boolean useHttps = false;
81         private String hostname;
82         private int port;
83         private String userName;
84         private String password;
85         private String clientAuth;
86         private boolean isManaged = true;
87         private String pdpGroup;
88
89         public XacmlPdpPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
90             this.useHttps = useHttps;
91             return this;
92         }
93
94         public XacmlPdpPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
95             this.hostname = hostname;
96             return this;
97         }
98
99         public XacmlPdpPolicyForwarderParameterGroupBuilder setPort(final int port) {
100             this.port = port;
101             return this;
102         }
103
104         public XacmlPdpPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
105             this.userName = userName;
106             return this;
107         }
108
109         public XacmlPdpPolicyForwarderParameterGroupBuilder setPassword(final String password) {
110             this.password = password;
111             return this;
112         }
113
114         public XacmlPdpPolicyForwarderParameterGroupBuilder setClientAuth(final String clientAuth) {
115             this.clientAuth = clientAuth;
116             return this;
117         }
118
119         public XacmlPdpPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
120             this.isManaged = isManaged;
121             return this;
122         }
123
124         public XacmlPdpPolicyForwarderParameterGroupBuilder setPdpGroup(final String pdpGroup) {
125             this.pdpGroup = pdpGroup;
126             return this;
127         }
128
129         /**
130          * Creates a new XacmlPapServletPolicyForwarderParameterGroup instance.
131          */
132         public XacmlPdpPolicyForwarderParameterGroup build() {
133             return new XacmlPdpPolicyForwarderParameterGroup(this);
134         }
135     }
136
137     /**
138      * Construct an instance
139      *
140      * @param builder the builder create the instance from
141      */
142     private XacmlPdpPolicyForwarderParameterGroup(final XacmlPdpPolicyForwarderParameterGroupBuilder builder) {
143         this.useHttps = builder.useHttps;
144         this.hostname = builder.hostname;
145         this.port = builder.port;
146         this.userName = builder.userName;
147         this.password = builder.password;
148         this.clientAuth = builder.clientAuth;
149         this.isManaged = builder.isManaged;
150         this.pdpGroup = builder.pdpGroup;
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 }