diff options
author | Vikas Varma <vv8305@att.com> | 2019-03-14 15:26:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-14 15:26:52 +0000 |
commit | 5bd2732d4a92e01cbcac28aaccecb69d5a4364dc (patch) | |
tree | dd8b1c60c66d553cbbb2d5f80309632c18648e91 | |
parent | 123587e6ef68d15c7adaf53cfe89ea53738882c3 (diff) | |
parent | 4c81b00d2457e9d254959df78fa277301d7243f0 (diff) |
Merge "Commit 2 for TM API definition"
5 files changed, 436 insertions, 0 deletions
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; + } + } +} |