0a789904c071fe76230413c1ef260123b183390d
[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     public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getCanonicalName();
33
34     private boolean useHttps;
35     private String hostname;
36     private int port;
37     private String userName;
38     private String password;
39     private String clientAuth;
40     private boolean isManaged;
41     private String pdpGroup;
42
43     public boolean isUseHttps() {
44         return useHttps;
45     }
46
47     public String getHostname() {
48         return hostname;
49     }
50
51     public int getPort() {
52         return port;
53     }
54
55     public String getUserName() {
56         return userName;
57     }
58
59     public String getPassword() {
60         return password;
61     }
62
63     public String getClientAuth() {
64         return clientAuth;
65     }
66
67     public boolean isManaged() {
68         return isManaged;
69     }
70
71     public String getPdpGroup() {
72         return pdpGroup;
73     }
74
75     /**
76      * Builder for XacmlPdpPolicyForwarderParameterGroup.
77      */
78     public static class XacmlPdpPolicyForwarderParameterGroupBuilder {
79         private boolean useHttps = false;
80         private String hostname;
81         private int port;
82         private String userName;
83         private String password;
84         private String clientAuth;
85         private boolean isManaged = true;
86         private String pdpGroup;
87
88         public XacmlPdpPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
89             this.useHttps = useHttps;
90             return this;
91         }
92
93         public XacmlPdpPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
94             this.hostname = hostname;
95             return this;
96         }
97
98         public XacmlPdpPolicyForwarderParameterGroupBuilder setPort(final int port) {
99             this.port = port;
100             return this;
101         }
102
103         public XacmlPdpPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
104             this.userName = userName;
105             return this;
106         }
107
108         public XacmlPdpPolicyForwarderParameterGroupBuilder setPassword(final String password) {
109             this.password = password;
110             return this;
111         }
112
113         public XacmlPdpPolicyForwarderParameterGroupBuilder setClientAuth(final String clientAuth) {
114             this.clientAuth = clientAuth;
115             return this;
116         }
117
118         public XacmlPdpPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
119             this.isManaged = isManaged;
120             return this;
121         }
122
123         public XacmlPdpPolicyForwarderParameterGroupBuilder setPdpGroup(final String pdpGroup) {
124             this.pdpGroup = pdpGroup;
125             return this;
126         }
127
128         /**
129          * Creates a new XacmlPapServletPolicyForwarderParameterGroup instance.
130          */
131         public XacmlPdpPolicyForwarderParameterGroup build() {
132             return new XacmlPdpPolicyForwarderParameterGroup(this);
133         }
134     }
135
136     /**
137      * Construct an instance
138      *
139      * @param builder the builder create the instance from
140      */
141     private XacmlPdpPolicyForwarderParameterGroup(final XacmlPdpPolicyForwarderParameterGroupBuilder builder) {
142         this.useHttps = builder.useHttps;
143         this.hostname = builder.hostname;
144         this.port = builder.port;
145         this.userName = builder.userName;
146         this.password = builder.password;
147         this.clientAuth = builder.clientAuth;
148         this.isManaged = builder.isManaged;
149         this.pdpGroup = builder.pdpGroup;
150     }
151
152     @Override
153     public GroupValidationResult validate() {
154         final GroupValidationResult validationResult = new GroupValidationResult(this);
155         if (!ParameterValidationUtils.validateStringParameter(hostname)) {
156             validationResult.setResult("hostname", ValidationStatus.INVALID,
157                     "must be a non-blank string containing hostname/ipaddress");
158         }
159         if (!ParameterValidationUtils.validateIntParameter(port)) {
160             validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
161         }
162         if (!ParameterValidationUtils.validateStringParameter(userName)) {
163             validationResult.setResult("userName", ValidationStatus.INVALID,
164                     "must be a non-blank string containing userName");
165         }
166         if (!ParameterValidationUtils.validateStringParameter(password)) {
167             validationResult.setResult("password", ValidationStatus.INVALID,
168                     "must be a non-blank string containing password");
169         }
170         if (!ParameterValidationUtils.validateStringParameter(clientAuth)) {
171             validationResult.setResult("clientAuth", ValidationStatus.INVALID,
172                     "must be a non-blank string containing clientAuth");
173         }
174         if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
175             validationResult.setResult("pdpGroup", ValidationStatus.INVALID,
176                     "must be a non-blank string containing pdpGroup");
177         }
178         return validationResult;
179     }
180
181 }