diff options
author | 2020-08-10 19:55:26 +0000 | |
---|---|---|
committer | 2020-08-10 19:55:26 +0000 | |
commit | c147163fcfe5144830bae7d400c713aeb70704e1 (patch) | |
tree | 838088f5bc7d0cd9636b6022096da0e54befed75 /mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls | |
parent | b1729f6e2b9bd4f7aa00091339f820ade64d926f (diff) | |
parent | bc2e6287569ed6a848acf31b26097f54934baf9b (diff) |
Merge "Add factories for Ext tls parameters"
Diffstat (limited to 'mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls')
7 files changed, 387 insertions, 0 deletions
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactory.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactory.java new file mode 100644 index 0000000..546a809 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactory.java @@ -0,0 +1,74 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls; + +import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createInputValue; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.COMMON_NAME_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_COMMON_NAME; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_SANS; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.SANS_FIELD; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.onap.blueprintgenerator.models.blueprint.tls.api.ExternalCertificateDataFactory; +import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalCertificateParameters; + +/** + * Factory class for providing parameters of ExternalCertificate. Allow to get ExternalCertificateParameters Object and + * input list + */ +public class ExternalCertificateParametersFactory extends ExternalCertificateDataFactory { + + /** + * Create ExternalCertificateParameters Object + * + * @return ExternalCertificateParameters + */ + public ExternalCertificateParameters create() { + ExternalCertificateParameters externalCertificateParameters = new ExternalCertificateParameters(); + externalCertificateParameters.setCommonName(createPrefixedGetInput(COMMON_NAME_FIELD)); + externalCertificateParameters.setSans(createPrefixedGetInput(SANS_FIELD)); + return externalCertificateParameters; + } + + /** + * Create input list for ExternalCertificateParameters + * + * @return Input list + */ + public Map<String, LinkedHashMap<String, Object>> createInputList() { + Map<String, LinkedHashMap<String, Object>> retInputs = new LinkedHashMap<>(); + + LinkedHashMap<String, Object> commonNameInputMap = createInputValue("string", + "Common name which should be present in certificate.", + DEFAULT_COMMON_NAME); + retInputs.put(addPrefix(COMMON_NAME_FIELD), commonNameInputMap); + + LinkedHashMap<String, Object> sansInputMap = createInputValue("string", + "\"List of Subject Alternative Names (SANs) which should be present in certificate. " + + "Delimiter - : Should contain common_name value and other FQDNs under which given " + + "component is accessible.\"", + DEFAULT_SANS); + retInputs.put(addPrefix(SANS_FIELD), sansInputMap); + + return retInputs; + } + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalTlsInfoFactory.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalTlsInfoFactory.java new file mode 100644 index 0000000..e954afc --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalTlsInfoFactory.java @@ -0,0 +1,102 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls; + +import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createInputValue; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.CA_NAME_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.CERT_DIRECTORY_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.CERT_TYPE_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_CA; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_CERT_TYPE; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; +import org.onap.blueprintgenerator.models.blueprint.tls.api.ExternalCertificateDataFactory; +import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalTlsInfo; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +/** + * Factory class for providing ExternalTlsInfo data. Allow to get ExternalTlsInfo Object and Inputs list. + */ +public class ExternalTlsInfoFactory extends ExternalCertificateDataFactory { + + private ExternalCertificateParametersFactory externalCertificateParametersFactory; + + /** + * Constructor for ExternalTlsInfoFactory + * + * @param externalCertificateDataFactory Factory providing external certificate parameters. + */ + public ExternalTlsInfoFactory(ExternalCertificateParametersFactory externalCertificateDataFactory) { + this.externalCertificateParametersFactory = externalCertificateDataFactory; + } + + /** + * Create ExternalTlsInfo from ComponentSpec Object + * + * @param cs ComponentSpec Object + * @return ExternalTlsInfo Object + */ + public ExternalTlsInfo createFromComponentSpec(ComponentSpec cs) { + ExternalTlsInfo externalTlsInfoBp = new ExternalTlsInfo(); + TreeMap<String, Object> tlsInfoCs = cs.getAuxilary().getTls_info(); + + externalTlsInfoBp.setExternalCertDirectory((String) tlsInfoCs.get(CERT_DIRECTORY_FIELD)); + externalTlsInfoBp.setUseExternalTls(createPrefixedGetInput(USE_EXTERNAL_TLS_FIELD)); + externalTlsInfoBp.setCaName(createPrefixedGetInput(CA_NAME_FIELD)); + externalTlsInfoBp.setCertType(createPrefixedGetInput(CERT_TYPE_FIELD)); + externalTlsInfoBp.setExternalCertificateParameters(externalCertificateParametersFactory.create()); + + return externalTlsInfoBp; + } + + /** + * Create input list from ComponentSpec Object + * + * @param cs ComponentSpec Object + * @return Input list + */ + public Map<String, LinkedHashMap<String, Object>> createInputListFromComponentSpec(ComponentSpec cs) { + Map<String, LinkedHashMap<String, Object>> retInputs = new HashMap<>(); + + Map<String, Object> externalTlsInfoCs = cs.getAuxilary().getTls_info(); + LinkedHashMap<String, Object> useTlsFlagInput = createInputValue("boolean", + "Flag to indicate external tls enable/disable.", + externalTlsInfoCs.get(USE_EXTERNAL_TLS_FIELD)); + retInputs.put(addPrefix(USE_EXTERNAL_TLS_FIELD), useTlsFlagInput); + + LinkedHashMap<String, Object> caNameInputMap = createInputValue("string", + "Name of Certificate Authority configured on CertService side.", + DEFAULT_CA); + retInputs.put(addPrefix(CA_NAME_FIELD), caNameInputMap); + + LinkedHashMap<String, Object> certTypeInputMap = createInputValue("string", + "Format of provided certificates", + DEFAULT_CERT_TYPE); + retInputs.put(addPrefix(CERT_TYPE_FIELD), certTypeInputMap); + + retInputs.putAll(externalCertificateParametersFactory.createInputList()); + return retInputs; + } + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsConstants.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsConstants.java new file mode 100644 index 0000000..cdbfd32 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsConstants.java @@ -0,0 +1,38 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls; + +public class TlsConstants { + + public static final String EXTERNAL_CERT_DIRECTORY_FIELD = "external_cert_directory"; + public static final String CERT_DIRECTORY_FIELD = "cert_directory"; + public static final String INPUT_PREFIX = "external_cert_"; + public static final String USE_EXTERNAL_TLS_FIELD = "use_external_tls"; + public static final String CA_NAME_FIELD = "ca_name"; + public static final String EXTERNAL_CERTIFICATE_PARAMETERS_FIELD = "external_certificate_parameters"; + public static final String COMMON_NAME_FIELD = "common_name"; + public static final String SANS_FIELD = "sans"; + public static final String CERT_TYPE_FIELD = "cert_type"; + + public static final String DEFAULT_CA = "RA"; + public static final Object DEFAULT_CERT_TYPE = "P12"; + public static final String DEFAULT_COMMON_NAME = "sample.onap.org"; + public static final String DEFAULT_SANS = "sample.onap.org:component.sample.onap.org"; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsInfo.java new file mode 100644 index 0000000..027f996 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/TlsInfo.java @@ -0,0 +1,39 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ +package org.onap.blueprintgenerator.models.blueprint.tls; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.GetInput; + +@Getter +@Setter +@NoArgsConstructor +public class TlsInfo { + + @JsonProperty("cert_directory") + private String certDirectory; + + @JsonProperty("use_tls") + private GetInput useTls; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/api/ExternalCertificateDataFactory.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/api/ExternalCertificateDataFactory.java new file mode 100644 index 0000000..21b20e4 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/api/ExternalCertificateDataFactory.java @@ -0,0 +1,37 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls.api; + +import org.onap.blueprintgenerator.models.blueprint.GetInput; + + +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.INPUT_PREFIX; + +public abstract class ExternalCertificateDataFactory { + + protected static GetInput createPrefixedGetInput(String fieldName) { + return new GetInput(addPrefix(fieldName)); + } + + protected static String addPrefix(String fieldName) { + return INPUT_PREFIX + fieldName; + } + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalCertificateParameters.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalCertificateParameters.java new file mode 100644 index 0000000..e3ccca1 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalCertificateParameters.java @@ -0,0 +1,43 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls.impl; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.GetInput; + +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.COMMON_NAME_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.SANS_FIELD; + + +@Getter +@Setter +@NoArgsConstructor +public class ExternalCertificateParameters { + + @JsonProperty(COMMON_NAME_FIELD) + private GetInput commonName; + + @JsonProperty(SANS_FIELD) + private GetInput sans; + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalTlsInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalTlsInfo.java new file mode 100644 index 0000000..588dbb5 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/tls/impl/ExternalTlsInfo.java @@ -0,0 +1,54 @@ +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.blueprint.tls.impl; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.blueprintgenerator.models.blueprint.GetInput; + +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.CA_NAME_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.CERT_TYPE_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.EXTERNAL_CERTIFICATE_PARAMETERS_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.EXTERNAL_CERT_DIRECTORY_FIELD; +import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD; + +@Getter +@Setter +@NoArgsConstructor +public class ExternalTlsInfo { + + @JsonProperty(EXTERNAL_CERT_DIRECTORY_FIELD) + private String externalCertDirectory; + + @JsonProperty(USE_EXTERNAL_TLS_FIELD) + private GetInput useExternalTls; + + @JsonProperty(CA_NAME_FIELD) + private GetInput caName; + + @JsonProperty(CERT_TYPE_FIELD) + private GetInput certType; + + @JsonProperty(EXTERNAL_CERTIFICATE_PARAMETERS_FIELD) + private ExternalCertificateParameters externalCertificateParameters; + +} |