diff options
author | LaMont, William(wl2432) <wl2432@att.com> | 2020-04-14 14:00:00 -0400 |
---|---|---|
committer | LaMont, William(wl2432) <wl2432@att.com> | 2020-04-15 15:36:42 -0400 |
commit | 86e7411b128bd7db440eceff7265533844e577bb (patch) | |
tree | 82d33b012b11c44e6edcfce8df0b45724ff6ec3e /aai-schema-service/src/main/java | |
parent | 8e131584d755d07bb12a99fa0d5981d84ed5592a (diff) |
schema-service processing for v19
Issue-ID: AAI-2864
Change-Id: I41a430ec9c9fd69be75bd9d01693249895e0928b
Signed-off-by: LaMont, William(wl2432) <wl2432@att.com>
Diffstat (limited to 'aai-schema-service/src/main/java')
15 files changed, 195 insertions, 482 deletions
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java index f2e0bd1..4e5bea5 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java @@ -19,11 +19,9 @@ */ package org.onap.aai.schemaservice; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.LoggingContext.StatusCode; import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +31,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; +import org.onap.aai.aailog.logs.AaiDebugLog; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -50,12 +50,19 @@ import java.util.UUID; DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) +@ComponentScan(basePackages = { + "org.onap.aai.schemaservice", + "org.onap.aai.aaf" +}) public class SchemaServiceApp { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceApp.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(SchemaServiceApp.class.getName()); private static final String APP_NAME = "aai-schema-service"; - private static Map<String, String> contextMap; + private static AaiDebugLog debugLog = new AaiDebugLog(); + static { + debugLog.setupMDC(); + } @Autowired private Environment env; @@ -64,14 +71,6 @@ public class SchemaServiceApp { setDefaultProps(); - LoggingContext.save(); - LoggingContext.component("init"); - LoggingContext.partnerName("NA"); - LoggingContext.targetEntity(APP_NAME); - LoggingContext.requestId(UUID.randomUUID().toString()); - LoggingContext.serviceName(APP_NAME); - LoggingContext.targetServiceName("contextInitialized"); - LoggingContext.statusCode(StatusCode.COMPLETE); SpringApplication app = new SpringApplication(SchemaServiceApp.class); @@ -79,19 +78,17 @@ public class SchemaServiceApp { app.setRegisterShutdownHook(true); app.addInitializers(new PropertyPasswordConfiguration()); Environment env = app.run(args).getEnvironment(); - MDC.setContextMap(contextMap); - logger.info( + logger.debug( "Application '{}' is running on {}!", env.getProperty("spring.application.name"), env.getProperty("server.port") ); - logger.info("SchemaService MicroService Started"); + logger.debug("SchemaService MicroService Started"); System.out.println("SchemaService Microservice Started"); - LoggingContext.restoreIfPossible(); } public static void setDefaultProps() { @@ -122,17 +119,7 @@ public class SchemaServiceApp { System.setProperty("org.onap.aai.serverStarted", "false"); setDefaultProps(); - LoggingContext.save(); - LoggingContext.component("init"); - LoggingContext.partnerName("NA"); - LoggingContext.targetEntity(APP_NAME); - LoggingContext.requestId(UUID.randomUUID().toString()); - LoggingContext.serviceName(APP_NAME); - LoggingContext.targetServiceName("contextInitialized"); - LoggingContext.statusCode(StatusCode.COMPLETE); - - contextMap = MDC.getCopyOfContextMap(); - logger.info("SchemaService initialization started..."); + logger.debug("SchemaService initialization started..."); // Setting this property to allow for encoded slash (/) in the path parameter // This is only needed for tomcat keeping this as temporary @@ -143,20 +130,11 @@ public class SchemaServiceApp { logger.warn("You have seriously misconfigured your application"); } - LoggingContext.restoreIfPossible(); } @PreDestroy public void cleanup() { - LoggingContext.save(); - LoggingContext.component("Stopped"); - LoggingContext.partnerName("NA"); - LoggingContext.targetEntity(APP_NAME); - LoggingContext.requestId(UUID.randomUUID().toString()); - LoggingContext.serviceName(APP_NAME); - LoggingContext.targetServiceName("Stopped"); - LoggingContext.statusCode(StatusCode.COMPLETE); - logger.info("SchemaService shutting down"); + logger.debug("SchemaService shutting down"); } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java index 76dd084..8069520 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java @@ -19,7 +19,7 @@ */ package org.onap.aai.schemaservice.config; -import org.onap.aai.auth.AAIAuthCore; +import org.onap.aai.aaf.auth.AAIAuthCore; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java index cb5416f..6e29d4a 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.config; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.onap.aai.exceptions.AAIException; import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.logging.ErrorObject; @@ -49,7 +49,7 @@ import java.util.List; @Component public class ErrorHandler extends OncePerRequestFilter { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ErrorHandler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ErrorHandler.class); private String basePath; public ErrorHandler(@Value("${schema.uri.base.path}") String basePath) { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java index 49cd1ed..db67ac6 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java @@ -26,28 +26,114 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.commons.io.IOUtils; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.*; + public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> { private static final Pattern decodePasswordPattern = Pattern.compile("password\\((.*?)\\)"); - private PasswordDecoder passwordDecoder = new JettyPasswordDecoder(); + private static final Logger logger = LoggerFactory.getLogger(PropertyPasswordConfiguration.class.getName()); @Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); + String certPath = environment.getProperty("server.certs.location"); + File passwordFile = null; + File passphrasesFile = null; + InputStream passwordStream = null; + InputStream passphrasesStream = null; + Map<String, Object> sslProps = new LinkedHashMap<>(); + + // Override the passwords from application.properties if we find AAF certman files + if (certPath != null) { + try { + passwordFile = new File(certPath + ".password"); + passwordStream = new FileInputStream(passwordFile); + + if (passwordStream != null) { + String keystorePassword = null; + + keystorePassword = IOUtils.toString(passwordStream); + if (keystorePassword != null) { + keystorePassword = keystorePassword.trim(); + sslProps.put("server.ssl.key-store-password", keystorePassword); + } + else{ + logger.warn("Keystore password is null in AAF Certman password file"); + } + } else { + logger.info("Not using AAF Certman password file"); + } + } catch (IOException e) { + logger.warn("Not using AAF Certman password file " + passwordFile.getName() + " e=" + e.getMessage()); + } finally { + if (passwordStream != null) { + try { + passwordStream.close(); + } catch (Exception e) { + } + } + } + try { + passphrasesFile = new File(certPath + ".passphrases"); + passphrasesStream = new FileInputStream(passphrasesFile); + + if (passphrasesStream != null) { + String truststorePassword = null; + Properties passphrasesProps = new Properties(); + passphrasesProps.load(passphrasesStream); + truststorePassword = passphrasesProps.getProperty("cadi_truststore_password"); + if (truststorePassword != null) { + truststorePassword = truststorePassword.trim(); + sslProps.put("server.ssl.trust-store-password", truststorePassword); + } + else { + logger.warn("Truststore password is null in AAF Certman passphrases file"); + } + } else { + logger.info("Not using AAF Certman passphrases file"); + } + } catch (IOException e) { + logger.warn("Not using AAF Certman passphrases file " + passphrasesFile.getName() + " e=" + e.getMessage()); + } finally { + if (passphrasesStream != null) { + try { + passphrasesStream.close(); + } catch (Exception e) { + } + } + } + } for (PropertySource<?> propertySource : environment.getPropertySources()) { Map<String, Object> propertyOverrides = new LinkedHashMap<>(); decodePasswords(propertySource, propertyOverrides); if (!propertyOverrides.isEmpty()) { - PropertySource<?> decodedProperties = new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); + PropertySource<?> decodedProperties = new MapPropertySource("decoded "+ propertySource.getName(), propertyOverrides); environment.getPropertySources().addBefore(propertySource.getName(), decodedProperties); } + } + if (!sslProps.isEmpty()) { + logger.info("Using AAF Certman files"); + PropertySource<?> additionalProperties = new MapPropertySource("additionalProperties", sslProps); + environment.getPropertySources().addFirst(additionalProperties); + } + } private void decodePasswords(PropertySource<?> source, Map<String, Object> propertyOverrides) { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java index ca953fd..a4eba45 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.edges; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -45,7 +45,7 @@ import java.util.stream.Stream; @Service public class EdgeService { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(EdgeService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(EdgeService.class); private static final String FILESEP = System.getProperty("file.separator"); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResetLoggingContext.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResetLoggingContext.java deleted file mode 100644 index 420ee78..0000000 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResetLoggingContext.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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.aai.schemaservice.interceptors.post; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.LoggingContext.StatusCode; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.annotation.Priority; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.container.ContainerResponseFilter; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.Response.StatusType; -import java.io.IOException; - -@Priority(AAIResponseFilterPriority.RESET_LOGGING_CONTEXT) -public class ResetLoggingContext extends AAIContainerFilter implements ContainerResponseFilter { - - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ResetLoggingContext.class); - - @Autowired - private HttpServletRequest httpServletRequest; - - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) - throws IOException { - - this.cleanLoggingContext(responseContext); - - } - - private void cleanLoggingContext(ContainerResponseContext responseContext) { - //String url = httpServletRequest.getRequestURL().toString(); - boolean success = true; - String uri = httpServletRequest.getRequestURI(); - String queryString = httpServletRequest.getQueryString(); - - if (queryString != null && !queryString.isEmpty()) { - uri = uri + "?" + queryString; - } - // For now, we use the the HTTP status code, - // This may change, once the requirements for response codes are defined - - int httpStatusCode = responseContext.getStatus(); - if (httpStatusCode < 100 || httpStatusCode > 599) { - httpStatusCode = Status.INTERNAL_SERVER_ERROR.getStatusCode(); - } - LoggingContext.responseCode(Integer.toString(httpStatusCode)); - - StatusType sType = responseContext.getStatusInfo(); - if (sType != null) { - Status.Family sFamily = sType.getFamily(); - if (!(Status.Family.SUCCESSFUL.equals(sFamily) || - (Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode))))) { - success = false; - } - } else { - if ((httpStatusCode < 200 || httpStatusCode > 299) && (!(Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode))))) { - success = false; - } - } - if (success) { - LoggingContext.statusCode(StatusCode.COMPLETE); - LOGGER.info(uri + " call succeeded"); - } else { - LoggingContext.statusCode(StatusCode.ERROR); - LOGGER.error(uri + " call failed with responseCode=" + httpStatusCode); - } - LoggingContext.clear(); - - - } - -} diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java index cd6706d..bc42d0f 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.interceptors.post; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.JsonObject; import org.onap.aai.exceptions.AAIException; import org.onap.aai.logging.ErrorLogHelper; @@ -42,7 +42,7 @@ import java.util.Optional; @Priority(AAIResponseFilterPriority.RESPONSE_TRANS_LOGGING) public class ResponseTransactionLogging extends AAIContainerFilter implements ContainerResponseFilter { - private static final EELFLogger TRANSACTION_LOGGER = EELFManager.getInstance().getLogger(ResponseTransactionLogging.class); + private static final Logger TRANSACTION_LOGGER = LoggerFactory.getLogger(ResponseTransactionLogging.class); @Autowired private HttpServletResponse httpServletResponse; @@ -57,24 +57,13 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co private void transLogging(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { - String logValue; - String getValue; - - try { - logValue = AAIConfig.get("aai.transaction.logging"); - getValue = AAIConfig.get("aai.transaction.logging.get"); - } catch (AAIException e) { - return; - } + String logValue = AAIConfig.get("aai.transaction.logging", "true"); + String isGetTransactionResponseLoggingEnabled = AAIConfig.get("aai.transaction.logging.get", "false"); String httpMethod = requestContext.getMethod(); if(Boolean.parseBoolean(logValue)){ - if(!Boolean.parseBoolean(getValue) && HttpMethod.GET.equals(httpMethod)){ - return; - } - String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); String fullUri = requestContext.getUriInfo().getRequestUri().toString(); @@ -96,7 +85,9 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co logEntry.addProperty("resourceId", fullUri); logEntry.addProperty("resourceType", httpMethod); logEntry.addProperty("rqstBuf", Objects.toString(request, "")); - logEntry.addProperty("respBuf", Objects.toString(response, "")); + if(Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled) || (!HttpMethod.GET.equals(httpMethod))) { + logEntry.addProperty("respBuf", Objects.toString(response, "")); + } try { TRANSACTION_LOGGER.debug(logEntry.toString()); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java index 85cb6be..66be48e 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java @@ -23,6 +23,8 @@ import org.onap.aai.exceptions.AAIException; import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; @@ -34,7 +36,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.UUID; @PreMatching @Priority(AAIRequestFilterPriority.HEADER_VALIDATION) @@ -45,35 +46,26 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq Optional<Response> oResp; - String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); - String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); - List<MediaType> acceptHeaderValues = requestContext.getAcceptableMediaTypes(); - + String fromAppId = getPartnerName(requestContext); oResp = this.validateHeaderValuePresence(fromAppId, "AAI_4009", acceptHeaderValues); if (oResp.isPresent()) { requestContext.abortWith(oResp.get()); return; } + String transId = getRequestId(requestContext); oResp = this.validateHeaderValuePresence(transId, "AAI_4010", acceptHeaderValues); if (oResp.isPresent()) { requestContext.abortWith(oResp.get()); return; } - - if (!this.isValidUUID(transId)) { - transId = UUID.randomUUID().toString(); - requestContext.getHeaders().get(AAIHeaderProperties.TRANSACTION_ID).clear(); - requestContext.getHeaders().add(AAIHeaderProperties.TRANSACTION_ID, transId); - } - } private Optional<Response> validateHeaderValuePresence(String value, String errorCode, List<MediaType> acceptHeaderValues) { Response response = null; AAIException aaie; - if (value == null) { + if (value == null || value.isEmpty()) { aaie = new AAIException(errorCode); return Optional.of(Response.status(aaie.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) @@ -82,5 +74,52 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq return Optional.ofNullable(response); } + public String getRequestId(ContainerRequestContext requestContext) { + String requestId = requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.HEADER_REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.TRANSACTION_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.ECOMP_REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + return requestId; + } + } + } + } + if (requestContext.getHeaders().get(ONAPLogConstants.Headers.REQUEST_ID) != null) { + requestContext.getHeaders().get(ONAPLogConstants.Headers.REQUEST_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.TRANSACTION_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.TRANSACTION_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.HEADER_REQUEST_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.HEADER_REQUEST_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.ECOMP_REQUEST_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.ECOMP_REQUEST_ID).clear(); + } + requestContext.getHeaders().add(Constants.HttpHeaders.TRANSACTION_ID, requestId); + + return requestId; + } + public String getPartnerName(ContainerRequestContext requestContext) { + String partnerName = requestContext.getHeaderString(ONAPLogConstants.Headers.PARTNER_NAME); + if (partnerName == null || (partnerName.isEmpty())) { + partnerName = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); + if (partnerName == null || (partnerName.isEmpty())) { + return partnerName; + } + } + if (requestContext.getHeaders().get(ONAPLogConstants.Headers.PARTNER_NAME) != null) { + requestContext.getHeaders().get(ONAPLogConstants.Headers.PARTNER_NAME).clear(); + } + if (requestContext.getHeaders().get(AAIHeaderProperties.FROM_APP_ID) != null) { + requestContext.getHeaders().get(AAIHeaderProperties.FROM_APP_ID).clear(); + } + requestContext.getHeaders().add(AAIHeaderProperties.FROM_APP_ID, partnerName); + return partnerName; + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/SetLoggingContext.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/SetLoggingContext.java deleted file mode 100644 index 32802d1..0000000 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/SetLoggingContext.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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.aai.schemaservice.interceptors.pre; - -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; - -import javax.annotation.Priority; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.PreMatching; -import java.io.IOException; - -@PreMatching -@Priority(AAIRequestFilterPriority.SET_LOGGING_CONTEXT) -public class SetLoggingContext extends AAIContainerFilter implements ContainerRequestFilter { - - @Autowired - private Environment environment; - - @Autowired - private HttpServletRequest httpServletRequest; - - @Override - public void filter(ContainerRequestContext requestContext) throws IOException { - - String uri = httpServletRequest.getRequestURI(); - String queryString = httpServletRequest.getQueryString(); - - if (queryString != null && !queryString.isEmpty()) { - uri = uri + "?" + queryString; - } - - String httpMethod = requestContext.getMethod(); - String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); - String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); - - LoggingContext.init(); - LoggingContext.requestId(transId); - LoggingContext.partnerName(fromAppId); - LoggingContext.targetEntity(environment.getProperty("spring.application.name")); - LoggingContext.component(fromAppId); - LoggingContext.serviceName(httpMethod + " " + uri); - LoggingContext.targetServiceName(httpMethod + " " + uri); - LoggingContext.statusCode(LoggingContext.StatusCode.COMPLETE); - } - -} diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/TwoWaySslAuthorization.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/TwoWaySslAuthorization.java deleted file mode 100644 index 4f69042..0000000 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/TwoWaySslAuthorization.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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.aai.schemaservice.interceptors.pre; - -import org.onap.aai.auth.AAIAuthCore; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.restcore.HttpMethod; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Profile; - -import javax.annotation.Priority; -import javax.security.auth.x500.X500Principal; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.PreMatching; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.security.cert.X509Certificate; -import java.util.*; -import java.util.stream.Collectors; - -@PreMatching -@Priority(AAIRequestFilterPriority.AUTHORIZATION) -@Profile("two-way-ssl") -public class TwoWaySslAuthorization extends AAIContainerFilter implements ContainerRequestFilter { - - private static final String PATCH = "PATCH"; - - @Autowired - private HttpServletRequest httpServletRequest; - - @Autowired - private AAIAuthCore aaiAuthCore; - - @Override - public void filter(ContainerRequestContext requestContext) { - - Optional<Response> oResp; - - String uri = requestContext.getUriInfo().getAbsolutePath().getPath(); - String httpMethod = getHttpMethod(requestContext); - - List<MediaType> acceptHeaderValues = requestContext.getAcceptableMediaTypes(); - - Optional<String> authUser = getUser(this.httpServletRequest); - - if (authUser.isPresent()) { - oResp = this.authorize(uri, httpMethod, acceptHeaderValues, authUser.get(), - this.getHaProxyUser(this.httpServletRequest), getCertIssuer(this.httpServletRequest)); - if (oResp.isPresent()) { - requestContext.abortWith(oResp.get()); - return; - } - } else { - AAIException aaie = new AAIException("AAI_9107"); - requestContext - .abortWith(Response - .status(aaie.getErrorObject().getHTTPResponseCode()).entity(ErrorLogHelper - .getRESTAPIErrorResponseWithLogging(acceptHeaderValues, aaie, new ArrayList<>())) - .build()); - } - - } - - private String getCertIssuer(HttpServletRequest hsr) { - String issuer = hsr.getHeader("X-AAI-SSL-Issuer"); - if (issuer != null && !issuer.isEmpty()) { - // the haproxy header replaces the ', ' with '/' and reverses on the '/' need to undo that. - List<String> broken = Arrays.asList(issuer.split("/")); - broken = broken.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList()); - Collections.reverse(broken); - issuer = String.join(", ", broken); - } else { - if (hsr.getAttribute("javax.servlet.request.cipher_suite") != null) { - X509Certificate[] certChain = (X509Certificate[]) hsr.getAttribute("javax.servlet.request.X509Certificate"); - if (certChain != null && certChain.length > 0) { - X509Certificate clientCert = certChain[0]; - issuer = clientCert.getIssuerX500Principal().getName(); - } - } - } - return issuer; - } - - private String getHttpMethod(ContainerRequestContext requestContext) { - String httpMethod = requestContext.getMethod(); - if (javax.ws.rs.HttpMethod.POST.equalsIgnoreCase(httpMethod) - && PATCH.equals(requestContext.getHeaderString(AAIHeaderProperties.HTTP_METHOD_OVERRIDE))) { - httpMethod = HttpMethod.MERGE_PATCH.toString(); - } - if (httpMethod.equalsIgnoreCase(HttpMethod.MERGE_PATCH.toString()) || PATCH.equalsIgnoreCase(httpMethod)) { - httpMethod = HttpMethod.PUT.toString(); - } - return httpMethod; - } - - private Optional<String> getUser(HttpServletRequest hsr) { - String authUser = null; - if (hsr.getAttribute("javax.servlet.request.cipher_suite") != null) { - X509Certificate[] certChain = (X509Certificate[]) hsr.getAttribute("javax.servlet.request.X509Certificate"); - - /* - * If the certificate is null or the certificate chain length is zero Then - * retrieve the authorization in the request header Authorization Check that it - * is not null and that it starts with Basic and then strip the basic portion to - * get the base64 credentials Check if this is contained in the AAIBasicAuth - * Singleton class If it is, retrieve the username associated with that - * credentials and set to authUser Otherwise, get the principal from certificate - * and use that authUser - */ - - if (certChain == null || certChain.length == 0) { - - String authorization = hsr.getHeader("Authorization"); - - if (authorization != null && authorization.startsWith("Basic ")) { - authUser = authorization.substring(6); - } - - } else { - X509Certificate clientCert = certChain[0]; - X500Principal subjectDN = clientCert.getSubjectX500Principal(); - authUser = subjectDN.toString().toLowerCase(); - } - } - - return Optional.ofNullable(authUser); - } - - private String getHaProxyUser(HttpServletRequest hsr) { - String haProxyUser; - if (Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-CN")) - || Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-OU")) - || Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-O")) - || Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-L")) - || Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-ST")) - || Objects.isNull(hsr.getHeader("X-AAI-SSL-Client-C"))) { - haProxyUser = ""; - } else { - haProxyUser = String.format("CN=%s, OU=%s, O=\"%s\", L=%s, ST=%s, C=%s", - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-CN"), ""), - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-OU"), ""), - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-O"), ""), - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-L"), ""), - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-ST"), ""), - Objects.toString(hsr.getHeader("X-AAI-SSL-Client-C"), "")).toLowerCase(); - } - return haProxyUser; - } - - private Optional<Response> authorize(String uri, String httpMethod, List<MediaType> acceptHeaderValues, - String authUser, String haProxyUser, String issuer) { - Response response = null; - try { - if (!aaiAuthCore.authorize(authUser, uri, httpMethod, haProxyUser, issuer)) { - throw new AAIException("AAI_9101", "Request on " + httpMethod + " " + uri + " status is not OK"); - } - } catch (AAIException e) { - response = Response.status(e.getErrorObject().getHTTPResponseCode()) - .entity(ErrorLogHelper.getRESTAPIErrorResponseWithLogging(acceptHeaderValues, e, new ArrayList<>())) - .build(); - } - return Optional.ofNullable(response); - } - -} diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java index e372c2a..016e86f 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.nodeschema; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.CaseFormat; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; @@ -54,7 +54,7 @@ import java.util.regex.Pattern; @Component public class NodeIngestor { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(NodeIngestor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(NodeIngestor.class); private static final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\."); private Map<SchemaVersion, DynamicJAXBContext> versionContextMap = new TreeMap<>(); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java index 07f4cf4..8c6399b 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.nodeschema; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.onap.aai.logging.LogFormatTools; import org.springframework.stereotype.Service; @@ -38,7 +38,7 @@ import java.util.Optional; @Service public class NodeSchemaService { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(NodeSchemaResource.class); + private static final Logger LOGGER = LoggerFactory.getLogger(NodeSchemaResource.class); private SchemaVersions schemaVersions; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java index badb09a..1e67bd9 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.query; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -35,7 +35,7 @@ import java.util.stream.Stream; @Service public class QueryService { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(QueryService.class); private String queryLocation; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java index 1a83aa5..766e56c 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java @@ -19,8 +19,8 @@ */ package org.onap.aai.schemaservice.service; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.eclipse.jetty.util.security.Password; import org.onap.aai.schemaservice.Profiles; import org.onap.aai.util.AAIConstants; @@ -41,7 +41,7 @@ import java.util.stream.Stream; @Service public class AuthorizationService { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(AuthorizationService.class); + private static final Logger logger = LoggerFactory.getLogger(AuthorizationService.class); private final Map<String, String> authorizedUsers = new HashMap<>(); @@ -72,7 +72,7 @@ public class AuthorizationService { String[] usernamePasswordArray = usernamePassword.split(":"); if(usernamePasswordArray == null || usernamePasswordArray.length != 3){ - throw new RuntimeException("Not a valid entry for the realm.properties entry: " + usernamePassword); + throw new RuntimeException("This username / pwd is not a valid entry in realm.properties"); } String username = usernamePasswordArray[0]; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java index 9fbe3a5..3023fab 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java @@ -38,6 +38,8 @@ import java.util.List; import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; +import org.onap.logging.filter.base.AuditLogContainerFilter; + @Component public class JerseyConfiguration extends ResourceConfig { @@ -58,19 +60,19 @@ public class JerseyConfiguration extends ResourceConfig { register(EdgeResource.class); //Request Filters - registerFiltersForRequests(); - // Response Filters - registerFiltersForResponses(); + registerFilters(ContainerRequestFilter.class); + registerFilters(ContainerResponseFilter.class); + registerFilters(AuditLogContainerFilter.class); } - public void registerFiltersForRequests() { + public <T> void registerFilters(Class<T> type) { - // Find all the classes within the interceptors package + Reflections loggingReflections = new Reflections("org.onap.aai.aailog.filter"); Reflections reflections = new Reflections("org.onap.aai.schemaservice.interceptors"); // Filter them based on the clazz that was passed in - Set<Class<? extends ContainerRequestFilter>> filters = reflections.getSubTypesOf(ContainerRequestFilter.class); - + Set<Class<? extends T>> filters = loggingReflections.getSubTypesOf(type); + filters.addAll(reflections.getSubTypesOf(type)); // Check to ensure that each of the filter has the @Priority annotation and if not throw exception for (Class filterClass : filters) { @@ -80,7 +82,7 @@ public class JerseyConfiguration extends ResourceConfig { } // Turn the set back into a list - List<Class<? extends ContainerRequestFilter>> filtersList = filters + List<Class<? extends T>> filtersList = filters .stream() .filter(f -> { if (f.isAnnotationPresent(Profile.class) @@ -98,36 +100,5 @@ public class JerseyConfiguration extends ResourceConfig { filtersList.forEach(this::register); } - public void registerFiltersForResponses() { - - // Find all the classes within the interceptors package - Reflections reflections = new Reflections("org.onap.aai.schemaservice.interceptors"); - // Filter them based on the clazz that was passed in - Set<Class<? extends ContainerResponseFilter>> filters = reflections.getSubTypesOf(ContainerResponseFilter.class); - - // Check to ensure that each of the filter has the @Priority annotation and if not throw exception - for (Class filterClass : filters) { - if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); - } - } - - // Turn the set back into a list - List<Class<? extends ContainerResponseFilter>> filtersList = filters.stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); - - // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); - - // Then register this to the jersey application - filtersList.forEach(this::register); - } } |