diff options
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
20 files changed, 318 insertions, 204 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicProperties.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicProperties.java index 5ff22635..e867deb1 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicProperties.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/music/util/MusicProperties.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -186,4 +186,40 @@ public class MusicProperties { } return true; } + + /** + * Tests whether a property value is available for the specified key. + * + * @param key + * Property key + * @return True if the key is known, otherwise false. + */ +/* public static boolean containsProperty(String key) { + return environment.containsProperty(key); + }*/ + + /** + * Returns the property value associated with the given key (never + * {@code null}), after trimming any trailing space. + * + * @param key + * Property key + * @return Property value; the empty string if the environment was not + * autowired, which should never happen. + * @throws IllegalStateException + * if the key is not found + */ +/* public static String getProperty(String key) { + String value = ""; + if (environment == null) { + // logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!"); + } else { + value = environment.getRequiredProperty(key); + // java.util.Properties preserves trailing space + if (value != null) + value = value.trim(); + } + return value; + }*/ + } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java index e0bf7b01..4a5e0331 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -854,7 +854,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @RequestMapping(value = { "/v2/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json") public String getEcompUser(HttpServletRequest request, HttpServletResponse response, @PathVariable("loginId") String loginId) throws Exception { - EcompUser user = null; + EcompUser user = new EcompUser(); ObjectMapper mapper = new ObjectMapper(); String answer = null; try { @@ -868,10 +868,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl sendErrorResponse(response, e); logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e); } - if (user != null) { - return mapper.writeValueAsString(user); - } - return null; + return mapper.writeValueAsString(user); } @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List") diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppController.java index 7c53d62c..afde8bc5 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppController.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -219,7 +219,7 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl if (appKeyValue == null || appKeyValue.equals("")) { logger.error(EELFLoggerDelegate.errorLogger, " App Key unavailable; Proceeding with null app name"); } else { - EPApp appRecord = appCacheService.getAppForAnalytics(appKeyValue); + EPApp appRecord = appCacheService.getAppFromUeb(appKeyValue); if (appRecord == null) { logger.error(EELFLoggerDelegate.errorLogger, " App could not be found for the key " + appKeyValue); } else diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/ecomp/model/AppContactUsItem.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/ecomp/model/AppContactUsItem.java index 9e1c3b3b..c7c8ebcc 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/ecomp/model/AppContactUsItem.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/ecomp/model/AppContactUsItem.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java index 25ca5e65..3160032f 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -61,8 +61,10 @@ import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice; import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum; import org.onap.portalapp.portal.logging.logic.EPLogUtil; +import org.onap.portalapp.portal.service.AppsCacheService; import org.onap.portalapp.portal.service.BasicAuthenticationCredentialService; import org.onap.portalapp.portal.service.ExternalAccessRolesService; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.service.RemoteWebServiceCallService; import org.onap.portalapp.service.sessionmgt.ManageService; @@ -79,8 +81,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.method.HandlerMethod; public class PortalResourceInterceptor extends ResourceInterceptor { - private static final String APP_KEY = "uebkey"; - + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PortalResourceInterceptor.class); @Autowired @@ -88,6 +89,9 @@ public class PortalResourceInterceptor extends ResourceInterceptor { @Autowired private ManageService manageService; + + @Autowired + AppsCacheService appCacheService; @Autowired private EPEELFLoggerAdvice epAdvice; @@ -167,7 +171,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { String secretKey = null; try { epAdvice.loadServletRequestBasedDefaults(request, SecurityEventTypeEnum.INCOMING_REST_MESSAGE); - if (!remoteWebServiceCallService.verifyRESTCredential(secretKey, request.getHeader(APP_KEY), + if (!remoteWebServiceCallService.verifyRESTCredential(secretKey, request.getHeader(EPCommonSystemProperties.UEB_KEY), request.getHeader("username"), request.getHeader("password"))) { throw new UrlAccessRestrictedException(); } @@ -180,7 +184,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { } if (controllerObj instanceof WebAnalyticsExtAppController) { - if (!remoteWebServiceCallService.verifyAppKeyCredential(request.getHeader(APP_KEY))) { + if (!remoteWebServiceCallService.verifyAppKeyCredential(request.getHeader(EPCommonSystemProperties.UEB_KEY))) { logger.error(EELFLoggerDelegate.errorLogger, "preHandle: failed to verify app key for web analytics call"); throw new UrlAccessRestrictedException(); @@ -226,8 +230,8 @@ public class PortalResourceInterceptor extends ResourceInterceptor { String uri = request.getRequestURI().toString(); uri = uri.substring(uri.indexOf("/", 1)); - final String authHeader = request.getHeader("Authorization"); - final String uebkey = request.getHeader("uebkey"); + final String authHeader = request.getHeader(EPCommonSystemProperties.AUTHORIZATION); + final String uebkey = request.getHeader(EPCommonSystemProperties.UEB_KEY); // Unauthorized access due to missing HTTP Authorization request header if (authHeader == null) { @@ -237,7 +241,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { return false; } - String[] accountNamePassword = getUserNamePassword(authHeader); + String[] accountNamePassword = EcompPortalUtils.getUserNamePassword(authHeader); if (accountNamePassword == null || accountNamePassword.length != 2) { final String msg = "failed to get username and password from Atuhorization header"; logger.debug(EELFLoggerDelegate.debugLogger, "checkBasicAuth: {}", msg); @@ -247,15 +251,11 @@ public class PortalResourceInterceptor extends ResourceInterceptor { if(uebkey !=null && !uebkey.isEmpty()) { - List<EPApp> app = externalAccessRolesService.getApp(uebkey); - EPApp application = null; - if (app.isEmpty()) { + EPApp application = appCacheService.getAppFromUeb(uebkey,1); + if (application == null) { throw new Exception("Invalid uebkey!"); } - if (app.size() != 0 && !app.isEmpty()) { - application = app.get(0); - } - if (application != null) { + else { final String appUsername = application.getUsername(); final String dbDecryptedPwd = CipherUtil.decryptPKC(application.getAppPassword()); if (appUsername.equals(accountNamePassword[0]) && dbDecryptedPwd.equals(accountNamePassword[1])) { @@ -317,13 +317,6 @@ public class PortalResourceInterceptor extends ResourceInterceptor { return true; } - private String[] getUserNamePassword(String authValue) { - String base64Credentials = authValue.substring("Basic".length()).trim(); - String credentials = new String(Base64.getDecoder().decode(base64Credentials), Charset.forName("UTF-8")); - final String[] values = credentials.split(":", 2); - return values; - } - @SuppressWarnings("unused") private String decrypted(String encrypted) throws Exception { String result = ""; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/listener/HealthMonitor.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/listener/HealthMonitor.java index 82f5637d..6df4f9bd 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/listener/HealthMonitor.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/listener/HealthMonitor.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -405,7 +405,6 @@ public class HealthMonitor { pQuery.addValue(creationTime.toString()); pQuery.addValue(APPLICATION); try { - MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.ATOMIC); MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.CRITICAL); } catch (MusicServiceException e) { return Boolean.FALSE; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java index 18fb5027..71338a84 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -38,15 +38,17 @@ package org.onap.portalapp.portal.logging.aop; import java.net.InetAddress; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; import javax.servlet.http.HttpServletRequest; +import org.onap.portalapp.portal.domain.EPApp; import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.service.AppsCacheService; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.util.EPUserUtils; import org.onap.portalsdk.core.exception.SessionExpiredException; import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; @@ -56,6 +58,7 @@ import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum; import org.onap.portalsdk.core.web.support.UserUtils; import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; import com.att.eelf.configuration.Configuration; @@ -63,6 +66,9 @@ import com.att.eelf.configuration.Configuration; public class EPEELFLoggerAdvice { private EELFLoggerDelegate adviceLogger = EELFLoggerDelegate.getLogger(EPEELFLoggerAdvice.class); + + @Autowired + AppsCacheService appCacheService; /** * DateTime Format according to the ONAP Application Logging Guidelines. @@ -166,7 +172,11 @@ public class EPEELFLoggerAdvice { String requestId = UUID.randomUUID().toString(); MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); } - MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown"); + + if (MDC.get(EPCommonSystemProperties.PARTNER_NAME) == null|| MDC.get(EPCommonSystemProperties.PARTNER_NAME).isEmpty()){ + MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown"); + } + MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE); @@ -310,62 +320,18 @@ public class EPEELFLoggerAdvice { && securityEventType != SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH && securityEventType != SecurityEventTypeEnum.INCOMING_UEB_MESSAGE) { // Load the RequestID (aka TrasactionId) into MDC context. - String requestId = UserUtils.getRequestId(req); - if (requestId == null||requestId.trim().length()==0) { - requestId = UUID.randomUUID().toString(); - } - MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); - - // Load user agent into MDC context, if available. - String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); - accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient; - if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla") - || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) { - accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE; - } - MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient); - - // Load loginId into MDC context. - EPUser user = null; - try { - user = EPUserUtils.getUserSession(req); - } catch (SessionExpiredException se) { - adviceLogger.debug(EELFLoggerDelegate.debugLogger, - "setHttpRequestBasedDefaultsIntoGlobalLoggingContext: No user found in session"); - } + loadRequestId(req); + + loadPartnerName(req); - MDC.put(EPCommonSystemProperties.MDC_LOGIN_ID, (user != null ? user.getOrgUserId() : "NoUser")); - - // Rest URL & Protocol - String restURL = ""; - MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN); - MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP); - restURL = UserUtils.getFullURL(req); - //if (restURL != null && restURL != "") { - if (restURL != null && restURL.trim().length()>0) { - MDC.put(EPCommonSystemProperties.FULL_URL, restURL); - if (restURL.toLowerCase().contains("https")) { - MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS); - } - } + loadLoginId(req); - // Rest Path - MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); - String restPath = req.getServletPath(); - //if (restPath != null && restPath != "") { - if (restPath != null && restPath.trim().length()>0) { + loadUrlProtocol(req); - MDC.put(Configuration.MDC_SERVICE_NAME, restPath); - } + loadServicePath(req, restMethod); - // Client IPAddress i.e. IPAddress of the remote host who is - // making this request. - String clientIPAddress = ""; - clientIPAddress = req.getHeader("X-FORWARDED-FOR"); - if (clientIPAddress == null) { - clientIPAddress = req.getRemoteAddr(); - } - MDC.put(EPCommonSystemProperties.CLIENT_IP_ADDRESS, clientIPAddress); + loadClientAddress(req); + } else if (securityEventType == SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH) { MDC.put(EPCommonSystemProperties.TARGET_ENTITY, "Phonebook"); MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search"); @@ -387,6 +353,105 @@ public class EPEELFLoggerAdvice { } } + private void loadClientAddress(HttpServletRequest req) { + // Client IPAddress i.e. IPAddress of the remote host who is + // making this request. + String clientIPAddress = ""; + clientIPAddress = req.getHeader("X-FORWARDED-FOR"); + if (clientIPAddress == null) { + clientIPAddress = req.getRemoteAddr(); + } + MDC.put(EPCommonSystemProperties.CLIENT_IP_ADDRESS, clientIPAddress); + } + + private void loadServicePath(HttpServletRequest req, String restMethod) { + // Rest Path + MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); + String restPath = req.getServletPath(); + //if (restPath != null && restPath != "") { + if (restPath != null && restPath.trim().length()>0) { + + MDC.put(Configuration.MDC_SERVICE_NAME, restPath); + } + } + + private void loadUrlProtocol(HttpServletRequest req) { + // Rest URL & Protocol + String restURL = ""; + MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN); + MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP); + restURL = UserUtils.getFullURL(req); + //if (restURL != null && restURL != "") { + if (restURL != null && restURL.trim().length()>0) { + MDC.put(EPCommonSystemProperties.FULL_URL, restURL); + if (restURL.toLowerCase().contains("https")) { + MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS); + } + } + } + + private void loadRequestId(HttpServletRequest req) { + String requestId = UserUtils.getRequestId(req); + if (requestId == null||requestId.trim().length()==0) { + requestId = UUID.randomUUID().toString(); + } + MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); + } + + private void loadLoginId(HttpServletRequest req) { + // Load loginId into MDC context. + String loginId = "NoUser"; + + try { + EPUser user = EPUserUtils.getUserSession(req); + loginId = (user != null ? user.getOrgUserId(): loginId); + } catch (SessionExpiredException se) { + adviceLogger.debug(EELFLoggerDelegate.debugLogger, + "setHttpRequestBasedDefaultsIntoGlobalLoggingContext: No user found in session"); + } + + // try fetching from username in header + final String nameHeader = req.getHeader(EPCommonSystemProperties.USERNAME); + if (nameHeader != null) { + loginId = nameHeader; + } + + // try fetching from BasicAuth info + final String authHeader = req.getHeader(EPCommonSystemProperties.AUTHORIZATION); + if (authHeader != null) { + String[] accountNamePassword = EcompPortalUtils.getUserNamePassword(authHeader); + if (accountNamePassword != null && accountNamePassword.length == 2) { + loginId = accountNamePassword[0]; + } + + } + + MDC.put(EPCommonSystemProperties.MDC_LOGIN_ID, loginId ); + + } + + private void loadPartnerName(HttpServletRequest req) { + + + // Load user agent into MDC context, if available. + String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); + accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient; + if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla") + || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) { + accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE; + } + MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient); + + // try get the Partner name from uebkey + String uebVal = req.getHeader(EPCommonSystemProperties.UEB_KEY); + if(uebVal != null) { + EPApp appRecord = appCacheService.getAppFromUeb(uebVal); + MDC.put(EPCommonSystemProperties.PARTNER_NAME, appRecord.getName()); + } + + + } + /** * * @param beginDateTime diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/logic/AuxDiscriminator.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/logic/AuxDiscriminator.java new file mode 100644 index 00000000..d3add13d --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/logic/AuxDiscriminator.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.portalapp.portal.logging.logic; + +import java.util.Map; + +import org.onap.portalsdk.core.util.SystemProperties; + +import ch.qos.logback.classic.sift.MDCBasedDiscriminator; +import ch.qos.logback.classic.spi.ILoggingEvent; + +public class AuxDiscriminator extends MDCBasedDiscriminator { + + final String MUSIC = "music"; + final String HEALTHMONITOR = "HealthMonitor"; + + @Override + public String getDiscriminatingValue(ILoggingEvent event) { + + String message = event.getMessage(); + if (message != null && message.matches("org.onap.music.*")) { + return getDefaultValue() + "-" + MUSIC; + } + + Map<String, String> mdcMap = event.getMDCPropertyMap(); + if (mdcMap == null) { + return getDefaultValue(); + } + String mdcValue = mdcMap.get(SystemProperties.MDC_CLASS_NAME); + if (mdcValue != null && mdcValue.endsWith(HEALTHMONITOR)) { + return getDefaultValue() + "-" + HEALTHMONITOR; + } + + + return getDefaultValue(); + } + + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java index 763505b3..4e470462 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java @@ -82,24 +82,5 @@ public class SchedulerAuxUtil { return (w); } - public static <T> String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException { - - String methodName = "convertPojoToString"; - ObjectMapper mapper = new ObjectMapper(); - String r_json_str = ""; - if ( t != null ) { - try { - r_json_str = mapper.writeValueAsString(t); - } - catch ( com.fasterxml.jackson.core.JsonProcessingException j ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json"); - } - } - return (r_json_str); - } - - public static void main(String[] args) { - // TODO Auto-generated method stub - } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java index c9f2c6ee..5a354f3a 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -358,48 +358,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient return post( clazz, appId, payload, restPath, SystemType.APPLICATION); } - //@Override - public <T> T postForClass(Class<T> clazz, long appId, Object payload, String restPath, Class<T> forClass) throws HTTPException { - WebClient client = null; - Response response = null; - T t = null; - logger.debug(EELFLoggerDelegate.debugLogger, "Entering to createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId); - client = createClientForApp(appId, restPath); - EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST request =", payload); - logger.debug(EELFLoggerDelegate.debugLogger, "Finished createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId); - try { - if (client != null) { - logger.debug(EELFLoggerDelegate.debugLogger, "Entering to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId); - response = client.post(payload); - logger.debug(EELFLoggerDelegate.debugLogger, "Finished to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId); - } else { - logger.error(EELFLoggerDelegate.errorLogger, - "Unable to create the Webclient to make the '" + restPath + "' API call."); - } - } catch (Exception e) { - MDC.put(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE, - Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)); - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeRestApiGeneralError, e); - logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while making the POST REST API call", e); - } - - if (response != null) { - verifyResponse(response); - - // String contentType = response.getHeaderString("Content-Type"); - if (clazz != null) { - String str = ((ResponseImpl)response).readEntity(String.class); - EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str); - try { - t = gson.fromJson(str, clazz); - } catch (Exception e) { - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e); - } - } - } - return t; - } - @Override public <T> T put(Class<T> clazz, long appId, Object payload, String restPath) throws HTTPException { diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java index 2aaf30df..b684d3f1 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -56,5 +56,7 @@ public interface AppsCacheService { */ String getAppEndpoint(Long appId); - EPApp getAppForAnalytics(String appKey); + EPApp getAppFromUeb(String appKey); + + EPApp getAppFromUeb(String appKey, Integer quickCacheRefresh); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java index 06adb7f5..0fb92900 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -73,47 +73,46 @@ public class AppsCacheServiceImple implements AppsCacheService { } } - CacheConfiguration appConf = null; - CacheConfiguration analyticsAppConf = null; + CacheConfiguration quickRefreshCacheConf = null; + CacheConfiguration slowRefreshCacheConf = null; private static volatile Map<Long, EPApp> appsMap; - private static volatile Map<String, EPApp> anlyticsAppsMap; + private static volatile Map<String, EPApp> uebAppsMap; @PostConstruct public void init() { - appConf = new CacheConfiguration(0, 10); - analyticsAppConf = new CacheConfiguration(0, 3600); + quickRefreshCacheConf = new CacheConfiguration(0, 120); + slowRefreshCacheConf = new CacheConfiguration(0, 3600); - this.refreshAppsMap(appConf); + this.refreshAppsMap(quickRefreshCacheConf); } - private Map<Long, EPApp> refreshAppsMap(CacheConfiguration conf) { + private void refreshAppsMap(CacheConfiguration conf) { long now = System.currentTimeMillis(); if(noNeedToUpdate(now, conf)) - return null; + return; synchronized (this) { if(noNeedToUpdate(now, conf)) - return null; + return; List<EPApp> allApps = appsService.getAppsFullList(); Map<Long, EPApp> newAppsMap = new HashMap<Long, EPApp>(); for (EPApp app : allApps) { newAppsMap.put(app.getId(), app); } - Map<String, EPApp> newAnalyticsAppsMap = new HashMap<String, EPApp>(); + Map<String, EPApp> newUebAppsMap = new HashMap<String, EPApp>(); for (EPApp app : allApps) { - newAnalyticsAppsMap.put(app.getUebKey(), app); + newUebAppsMap.put(app.getUebKey(), app); } // Switch cache with the new one. appsMap = newAppsMap; - anlyticsAppsMap = newAnalyticsAppsMap; + uebAppsMap = newUebAppsMap; conf.updateTime = now; } - return appsMap; } private boolean noNeedToUpdate(long now, CacheConfiguration conf) { @@ -127,7 +126,7 @@ public class AppsCacheServiceImple implements AppsCacheService { @Override public String getAppEndpoint(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app.getAppRestEndpoint(); @@ -136,7 +135,7 @@ public class AppsCacheServiceImple implements AppsCacheService { @Override public EPApp getApp(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app; @@ -144,9 +143,14 @@ public class AppsCacheServiceImple implements AppsCacheService { } @Override - public EPApp getAppForAnalytics(String appKey) { - refreshAppsMap(analyticsAppConf); - EPApp app = anlyticsAppsMap.get(appKey); + public EPApp getAppFromUeb(String appKey) { + return getAppFromUeb(appKey,0); + } + + @Override + public EPApp getAppFromUeb(String appKey, Integer quickCacheRefresh) { + refreshAppsMap(quickCacheRefresh == 1 ? quickRefreshCacheConf:slowRefreshCacheConf); + EPApp app = uebAppsMap.get(appKey); if(app != null) return app; return null; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImpl.java index a64aea47..3693906b 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -43,18 +43,13 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; import org.hibernate.SessionFactory; -import org.onap.portalapp.portal.controller.RoleManageController; import org.onap.portalapp.portal.domain.CentralV2RoleFunction; -import org.onap.portalapp.portal.domain.EPRole; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.exceptions.RoleFunctionException; import org.onap.portalapp.portal.utils.EcompPortalUtils; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java index 1811f8dc..e3ce07ff 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -482,6 +482,7 @@ public class UserRolesCommonServiceImpl { oldAppRole.setName(role.getName()); localSession.update(oldAppRole); } + oldAppRole.setActive(true); newRolesMap.remove(oldAppRole.getAppRoleId()); } else { obsoleteRoles.add(oldAppRole); @@ -817,16 +818,7 @@ public class UserRolesCommonServiceImpl { private EPUser addRemoteUser(List<RoleInAppForUser> roleInAppForUserList, String userId, EPApp app, ObjectMapper mapper, SearchService searchService, ApplicationsRestClientService applicationsRestClientService) throws Exception{ EPUser addRemoteUser = null; if (remoteUserShouldBeCreated(roleInAppForUserList)) { - createNewUserOnRemoteApp(userId, app, applicationsRestClientService, searchService, mapper, isAppUpgradeVersion(app)); - // If we succeed, we know that the new user was - // persisted on remote app. - addRemoteUser = getUserFromApp(userId, app, applicationsRestClientService); - if (addRemoteUser == null) { - logger.error(EELFLoggerDelegate.errorLogger, - "Failed to persist new user: " + userId + " in remote app. appId = " + app.getId()); - // return null; - } } return addRemoteUser; } @@ -890,14 +882,12 @@ public class UserRolesCommonServiceImpl { // if centralized app if (app.getCentralAuth()) { - // We should add If user does not exist in remote application if (!app.getId().equals(PortalConstants.PORTAL_APP_ID)) { - EPUser remoteAppUser = null; - remoteAppUser = checkIfRemoteUserExits(userId, app, applicationsRestClientService); - - if (remoteAppUser == null) { + try { addRemoteUser(roleInAppForUserList, userId, app, mapper, searchService, applicationsRestClientService); + } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, e.getMessage()); } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java index 755de799..0f91f620 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -130,7 +130,9 @@ public class UserServiceImpl implements UserService { logger.error(EELFLoggerDelegate.errorLogger, "getUserByUserId failed", e); } finally { try { + if(in!=null) { in.close(); + } con.disconnect(); } catch (IOException e) { logger.error(EELFLoggerDelegate.errorLogger, "getUserByUserId failed to close", e); @@ -187,8 +189,9 @@ public class UserServiceImpl implements UserService { in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); String inputLine; - while ((inputLine = in.readLine()) != null) + while ((inputLine = in.readLine()) != null) { response.append(inputLine); + } JSONObject jObject = new JSONObject(response.toString()); // json JSONArray jsonUsers = jObject.getJSONArray("response"); // get // data @@ -224,8 +227,10 @@ public class UserServiceImpl implements UserService { logger.error(EELFLoggerDelegate.errorLogger, "getUserByFirstLastName failed", e); } finally { try { + if(in!=null) { in.close(); con.disconnect(); + } } catch (IOException e) { logger.error(EELFLoggerDelegate.errorLogger, "getUserByFirstLastName failed to close", e); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EpNotificationItemVO.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EpNotificationItemVO.java index 9cb7c755..6f927b38 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EpNotificationItemVO.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EpNotificationItemVO.java @@ -197,10 +197,6 @@ public class EpNotificationItemVO extends DomainVo { this.createdDate = createdDate; } - public static long getSerialversionuid() { - return serialVersionUID; - } - public String getMsgSource() { return msgSource; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/RemoteRoleV1.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/RemoteRoleV1.java index 724c275d..51153fcb 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/RemoteRoleV1.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/RemoteRoleV1.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalapp.portal.transport; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EPCommonSystemProperties.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EPCommonSystemProperties.java index 53f6a3ee..2c619af8 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EPCommonSystemProperties.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EPCommonSystemProperties.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -96,5 +96,8 @@ public class EPCommonSystemProperties extends SystemProperties { public static final String MS_WIDGET_LOCAL_PORT = "microservices.widget.local.port"; public static final String MS_WIDGET_UPLOAD_FLAG = "microservices.widget.upload.flag"; - + public static final String UEB_KEY = "uebkey"; + public static final String AUTHORIZATION = "Authorization"; + public static final String USERNAME = "username"; + } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java index 53b69d7f..ab43149c 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -40,8 +40,10 @@ package org.onap.portalapp.portal.utils; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Base64; import java.util.Date; import java.util.List; @@ -564,4 +566,18 @@ public class EcompPortalUtils { return false; } } + /** + * + * It retrieves account information from input String + * + * @param authValue + * @return Array of Account information + * + */ + public static String[] getUserNamePassword(String authValue) { + String base64Credentials = authValue.substring("Basic".length()).trim(); + String credentials = new String(Base64.getDecoder().decode(base64Credentials), Charset.forName("UTF-8")); + final String[] values = credentials.split(":", 2); + return values; + } } diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml index 34bd66af..9d5c7328 100644 --- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml +++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml @@ -40,7 +40,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> -<!-- Publishes mappings and queries specific to the ECOMP Portal application. --> +<!-- Publishes mappings and queries specific to the ONAP Portal application. --> <hibernate-mapping package="org.onap.portalapp.portal.domain"> <!-- Widget class mapping details --> |