diff options
Diffstat (limited to 'cmso-ticketmgt/src/main/java/org/onap')
24 files changed, 2165 insertions, 0 deletions
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java b/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java new file mode 100644 index 0000000..cf49ccd --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java @@ -0,0 +1,223 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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.observations; + +import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP; +import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP; +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; +import static com.att.eelf.configuration.Configuration.MDC_PARTNER_NAME; +import static com.att.eelf.configuration.Configuration.MDC_REMOTE_HOST; +import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE; +import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC; +import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE; +import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY; +import static com.att.eelf.configuration.Configuration.MDC_TARGET_SERVICE_NAME; + +import java.net.URI; +import java.util.Date; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientResponseContext; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response.StatusType; + +import org.onap.observations.MessageHeaders.HeadersEnum; +import org.slf4j.MDC; + +import com.att.eelf.utils.Stopwatch; + +/** + * ECOMP EELF logging MDC fields not defined in the MDC Configuration (i.e. + * MDC_ALERT_SEVERITY) + **/ +public class Mdc { + public static final String SERVICE_NAME = "CSS-Scheduler"; + public enum Enum { + // BeginTimestamp, + // EndTimeStamp, + // RequestId, + // ServiceInstanceId, + VirtualServerName, + // ServiceName, + // PartnerName, + // StatusCOde, + // ResponseCode, + // ResponseDescription, + // InstanceUUID, + // AlertSeverity, + // ServerIPAddress, + // ElapsedTime, + // ServerFQDN, + // RemoteHost, + ClassName, Unused, + // ProcessKey, + CustomField1, CustomField2, CustomField3, CustomField4, + // TargetVirtualEntity, + // TargetEntity, + // TargetServiceName, + ErrorCode, ErrorDescription, Timer, + } + + public static String getCaller(int back) + { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + return stackTraceElements[back].getClassName() + "." + stackTraceElements[back].getMethodName(); + } + + public static void setCaller(int back) + { + String caller = MDC.get(Enum.ClassName.name()); + if (caller == null) + MDC.put(Enum.ClassName.name(), getCaller(back)); + } + + public static void setObservation(ObservationInterface o) + { + MDC.put(Enum.CustomField4.name(), o.name()); + } + + public static void clearCaller() + { + MDC.remove(Enum.ClassName.name()); + } + + public static Map<String, String> save() + { + Map<String, String> save = MDC.getCopyOfContextMap(); + return save; + } + + public static void restore(Map<String, String> mdcSave) + { + MDC.clear(); + for (String name : mdcSave.keySet()) + MDC.put(name, mdcSave.get(name)); + } + + + + public static void setRequestIdIfNotSet(String requestId) { + if (MDC.get(MDC_KEY_REQUEST_ID) == null || MDC.get(MDC_KEY_REQUEST_ID).equals("")) + { + setRequestId(requestId); + } + } + + public static void setRequestId(String requestId) { + MDC.put(MDC_KEY_REQUEST_ID, requestId); + } + + public static void metricStart(ClientRequestContext requestContext) { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + setPartnerTargetFromUri(requestContext.getUri()); + } + + public static void metricEnd(ClientResponseContext response) + { + + Date now = new Date(); + //MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + setResponseInfo(response.getStatusInfo()); + + } + public static void auditStart(ContainerRequestContext requestContext, HttpServletRequest servletRequest) + { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + MDC.put(MDC_REMOTE_HOST, servletRequest.getRemoteHost()); + MDC.put(Enum.ClassName.name(), getCaller(4)); + MultivaluedMap<String, String> headers = requestContext.getHeaders(); + String transactionId = (String) headers.getFirst(HeadersEnum.TransactionID.toString()); + if (transactionId != null) + { + setRequestId(transactionId); + } + else + { + setRequestId(UUID.randomUUID().toString()); + } + + } + + public static void auditEnd(ContainerRequestContext requestContext, ContainerResponseContext response) + { + Date now = new Date(); + //MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(Enum.ClassName.name(), getCaller(4)); + + setResponseInfo(response.getStatusInfo()); + + } + + private static void setResponseInfo(StatusType statusInfo) + { + Integer status = statusInfo.getStatusCode(); + String completed = "ERROR"; + if (status >=200 && status < 300) + { + completed = "COMPLETE"; + } + MDC.put(MDC_RESPONSE_CODE, status.toString()); + MDC.put(MDC_RESPONSE_DESC, statusInfo.getReasonPhrase()); + MDC.put(MDC_STATUS_CODE, completed); + } + + public static void setEvent(String requestID) { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + setRequestId(requestID); + } + + private static void setPartnerTargetFromUri(URI uri) + { + try + { + MDC.put(MDC_PARTNER_NAME, uri.getHost()); + MDC.put(MDC_TARGET_ENTITY, uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort()); + MDC.put(MDC_TARGET_SERVICE_NAME, uri.getPath()); + } + catch (Exception e) + { + MDC.put(MDC_PARTNER_NAME, "UNKNOWN"); + MDC.put(MDC_TARGET_ENTITY, "UNKNOWN"); + MDC.put(MDC_TARGET_SERVICE_NAME, "UNKNOWN"); + } + } + + +}
\ No newline at end of file diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java new file mode 100644 index 0000000..d8f80a2 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java @@ -0,0 +1,104 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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.observations; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class MessageHeaders { + public enum HeadersEnum { + UNDEFINED("UNDEFINED"), TransactionID("X-TransactionId"), FromAppID("X-FromAppId"), MinorVersion( + "X-MinorVersion"), PatchVersion("X-PatchVersion"), LatestVersion("X-LatestVersion"),; + + private final String text; + private final ArrayList<String> list; + + private HeadersEnum(String text) { + this.text = text; + this.list = new ArrayList<>(); + } + + @Override + public String toString() { + return text; + } + } + + public static final Map<String, String> supportedMajorVersions = new HashMap<String, String>(); + static { + supportedMajorVersions.put("v1", "0"); + supportedMajorVersions.put("v2", "0"); + } + public static final Set<String> supportedMajorMinorVersions = new HashSet<String>(); + static { + supportedMajorMinorVersions.add("v1.0"); + supportedMajorMinorVersions.add("v2.0"); + } + public static final String latestVersion = "2.0.0"; + public static final String patchVersion = "0"; + + public static HeadersEnum fromString(String text) { + for (HeadersEnum e : HeadersEnum.values()) + if (e.text.equals(text)) + return e; + return HeadersEnum.UNDEFINED; + } + + public static String getPatchVersion() { + return patchVersion; + } + + public static String getLatestVersion() { + return latestVersion; + } + + public static boolean validateMajorVersion(String major) { + String majorKey = major.toLowerCase(); + if (!supportedMajorVersions.containsKey(majorKey)) + return false; + return true; + } + + public static boolean validateMajorMinorVersion(String major, String minor) { + String majorKey = major.toLowerCase(); + if (!supportedMajorVersions.containsKey(majorKey)) + return false; + + if (minor != null) { + String majorMinorKey = majorKey + "." + minor; + return supportedMajorMinorVersions.contains(majorMinorKey); + } + return true; + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java b/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java new file mode 100644 index 0000000..0e1b1da --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java @@ -0,0 +1,125 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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.observations; + +import org.apache.log4j.Level; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class Observation +{ + private static EELFLogger log = EELFManager.getInstance().getLogger(Observation.class); + private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger(); + private static EELFLogger audit = EELFManager.getInstance().getAuditLogger(); + private static EELFLogger errors = EELFManager.getInstance().getErrorLogger(); + private static EELFLogger debug = EELFManager.getInstance().getDebugLogger(); + + //************************************************************************************************* + public static void report(ObservationInterface o, Exception e, String ...arguments) + { + Mdc.setCaller(4); + Mdc.setObservation(o); + if (o.getAudit()) + { + audit.info(o, e, arguments); + } + if (o.getMetric()) + { + metrics.info(o, e, arguments); + } + Level l = o.getLevel(); + switch (l.toInt()) + { + case Level.WARN_INT: + errors.warn(o, arguments); + debug.debug(o, e, arguments); + break; + case Level.INFO_INT: + log.info(o, e, arguments); + debug.debug(o, e, arguments); + break; + case Level.ERROR_INT: + errors.error(o, arguments); + debug.debug(o, e, arguments); + break; + case Level.TRACE_INT: + debug.trace(o, e, arguments); + break; + case Level.DEBUG_INT: + debug.debug(o, e, arguments); + break; + default: + log.info(o, e, arguments); + } + Mdc.clearCaller(); + } + + public static void report(ObservationInterface o, String ...arguments) + { + Mdc.setCaller(4); + Mdc.setObservation(o); + if (o.getAudit()) + { + audit.info(o, arguments); + } + if (o.getMetric()) + { + metrics.info(o, arguments); + } + Level l = o.getLevel(); + switch (l.toInt()) + { + case Level.WARN_INT: + errors.warn(o, arguments); + debug.debug(o, arguments); + break; + case Level.INFO_INT: + log.info(o, arguments); + debug.debug(o, arguments); + break; + case Level.ERROR_INT: + errors.error(o, arguments); + debug.debug(o, arguments); + break; + case Level.TRACE_INT: + debug.debug(o, arguments); + break; + case Level.DEBUG_INT: + debug.debug(o, arguments); + break; + default: + log.info(o, arguments); + } + Mdc.clearCaller(); + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java new file mode 100644 index 0000000..16305bc --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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.observations; + +import javax.ws.rs.core.Response.Status; + +import org.apache.log4j.Level; + +import com.att.eelf.i18n.EELFResolvableErrorEnum; + +public interface ObservationInterface extends EELFResolvableErrorEnum +{ + public Enum<?> getValue(); + public Level getLevel(); + public String getMessage(); + public Status getStatus(); + public String getDomain(); + public String name(); + public Boolean getAudit(); + public Boolean getMetric(); +}
\ No newline at end of file diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java new file mode 100644 index 0000000..639db76 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java @@ -0,0 +1,109 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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.observations; + +import javax.ws.rs.core.Response.Status; + +import org.apache.log4j.Level; + +import com.att.eelf.i18n.EELFResolvableErrorEnum; +import com.att.eelf.i18n.EELFResourceManager; + + +public class ObservationObject implements ObservationInterface +{ + + //************************************************************************************************* + // Interface class that matches the ObservationInteface pattern + // This will be used in case we decide to provide external overrides and we need to instantiate + // For now, we'll just use the Enum itself. + // + // + private Enum<?> value = null; + private Level level = null;; + private String message = null; + private Status status = null; + private String domain = null; + private Boolean metric = false; + private Boolean audit = false; + public ObservationObject(ObservationInterface o) + { + this.value = o.getValue(); + this.level = o.getLevel(); + this.message = o.getMessage(); + this.status = o.getStatus(); + this.domain = o.getDomain(); + this.metric = o.getMetric(); + this.audit = o.getAudit(); + + } + public Enum<?> getValue() {return value;} + @Override + public String getMessage() {return message;} + @Override + public Status getStatus() {return status;} + @Override + public String getDomain() {return domain;} + + @Override + public Level getLevel() { + return level; + } + @Override + public String name() { + return value.name(); + } + @Override + public Boolean getAudit() { + return audit; + } + @Override + public Boolean getMetric() { + return metric; + } + + public String getMessage(String ...arguments) { + return EELFResourceManager.format((EELFResolvableErrorEnum)value, arguments); + } + public void setValue(Enum<?> value) { + this.value = value; + } + public void setLevel(Level level) { + this.level = level; + } + public void setMessage(String message) { + this.message = message; + } + public void setStatus(Status status) { + this.status = status; + } + + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java new file mode 100644 index 0000000..b238561 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java @@ -0,0 +1,59 @@ +/* + * 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; + +import java.util.HashMap; +import java.util.Map; +import org.onap.optf.cmso.common.PropertiesManagement; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; + +public class CMSEnvironmentPostProcessor implements EnvironmentPostProcessor { + // TODO tested in ONAP springboot and this is called before all of the properties files have been loaded... + // perhaps there is a post post processor? Until this works. DB password will be in the clear in the proeprties files. + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + String pwd = environment.getProperty("cmso.database.password"); + if (pwd != null) { + pwd = PropertiesManagement.getDecryptedValue(pwd); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("spring.datasource.password", pwd); + MapPropertySource propertySource = new MapPropertySource("abc", map); + MutablePropertySources proeprtySources = environment.getPropertySources(); + proeprtySources.addLast(propertySource); + } + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java new file mode 100644 index 0000000..b6a59e3 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java @@ -0,0 +1,95 @@ +/* + * 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.IOException; +import java.io.UnsupportedEncodingException; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.core.MultivaluedMap; +import javax.xml.bind.DatatypeConverter; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class BasicAuthenticatorFilter implements ClientRequestFilter { + private static EELFLogger log = EELFManager.getInstance().getLogger(BasicAuthenticatorFilter.class); + private final String user; + private final String password; + + public BasicAuthenticatorFilter(String user, String password) { + this.user = user; + this.password = password; + log.info("user: " + user + " pass:" + password); + } + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + MultivaluedMap<String, Object> headers = requestContext.getHeaders(); + final String basicAuthentication = getBasicAuthentication(); + headers.add("Authorization", basicAuthentication); + } + + private String getBasicAuthentication() { + String token = this.user + ":" + this.password; + try { + return "Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8")); + } catch (UnsupportedEncodingException ex) { + throw new IllegalStateException("Cannot encode with UTF-8", ex); + } + } + + public static String getUser(HttpServletRequest request) { + String user = ""; + String header = request.getHeader("Authorization"); + if (header != null) { + String[] auth = header.split("Basic "); + if (auth.length == 2) { + String token = getToken(auth[1]); + if (token.contains(":")) { + String[] tokens = token.split(":"); + user = tokens[0]; + } + } + } + return user; + } + + private static String getToken(String auth) { + try { + String token = new String(DatatypeConverter.parseBase64Binary(auth)); + return token; + } catch (Exception e) { + return auth; + } + } +} 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); + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java new file mode 100644 index 0000000..f5c6345 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java @@ -0,0 +1,60 @@ +/* + * 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.ticketmgt; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.optf.cmso.common.PropertiesManagement; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; + +public class CMSEnvironmentPostProcessor implements EnvironmentPostProcessor { + // TODO tested in ONAP springboot and this is called before all of the properties files have been loaded... + // perhaps there is a post post processor? Until this works. DB password will be in the clear in the proeprties files. + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + String pwd = environment.getProperty("cmso.database.password"); + if (pwd != null) { + pwd = PropertiesManagement.getDecryptedValue(pwd); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("spring.datasource.password", pwd); + MapPropertySource propertySource = new MapPropertySource("abc", map); + MutablePropertySources proeprtySources = environment.getPropertySources(); + proeprtySources.addLast(propertySource); + } + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java new file mode 100644 index 0000000..3bc0153 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java @@ -0,0 +1,103 @@ +/* + * 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.util.logging.Logger; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; + +import org.glassfish.jersey.client.ClientConfig; +import org.glassfish.jersey.logging.LoggingFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; +import org.onap.optf.ticketmgt.filters.CMSOContainerFilters; +import org.onap.optf.ticketmgt.service.rs.AdminToolImpl; +import org.onap.optf.ticketmgt.service.rs.AvailabilityInterfaceImpl; +import org.onap.optf.ticketmgt.service.rs.HealthCheckImpl; +import org.onap.optf.ticketmgt.service.rs.TicketManagementImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +@Component +@ApplicationPath("/") +public class JerseyConfiguration extends ResourceConfig { + private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); + + @Bean + @Primary + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); + objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); + return objectMapper; + } + + @Autowired + public JerseyConfiguration( /* LogRequestFilter lrf */ ) { + register(HealthCheckImpl.class); + register(AdminToolImpl.class); + register(TicketManagementImpl.class); + register(AvailabilityInterfaceImpl.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + // TODO: ONAP Conversion identify appropriate ONAP logging filters if any + // register(lrf, 6001); + // register(LogResponseFilter.class, 6004); + + // TODO: Examine which logging features to enable + register(new LoggingFeature(log)); + register(CMSOContainerFilters.class); + } + + @Bean + public Client jerseyClient() { + ClientConfig client = new ClientConfig(); + + // TODO: ONAP Conversion identify appropriate ONAP logging filters if any + // client.register(TransactionIdRequestFilter.class); + // client.register(TransactionIdResponseFilter.class); + // client.register(DateTimeParamConverterProvider.class); + + return ClientBuilder.newClient(client); + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SecurityConfig.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SecurityConfig.java new file mode 100644 index 0000000..27f9019 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SecurityConfig.java @@ -0,0 +1,63 @@ +/* + * Copyright © 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.ticketmgt; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@EnableWebSecurity +@ComponentScan("org.onap.optf") +@Profile(SpringProfiles.PROPRIETARY__AUTHENTICATION) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private AuthProvider authProvider; + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth.authenticationProvider(authProvider); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic(); + + } +}
\ No newline at end of file diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SpringProfiles.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SpringProfiles.java new file mode 100644 index 0000000..2cb2c99 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/SpringProfiles.java @@ -0,0 +1,29 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.optf.cmso + * ================================================================================ + * Copyright © 2019 AT&T 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.optf.ticketmgt; + +public class SpringProfiles +{ + + public static final String AAF_AUTHENTICATION = "aaf-auth"; + public static final String PROPRIETARY__AUTHENTICATION = "proprietary-auth"; + + private SpringProfiles(){} +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java new file mode 100644 index 0000000..53a8d52 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.optf.cmso + * ================================================================================ + * Copyright © 2019 AT&T 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.optf.ticketmgt.aaf; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.observations.Observation; +import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.ticketmgt.SpringProfiles; +import org.onap.optf.ticketmgt.common.LogMessages; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +/** + * AAF authorization filter + */ + +@Component +@Profile(SpringProfiles.AAF_AUTHENTICATION) +@PropertySource("file:${server.local.startpath}/aaf/permissions.properties") +public class AafAuthorizationFilter extends OrderedRequestContextFilter { + + @Value("${permission.type}") + String type; + + @Value("${permission.instance}") + String instance; + + public AafAuthorizationFilter() { + this.setOrder(FilterPriority.AAF_AUTHORIZATION.getPriority()); + + + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { + String permission = String.format("%s|%s|%s", type, instance, request.getMethod().toLowerCase()); + if(request.getRequestURI().matches("^.*/util/echo$")){ + filterChain.doFilter(request, response); + } + if(!request.isUserInRole(permission)){ + Observation.report(LogMessages.UNAUTHORIZED); + ResponseFormatter.errorResponse(request, response, + new CMSException(LogMessages.UNAUTHORIZED.getStatus(), + LogMessages.UNAUTHORIZED, "")); + }else{ + filterChain.doFilter(request,response); + } + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java new file mode 100644 index 0000000..89d6e3b --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.optf.cmso + * ================================================================================ + * Copyright © 2019 AT&T 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.optf.ticketmgt.aaf; + + +import java.io.IOException; +import java.util.Properties; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.filter.CadiFilter; +import org.onap.observations.Observation; +import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.ticketmgt.Application; +import org.onap.optf.ticketmgt.SpringProfiles; +import org.onap.optf.ticketmgt.common.LogMessages; +import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +/** + * AAF authentication filter + */ + +@Component +@Profile(SpringProfiles.AAF_AUTHENTICATION) +public class AafFilter extends OrderedRequestContextFilter { + + private final CadiFilter cadiFilter; + + public AafFilter() throws IOException, ServletException { + Properties cadiProperties = new Properties(); + cadiProperties.load(Application.class.getClassLoader().getResourceAsStream("cadi.properties")); + cadiFilter = new CadiFilter(new PropAccess(cadiProperties)); + this.setOrder(FilterPriority.AAF_AUTHENTICATION.getPriority()); + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { + if(!request.getRequestURI().matches("^.*/util/echo$")){ + cadiFilter.doFilter(request, response, filterChain); + if(response.getStatus() >=400 && response.getStatus() < 500){ + Observation.report(LogMessages.UNAUTHENTICATED); + ResponseFormatter.errorResponse(request, response, + new CMSException(LogMessages.UNAUTHENTICATED.getStatus(), + LogMessages.UNAUTHENTICATED, "")); + } + } else { + filterChain.doFilter(request, response); + } + } + + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/FilterPriority.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/FilterPriority.java new file mode 100644 index 0000000..0a74a97 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/FilterPriority.java @@ -0,0 +1,35 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.optf.cmso + * ================================================================================ + * Copyright © 2019 AT&T 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.optf.ticketmgt.aaf; + +import org.springframework.core.Ordered; + +public enum FilterPriority { + AAF_AUTHENTICATION(Ordered.HIGHEST_PRECEDENCE), + AAF_AUTHORIZATION(Ordered.HIGHEST_PRECEDENCE + 1); //higher number = lower priority + + private final int priority; + + FilterPriority(final int p) { + priority = p; + } + + public int getPriority() { return priority; } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java new file mode 100644 index 0000000..626776c --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java @@ -0,0 +1,42 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.optf.cmso + * ================================================================================ + * Copyright © 2019 AT&T 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.optf.ticketmgt.aaf; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.MediaType; + +import org.onap.optf.cmso.common.exceptions.CMSException; + +class ResponseFormatter { + + private static final String ACCEPT_HEADER = "accept"; + + static void errorResponse(HttpServletRequest request, HttpServletResponse response, CMSException error) throws IOException { + String accept = request.getHeader(ACCEPT_HEADER) == null ? MediaType.APPLICATION_JSON : request.getHeader(ACCEPT_HEADER); + response.setStatus(error.getStatus().getStatusCode()); + response.getWriter().write(error.getRequestError().toString()); + response.getWriter().flush(); + response.getWriter().close(); + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java new file mode 100644 index 0000000..1931296 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java @@ -0,0 +1,138 @@ +/* + * 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.service.rs; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.onap.optf.cmso.common.CMSRequestError; +import org.onap.optf.ticketmgt.service.rs.models.TicketData; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +@Api("Ticket Management") +@Path("/{apiVersion}") +@Produces({MediaType.APPLICATION_JSON}) +public interface TicketManagement { + // ****************************************************************** + @GET + @Path("/ticket/{id}") + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Fetch Ticket", notes = "Returns ticket information for the provided ticket id.", + response = TicketData.class) + @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), + @ApiResponse(code = 404, message = "No record found", response = CMSRequestError.class), + @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) + public Response fetchTicket( + @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, + @ApiParam(value = "Unique ticket identifier") @PathParam("id") String id); + + // ****************************************************************** + @POST + @Path("/ticket/") + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Create Ticket", notes = "Creates a ticket for the passed data") + @ApiResponses( + value = {@ApiResponse(code = 200, message = "Ticket Created. Ticket Id returned.", response=TicketData.class), + @ApiResponse(code = 400, message = "Bad request.", response = CMSRequestError.class), + @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) + public Response createTicket( + @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, + @ApiParam(value = "Data for creating a ticket") TicketData ticketData); + + // ****************************************************************** + @PUT + @Path("/ticket/") + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Update Ticket", notes = "Updates a ticket to the passed data") + @ApiResponses( + value = {@ApiResponse(code = 204, message = "Ticket Updated."), + @ApiResponse(code = 400, message = "Bad request.", response = CMSRequestError.class), + @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) + public Response updateTicket( + @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, + @ApiParam(value = "Data for updating a ticket") TicketData ticketData); + + // ****************************************************************** + @DELETE + @Path("/ticket/{id}") + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Cancel the ticket", notes = "Cancels the ticket.") + @ApiResponses(value = {@ApiResponse(code = 204, message = "Delete successful"), + @ApiResponse(code = 404, message = "No record found", response = CMSRequestError.class), + @ApiResponse(code = 400, message = "Bad request", response = CMSRequestError.class), + @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) + public Response deleteScheduleRequest( + @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, + @ApiParam(value = "Ticket id to uniquely identify the ticket being deleted.") @PathParam("id") String id); + + + + // ****************************************************************** + @GET + @Path("/tickets") + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Search Tickets", notes = "Returns a list of based upon the filter criteria.", + response = TicketData.class, responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), + @ApiResponse(code = 400, message = "Bad request", response = CMSRequestError.class), + @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) + public Response searchTcikets( + @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, + @ApiParam(value = "Ticket identifier", + allowMultiple = true) @QueryParam("id") String id, + @ApiParam(value = "Element Id", + allowMultiple = true) @QueryParam("elementId") String elementId, + @ApiParam(value = "Start time <low>,<high>", + allowMultiple = true) @QueryParam("startTime") String startTime, + @ApiParam(value = "Finish time <low>,<high>", + allowMultiple = true) @QueryParam("finishTime") String finishTime, + @ApiParam(value = "Maximum number of tickets to return") @QueryParam("maxTickets") Integer maxTickets, + @ApiParam(value = "Return tickets > last id") @QueryParam("lastId") String lastId); + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagementImpl.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagementImpl.java new file mode 100644 index 0000000..4346f0b --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagementImpl.java @@ -0,0 +1,180 @@ +/* + * 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.service.rs; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.onap.observations.Observation; +import org.onap.optf.ticketmgt.common.LogMessages; +import org.onap.optf.ticketmgt.service.rs.models.TicketData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@Controller +public class TicketManagementImpl implements TicketManagement { + private static EELFLogger debug = EELFManager.getInstance().getDebugLogger(); + + @Autowired + Environment env; + + @Context + UriInfo uri; + + @Context + HttpServletRequest request; + + @Override + public Response fetchTicket(String apiVersion, String id) { + // TODO Auto-generated method stub + Observation.report(LogMessages.FETCH_TICKET, "Received", request.getRemoteAddr(), id, ""); + Response response = null; + try + { + TicketData td = new TicketData(); + td.setId(id); + response = Response.ok(td).build(); +// } catch (CMSException e) { +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage()); +// response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + response = Response.serverError().build(); + } + Observation.report(LogMessages.FETCH_TICKET, "Returned", request.getRemoteAddr(), id, response.getStatusInfo().toString()); + return response; + } + + @Override + public Response createTicket(String apiVersion, TicketData ticketData) { + // TODO Auto-generated method stub + String id = UUID.randomUUID().toString(); + Observation.report(LogMessages.CREATE_TICKET, "Received", request.getRemoteAddr(), id, ""); + Response response = null; + try + { + ticketData.setId(id); + response = Response.ok(ticketData).build(); +// } catch (CMSException e) { +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage()); +// response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + response = Response.serverError().build(); + } + Observation.report(LogMessages.CREATE_TICKET, "Returned", request.getRemoteAddr(), id, response.getStatusInfo().toString()); + return response; + } + + @Override + public Response updateTicket(String apiVersion, TicketData ticketData) { + // TODO Auto-generated method stub + String id = ticketData.getId(); + Observation.report(LogMessages.UPDATE_TICKET, "Received", request.getRemoteAddr(), id, ""); + Response response = null; + try + { + response = Response.noContent().build(); +// } catch (CMSException e) { +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage()); +// response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + response = Response.serverError().build(); + } + Observation.report(LogMessages.UPDATE_TICKET, "Returned", request.getRemoteAddr(), id, response.getStatusInfo().toString()); + return response; + } + + + @Override + public Response searchTcikets(String apiVersion, String id, String elementId, String startTime, String finishTime, + Integer maxTickets, String lastId) { + // TODO Auto-generated method stub + // TODO Auto-generated method stub + Observation.report(LogMessages.SEARCH_TICKETS, "Received", request.getRemoteAddr(), uri.getPath(), ""); + Response response = null; + List<TicketData> list = new ArrayList<>(); + try + { + response = Response.ok(list).build(); +// } catch (CMSException e) { +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage()); +// response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + response = Response.serverError().build(); + } + Observation.report(LogMessages.SEARCH_TICKETS, "Returned", request.getRemoteAddr(), uri.getPath(), response.getStatusInfo().toString()); + return response; + } + + @Override + public Response deleteScheduleRequest(String apiVersion, String id) { + Observation.report(LogMessages.CANCEL_TICKET, "Received", request.getRemoteAddr(), id, ""); + Response response = null; + try + { + response = Response.noContent().build(); +// } catch (CMSException e) { +// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); +// Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage()); +// response = Response.status(e.getStatus()).entity(e.getRequestError()).build(); + } catch (Exception e) { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + response = Response.serverError().build(); + } + Observation.report(LogMessages.CANCEL_TICKET, "Returned", request.getRemoteAddr(), id, response.getStatusInfo().toString()); + return response; + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/models/ActiveTicketsRequest.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/models/ActiveTicketsRequest.java new file mode 100644 index 0000000..9c979de --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/models/ActiveTicketsRequest.java @@ -0,0 +1,115 @@ +/* + * 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.service.rs.models; + +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.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "Ticket Management Request", description = "Request to retrieve active tickets for the provided elements.") +public class ActiveTicketsRequest implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(ActiveTicketsRequest.class); + + @ApiModelProperty(value = "Unique Id of the request") + private String requestId; + + @ApiModelProperty( + value = "Implementation specific name value pairs provided to be passed to Ticket Management query .") + private List<NameValue> commonData; + + @ApiModelProperty( + value = "Lists of desired change windows for which TicketData will be returned.") + private List<ChangeWindow> changeWindows = new ArrayList<>(); + + @ApiModelProperty(value = "List of the elements for which TicketData will be returned.") + private List<ElementCriteria> elements = new ArrayList<>(); + + public String getRequestId() { + return requestId; + } + + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + + public List<NameValue> getCommonData() { + return commonData; + } + + + public void setCommonData(List<NameValue> commonData) { + this.commonData = commonData; + } + + + public List<ChangeWindow> getChangeWindows() { + return changeWindows; + } + + + public void setChangeWindows(List<ChangeWindow> changeWindows) { + this.changeWindows = changeWindows; + } + + + public List<ElementCriteria> getElements() { + return elements; + } + + + public void setElements(List<ElementCriteria> elements) { + this.elements = elements; + } + + + public String toString() { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.writeValueAsString(this); + } catch (JsonProcessingException e) { + log.debug("Error in toString()", e); + } + return ""; + } + +} |