2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Bell Canada.
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.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.cds.properties;
21 import java.nio.charset.StandardCharsets;
22 import java.util.Base64;
25 import lombok.ToString;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ParameterRuntimeException;
29 import org.onap.policy.common.parameters.annotations.Max;
30 import org.onap.policy.common.parameters.annotations.Min;
31 import org.onap.policy.common.parameters.annotations.NotNull;
36 public class CdsServerProperties implements ParameterGroup {
38 // Port range constants
39 private static final int MIN_USER_PORT = 1024;
40 private static final int MAX_USER_PORT = 65535;
42 private static final String SERVER_PROPERTIES_TYPE = "CDS gRPC Server Properties";
44 // CDS carrier properties
48 @Min(value = MIN_USER_PORT)
49 @Max(value = MAX_USER_PORT)
56 private String username;
59 private String password;
63 public String getName() {
64 return SERVER_PROPERTIES_TYPE;
68 public void setName(final String name) {
69 throw new ParameterRuntimeException("The name of this ParameterGroup implementation is always " + getName());
73 public GroupValidationResult validate() {
74 return new GroupValidationResult(this);
78 * Generate base64-encoded Authorization header from username and password.
80 * @return Base64 encoded string
82 public String getBasicAuth() {
83 return Base64.getEncoder().encodeToString(String.format("%s:%s", getUsername(), getPassword())
84 .getBytes(StandardCharsets.UTF_8));