2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.parameters;
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25 import org.onap.policy.common.parameters.ValidationStatus;
26 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
29 * Class to hold all parameters needed for xacml pdp rest server.
32 public class RestServerParameters implements ParameterGroup {
36 private String userName;
37 private String password;
40 * Constructor for instantiating RestServerParameters.
42 * @param host the host name
43 * @param port the port
44 * @param userName the user name
45 * @param password the password
47 public RestServerParameters(final String host, final int port, final String userName, final String password) {
51 this.userName = userName;
52 this.password = password;
56 * Return the name of this RestServerParameters instance.
58 * @return name the name of this RestServerParameters
61 public String getName() {
66 * Return the host of this RestServerParameters instance.
70 public String getHost() {
75 * Return the port of this RestServerParameters instance.
79 public int getPort() {
84 * Return the user name of this RestServerParameters instance.
86 * @return the userName
88 public String getUserName() {
93 * Return the password of this RestServerParameters instance.
95 * @return the password
97 public String getPassword() {
102 * Set the name of this RestServerParameters instance.
104 * @param name the name to set
107 public void setName(final String name) {
112 * Validate the rest server parameters.
114 * @return the result of the validation
117 public GroupValidationResult validate() {
118 final GroupValidationResult validationResult = new GroupValidationResult(this);
119 if (!ParameterValidationUtils.validateStringParameter(host)) {
120 validationResult.setResult("host", ValidationStatus.INVALID,
121 "must be a non-blank string containing hostname/ipaddress of the xacml pdp rest server");
123 if (!ParameterValidationUtils.validateStringParameter(userName)) {
124 validationResult.setResult("userName", ValidationStatus.INVALID,
125 "must be a non-blank string containing userName for xacml pdp rest server credentials");
127 if (!ParameterValidationUtils.validateStringParameter(password)) {
128 validationResult.setResult("password", ValidationStatus.INVALID,
129 "must be a non-blank string containing password for xacml pdp rest server credentials");
131 if (!ParameterValidationUtils.validateIntParameter(port)) {
132 validationResult.setResult("port", ValidationStatus.INVALID,
133 "must be a positive integer containing port of the xacml pdp rest server");
135 return validationResult;