aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Varma <vv8305@att.com>2019-03-14 15:27:03 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-14 15:27:03 +0000
commita13646b2c8eb8a3dc545f88cd8539054987eae04 (patch)
treefdd69b1c94c2d8c4858cff9d15dce2b694af2c35
parent5bd2732d4a92e01cbcac28aaccecb69d5a4364dc (diff)
parent76ff43a909a4038a37a6a0b2f2a580291906b930 (diff)
Merge "Commit 3 for TM API definition"
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java80
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java117
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java76
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/Application.java104
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/ApplicationPropertiesFiles.java44
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/AuthProvider.java66
6 files changed, 487 insertions, 0 deletions
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java
new file mode 100644
index 0000000..1be9603
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.common;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class CMSRequestError implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CMSRequestError.class);
+ @JsonProperty
+ RequestError requestError;
+
+ public CMSRequestError(String messageId, String text, List<String> variables) {
+ requestError = new RequestError(messageId, text, variables);
+ }
+
+ public CMSRequestError(String messageId, String text) {
+ requestError = new RequestError(messageId, text, new ArrayList<String>());
+ }
+
+ public class RequestError {
+ @JsonProperty
+ private String messageId;
+ @JsonProperty
+ private String text;
+ @JsonProperty
+ private List<String> variables;
+
+ private RequestError(String messageId, String text, List<String> variables) {
+ this.messageId = "Scheduler." + messageId;
+ this.text = text;
+ this.variables = variables;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(messageId).append(":").append(text).append(":").append(variables);
+ return sb.toString();
+
+ }
+ }
+
+ public String toString() {
+ return requestError.toString();
+ }
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
new file mode 100644
index 0000000..8c1f2c6
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.common;
+
+import java.io.UnsupportedEncodingException;
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Component
+public class PropertiesManagement {
+
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+ private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
+
+ private final static String algorithm = "AES";
+ private final static String cipherMode = "CBC";
+ private final static String paddingScheme = "PKCS5Padding";
+ private final static String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme;
+
+ private static final String initVector = "ONAPCMSOVECTORIV"; // 16 bytes IV
+
+ @Autowired
+ Environment env;
+
+ public String getProperty(String key, String defaultValue) {
+ String value = env.getProperty(key, defaultValue);
+ value = getDecryptedValue(value);
+ return value;
+ }
+
+ public static String getDecryptedValue(String value) {
+ if (value.startsWith("enc:")) {
+ String secret = getSecret();
+ value = decrypt(secret, initVector, value.substring(4));
+ }
+ return value;
+ }
+
+ public static String getEncryptedValue(String value) {
+ String secret = getSecret();
+ value = encrypt(secret, initVector, value);
+ return value;
+ }
+
+ private static final String encrypt(String key, String initVector, String value) {
+ try {
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+ Cipher cipher = Cipher.getInstance(transformation);
+ cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
+ byte[] encrypted = cipher.doFinal(value.getBytes());
+ return Base64.encodeBase64String(encrypted);
+ } catch (Exception ex) {
+ errors.error("Unexpected exception {0}", ex.getMessage());
+ debug.debug("Unexpected exception", ex);
+ }
+
+ return null;
+ }
+
+ private static final String decrypt(String key, String initVector, String encrypted) {
+ try {
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+ Cipher cipher = Cipher.getInstance(transformation);
+ cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
+ byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
+ return new String(original);
+ } catch (Exception ex) {
+ errors.error("Unexpected exception {0}", ex.getMessage());
+ debug.debug("Unexpected exception", ex);
+ }
+ return null;
+ }
+
+ private static String getSecret() {
+ return "ONAPCMSOSECRETIV";
+ }
+
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java
new file mode 100644
index 0000000..68418d6
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.cmso.common.exceptions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.onap.observations.ObservationInterface;
+import org.onap.optf.cmso.common.CMSRequestError;
+
+import com.att.eelf.i18n.EELFResourceManager;
+
+public class CMSException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ protected CMSRequestError requestError = null;
+ private List<String> variables = new ArrayList<String>();
+ protected ObservationInterface messageCode;
+ protected Status status;
+
+ public CMSException(Status status, ObservationInterface messageCode, String... args) {
+ super(EELFResourceManager.format(messageCode, args));
+ this.status = status;
+ this.messageCode = messageCode;
+ for (String arg : args)
+ variables.add(arg);
+ requestError = new CMSRequestError(messageCode.name(), getMessage(), variables);
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public ObservationInterface getMessageCode() {
+ return messageCode;
+ }
+
+ public String[] getVariables() {
+ return variables.toArray(new String[variables.size()]);
+ }
+
+ public CMSRequestError getRequestError() {
+ return requestError;
+ }
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/Application.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/Application.java
new file mode 100644
index 0000000..eca406d
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/Application.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.ticketmgt;
+
+import java.net.InetAddress;
+import java.util.TimeZone;
+
+import javax.annotation.PostConstruct;
+
+import org.onap.optf.ticketmgt.common.LogMessages;
+import org.slf4j.MDC;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableAsync;
+
+import com.att.eelf.configuration.Configuration;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@SpringBootApplication
+@ComponentScan(basePackages = {"org.onap.optf.ticketmgt"})
+@EnableAsync
+
+@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
+public class Application extends SpringBootServletInitializer {
+
+ private static EELFLogger log = EELFManager.getInstance().getLogger(Application.class);
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(Application.class);
+ }
+
+ @PostConstruct
+ void started() {
+ // Make sure all datetimes are stored in UTC format.
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ public static void main(String[] args) {
+ initMDCData();
+ SpringApplication.run(Application.class, args);
+ }
+
+ protected static void initMDCData() {
+ MDC.clear();
+ try {
+ MDC.put(Configuration.MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put("hostname", InetAddress.getLocalHost().getCanonicalHostName());
+ MDC.put("serviceName", System.getProperty("info.build.artifact"));
+ MDC.put("version", System.getProperty("info.build.version"));
+ MDC.put(Configuration.MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ log.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ }
+
+ @Bean
+ public ServletWebServerFactory servletContainer() {
+ TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
+ return tomcat;
+ }
+
+
+
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/ApplicationPropertiesFiles.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/ApplicationPropertiesFiles.java
new file mode 100644
index 0000000..8cd70a6
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/ApplicationPropertiesFiles.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2018-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+package org.onap.optf.ticketmgt;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
+
+
+@Configuration
+@PropertySources({
+ @PropertySource("file:etc/config/ticketmgt.properties"),
+})
+public class ApplicationPropertiesFiles
+{
+} \ No newline at end of file
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/AuthProvider.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/AuthProvider.java
new file mode 100644
index 0000000..43ded66
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/AuthProvider.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+package org.onap.optf.ticketmgt;
+
+import java.util.ArrayList;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.env.Environment;
+import org.springframework.security.authentication.AuthenticationProvider;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+@Component
+@Profile(SpringProfiles.PROPRIETARY__AUTHENTICATION)
+
+public class AuthProvider
+ implements AuthenticationProvider {
+
+ @Autowired
+ Environment env;
+
+ @Override
+ public Authentication authenticate(Authentication authentication) {
+ String name = authentication.getName();
+ String password = authentication.getCredentials().toString();
+ //TODO check credentials until we enable AAF
+ return new UsernamePasswordAuthenticationToken(
+ name, password, new ArrayList<>());
+ }
+
+ @Override
+ public boolean supports(Class<?> authentication) {
+ return authentication.equals(
+ UsernamePasswordAuthenticationToken.class);
+ }
+}