diff options
Diffstat (limited to 'ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal')
20 files changed, 305 insertions, 133 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java index 7615b660..5aea7f1c 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java @@ -50,8 +50,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.portalapp.controller.EPRestrictedRESTfulBaseController; +import org.onap.portalapp.music.conf.MusicSession; +import org.onap.portalapp.music.util.MusicUtil; import org.onap.portalapp.portal.domain.EPApp; import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPServiceCookie; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.logging.aop.EPAuditLog; import org.onap.portalapp.portal.service.AdminRolesService; @@ -70,6 +73,8 @@ import org.onap.portalapp.validation.DataValidator; import org.onap.portalapp.validation.SecureString; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.util.SystemProperties; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -240,4 +245,30 @@ public class ExternalAppsRestfulController extends EPRestrictedRESTfulBaseContro logger.warn(EELFLoggerDelegate.errorLogger, "Handling bad request", e); response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage()); } + + @EPAuditLog + @RequestMapping(value = { "/validateCookie" }, method = RequestMethod.POST) + public boolean validateCookie(@RequestBody EPServiceCookie epServiceCookie, HttpServletRequest request) throws Exception { + Map<String,String> epServiceCookieValueMap = epServiceCookie.getValue(); + if(epServiceCookieValueMap!=null) { + String multifactorauthfrontendurl = SystemProperties.getProperty("frontend_url"); + String encryptedJSessionId = epServiceCookieValueMap.get(multifactorauthfrontendurl); + if(encryptedJSessionId != null) { + String jSessionId = CipherUtil.decryptPKC(encryptedJSessionId); + if(jSessionId != null) { + if(jSessionId.equals(request.getSession().getId())) { + if(MusicUtil.isMusicEnable()) { + MusicSession musicSession = new MusicSession(); + String sessionId = musicSession.getAttribute(encryptedJSessionId); + logger.info(EELFLoggerDelegate.errorLogger, "Music sessionid : "+sessionId); + return (sessionId != null); + } else { + return true; + } + } + } + } + } + return false; + } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java index 97af4373..5e13127c 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java @@ -49,6 +49,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.Response; import org.json.JSONObject; import org.onap.portalapp.controller.EPRestrictedBaseController; @@ -74,6 +75,7 @@ import org.onap.portalapp.util.EPUserUtils; import org.onap.portalapp.validation.DataValidator; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -641,10 +643,18 @@ public class FunctionalMenuController extends EPRestrictedBaseController { */ @RequestMapping(value = { "/portalApi/userApplicationRoles" }, method = RequestMethod.GET, produces = "application/json") - public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request, + public List<BusinessCardApplicationRolesList> getAppList(HttpServletRequest request, HttpServletResponse response, @RequestParam("userId") String userId) throws IOException { List<BusinessCardApplicationRolesList> AppRoles = null; + + if(!UserUtils.getUserSession(request).getOrgUserId().equalsIgnoreCase(userId)) { + logger.error(EELFLoggerDelegate.errorLogger, "Not authorized to view roles of others "); + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + response.getWriter().flush(); + return null; + } + try { List<BusinessCardApplicationRole> userAppRoleList = functionalMenuService.getUserAppRolesList(userId); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java index 6818d505..ca66809f 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java @@ -192,16 +192,17 @@ public class HealthCheckController extends EPUnRestrictedBaseController { } statusCollection.add(CassandraStatusInfo); - HealthStatusInfo zookeeperStatusInfo = new HealthStatusInfo("Music-zookeeper"); - //zookeeperStatusInfo.hostName = EcompPortalUtils.getMyHostName(); - zookeeperStatusInfo.ipAddress = MusicUtil.getMyZkHost(); - if (!HealthMonitor.isZookeeperStatusOk()) { - overallStatus = false; - zookeeperStatusInfo.healthCheckStatus = statusDown; - zookeeperStatusInfo.description = "Check the logs for more details"; - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckZookeeperError); - } - statusCollection.add(zookeeperStatusInfo); + /* + * HealthStatusInfo zookeeperStatusInfo = new + * HealthStatusInfo("Music-zookeeper"); --zookeeperStatusInfo.hostName = + * EcompPortalUtils.getMyHostName(); zookeeperStatusInfo.ipAddress = + * MusicUtil.getMyZkHost(); if (!HealthMonitor.isZookeeperStatusOk()) { + * overallStatus = false; zookeeperStatusInfo.healthCheckStatus = statusDown; + * zookeeperStatusInfo.description = "Check the logs for more details"; + * EPLogUtil.logEcompError(logger, + * EPAppMessagesEnum.MusicHealthCheckZookeeperError); } + * statusCollection.add(zookeeperStatusInfo); + */ } String json = ""; 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 41273ecf..92449a3a 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 @@ -89,12 +89,12 @@ import org.springframework.web.client.AsyncRestTemplate; @EPAuditLog @NoArgsConstructor public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseController { + public static final String FEED_ML = "feed.ml"; private WidgetMService widgetMService; private AppsCacheService appCacheService; private static final String MACHINE_LEARNING_SERVICE_CTX = "/ml_api"; private static final String REGISTER_ACTION = MACHINE_LEARNING_SERVICE_CTX + "/" + "registerAction"; - private static final String CONSUL_ML_SERVICE_ID = "machine-learning"; private static final String APP_KEY = "uebkey"; private static final String ERROR_MSG = " Error retrieving Application to capture app name for analytics; Proceeding with empty app name"; private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WebAnalyticsExtAppController.class); @@ -102,7 +102,6 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl private final SuccessCallback<ResponseEntity<String>> successCallback = arg -> logger.info(EELFLoggerDelegate.debugLogger, arg.getBody()); private final FailureCallback failureCallback = arg -> logger.error(EELFLoggerDelegate.errorLogger, "storeAuxAnalytics failed", arg); - @Autowired public WebAnalyticsExtAppController(AppsCacheService appCacheService, WidgetMService consulHealthService) { this.appCacheService = appCacheService; @@ -170,19 +169,23 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl try { MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC()); String appName = ""; - try { - appName = getAppName(request, appName); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, + try { + appName = getAppName(request, appName); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, ERROR_MSG, e); - } + } - try { - storeAuxAnalytics(analyticsMap, appName); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, + try { + if(SystemProperties.containsProperty(FEED_ML) && + SystemProperties.getProperty(FEED_ML).equals("true")) { + storeAuxAnalytics(analyticsMap, appName); + } + + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, ERROR_MSG, e); - } + } MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC()); @@ -218,7 +221,7 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl private EPApp getApp(HttpServletRequest request) { String appKeyValue = request.getHeader(APP_KEY); EPApp appRecord = null; - if (appKeyValue == null || "".equals(appKeyValue)) { + if (appKeyValue == null || appKeyValue.equals("")) { logger.error(EELFLoggerDelegate.errorLogger, " App Key unavailable; Proceeding with null app name"); } else { appRecord = appCacheService.getAppFromUeb(appKeyValue); @@ -226,15 +229,16 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl return appRecord; } - private void storeAuxAnalytics(Analytics analyticsMap, String appName) { + protected void storeAuxAnalytics(Analytics analyticsMap, String appName) { logger.info(EELFLoggerDelegate.debugLogger, " Registering an action for recommendation: AppName/Function/UserId " + appName + "/" + analyticsMap.getFunction() + "/" + analyticsMap.getUserid()); + Map<String, String> requestMapping = new HashMap<>(); requestMapping.put("id", analyticsMap.getUserid()); requestMapping.put("action", appName + "|" + analyticsMap.getFunction()); - + HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); @@ -243,12 +247,11 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl // send it! ListenableFuture<ResponseEntity<String>> out = restTemplate.exchange( - EcompPortalUtils.widgetMsProtocol() + "://" - + widgetMService.getServiceLocation(CONSUL_ML_SERVICE_ID, - SystemProperties.getProperty("microservices.m-learn.local.port")) + EcompPortalUtils.widgetMLProtocol() + "://" + + widgetMService.getMLServiceLocation() + REGISTER_ACTION, HttpMethod.POST, entity, String.class); out.addCallback(successCallback, failureCallback); } -} +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPServiceCookie.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPServiceCookie.java new file mode 100644 index 00000000..b4eb6fcc --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPServiceCookie.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 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.domain; + +import java.util.Map; + + +public class EPServiceCookie { + Map<String, String> value; + + public Map<String, String> getValue() { + return value; + } + + public void setValue(Map<String, String> value) { + this.value = value; + } + +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceException.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceException.java index 2f78f807..3a4dc174 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceException.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceException.java @@ -37,9 +37,9 @@ */ package org.onap.portalapp.portal.exceptions; -import com.ecwid.consul.ConsulException; -public class NoHealthyServiceException extends ConsulException{ + +public class NoHealthyServiceException extends Exception{ private static final long serialVersionUID = -7089437673127729813L; 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 39c906a1..3209f35a 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 @@ -42,6 +42,7 @@ package org.onap.portalapp.portal.interceptor; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.HashMap; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; 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 4805a77d..31a323e4 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 @@ -143,18 +143,18 @@ public class HealthMonitor { } if(org.onap.portalapp.music.util.MusicUtil.isMusicEnable()){ - zookeeperStatusOk = checkZookeeperStatus(); - - if (!zookeeperStatusOk) { - if ((numIntervalsZookeeperNotHealthy % numIntervalsBetweenAlerts) == 0) { - logger.debug(EELFLoggerDelegate.debugLogger, - "monitorEPHealth: cluster nodes down, logging to error log to trigger alert."); - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckZookeeperError); - numIntervalsZookeeperNotHealthy++; - } else { - numIntervalsZookeeperNotHealthy = 0; - } - } + /* + * zookeeperStatusOk = checkZookeeperStatus(); + * + * if (!zookeeperStatusOk) { if ((numIntervalsZookeeperNotHealthy % + * numIntervalsBetweenAlerts) == 0) { + * logger.debug(EELFLoggerDelegate.debugLogger, + * "monitorEPHealth: cluster nodes down, logging to error log to trigger alert." + * ); EPLogUtil.logEcompError(logger, + * EPAppMessagesEnum.MusicHealthCheckZookeeperError); + * numIntervalsZookeeperNotHealthy++; } else { numIntervalsZookeeperNotHealthy = + * 0; } } + */ cassandraStatusOk = checkCassandraStatus(); if (!cassandraStatusOk) { @@ -257,6 +257,7 @@ public class HealthMonitor { String state = zkNodeStatistics.substring(zkNodeStatistics.indexOf("Mode:"), zkNodeStatistics.indexOf("Node")); logger.info(EELFLoggerDelegate.applicationLogger, + "Getting Status for zookeeper :" + zookeeperNode.trim() + ":------:" + state); if (state.contains("leader") || state.contains("follower")) { return true; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java index 14dfebee..93310a97 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterface.java @@ -37,32 +37,34 @@ */ package org.onap.portalapp.portal.scheduler; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializer; import java.util.Collections; import java.util.Date; + import javax.security.auth.login.CredentialException; -import javax.ws.rs.client.Client; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.Response; -import lombok.NoArgsConstructor; + import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.StringUtils; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.impl.ResponseImpl; import org.eclipse.jetty.util.security.Password; import org.json.simple.JSONObject; import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum; import org.onap.portalapp.portal.logging.logic.EPLogUtil; -import org.onap.portalapp.portal.scheduler.client.HttpBasicClient; -import org.onap.portalapp.portal.scheduler.client.HttpsBasicClient; import org.onap.portalapp.portal.scheduler.restobjects.RestObject; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializer; + +import lombok.NoArgsConstructor; + @SuppressWarnings("MalformedFormatString") @Service @NoArgsConstructor @@ -73,10 +75,10 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { + " MethodName: %APPLICATION_JSON, Url: %APPLICATION_JSON"; private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerRestInterface.class); - private static Client client = null; + private static WebClient client = null; private static Gson gson = null; - private MultivaluedHashMap<String, Object> commonHeaders; + private MultivaluedHashMap<String, String> commonHeaders; private static void init() { logger.debug(EELFLoggerDelegate.debugLogger, "initializing"); @@ -89,7 +91,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { gson = builder.create(); } - public void initRestClient() { + public void initRestClient(String URI) { logger.debug(EELFLoggerDelegate.debugLogger, "Starting to initialize rest client"); init(); @@ -130,19 +132,28 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { commonHeaders = new MultivaluedHashMap<>(); commonHeaders.put("Authorization", Collections.singletonList(("Basic " + authStringEnc))); - try { - if (!username.isEmpty()) { - - client = HttpBasicClient.getClient(); - } else { - - client = HttpsBasicClient.getClient(); - } - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Unable to initialize rest client",e.getMessage()); - - } + // try { + // if (!username.isEmpty()) { + // + // client = HttpBasicClient.getClient(); + // } else { + // + // client = HttpsBasicClient.getClient(); + // } + // } catch (Exception e) { + // logger.debug(EELFLoggerDelegate.debugLogger, "Unable to initialize rest client",e.getMessage()); + // + // } + + client = WebClient.create(URI); + client.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON); + //client.path(""); + client.headers(commonHeaders); + logger.debug(EELFLoggerDelegate.debugLogger, "Client Initialized"); + + + } @@ -155,10 +166,13 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { logger.debug(EELFLoggerDelegate.debugLogger, "URL FOR GET : ", url); try { - initRestClient(); - - final Response cres = client.target(url).request().accept(APPLICATION_JSON).headers(commonHeaders).get(); + initRestClient(url); + + + //final Response cres = client.target(url).request().accept(APPLICATION_JSON).headers(commonHeaders).get(); + final ResponseImpl cres = (ResponseImpl)client.get(); + logger.debug(EELFLoggerDelegate.debugLogger, "The implemenation class of Response : ", cres.getClass().getName()); int status = cres.getStatus(); restObject.setStatusCode(status); @@ -211,11 +225,10 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { try { - initRestClient(); + initRestClient(url); // Change the content length - final Response cres = client.target(url).request().accept(APPLICATION_JSON).headers(commonHeaders) - .post(Entity.entity(requestDetails, MediaType.APPLICATION_JSON)); + final ResponseImpl cres = (ResponseImpl)client.post(requestDetails.toJSONString()); if (cres != null && cres.getEntity() != null) { @@ -268,38 +281,5 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { throw new UnsupportedOperationException(); } - @SuppressWarnings("unchecked") - public <T> void Delete(T t, JSONObject requestDetails, String sourceID, String path, RestObject<T> restObject) { - - String methodName = "Delete"; - String url = ""; - Response cres; - - try { - initRestClient(); - - url = SchedulerProperties.getProperty(SchedulerProperties.SCHEDULER_SERVER_URL_VAL) + path; - - cres = client.target(url).request().accept(APPLICATION_JSON).headers(commonHeaders) - // .entity(r) - .build("DELETE", Entity.entity(requestDetails, MediaType.APPLICATION_JSON)).invoke(); - - int status = cres.getStatus(); - restObject.setStatusCode(status); - if (cres.getEntity() != null) { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - } - - } catch (HttpClientErrorException e) { - logger.error(EELFLoggerDelegate.errorLogger, " HttpClientErrorException:Exception For the Delete", - methodName, url, e); - EPLogUtil.schedulerAccessAlarm(logger, e.getStatusCode().value()); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "Exception For the Delete", methodName, url, e); - EPLogUtil.schedulerAccessAlarm(logger, HttpStatus.INTERNAL_SERVER_ERROR.value()); - throw e; - } - } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterfaceIfc.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterfaceIfc.java index 8d37a125..77ebe6a0 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterfaceIfc.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/SchedulerRestInterfaceIfc.java @@ -45,13 +45,10 @@ import org.springframework.stereotype.Service; @Service public interface SchedulerRestInterfaceIfc { - void initRestClient(); + void initRestClient(String URI); <T> void Get(T t, String sourceId, String path, org.onap.portalapp.portal.scheduler.restobjects.RestObject<T> restObject ) throws Exception; - <T> void Delete(T t, JSONObject requestDetails, String sourceID, String path, RestObject<T> restObject) - throws Exception; - <T> void Post(T t, JSONObject r, String path, RestObject<T> restObject) throws Exception; void logRequest(JSONObject requestDetails); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpBasicClient.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpBasicClient.java index 17dc3f1e..b2fff55f 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpBasicClient.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpBasicClient.java @@ -42,10 +42,11 @@ package org.onap.portalapp.portal.scheduler.client; import javax.servlet.ServletContext; +import javax.ws.rs.RuntimeType; import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import org.glassfish.jersey.client.ClientConfig; +import org.apache.cxf.jaxrs.client.spec.ClientBuilderImpl; +import org.apache.cxf.jaxrs.impl.ConfigurationImpl; import org.glassfish.jersey.client.ClientProperties; import org.onap.portalapp.portal.scheduler.util.CustomJacksonJaxBJsonProvider; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -71,10 +72,14 @@ public class HttpBasicClient{ */ public static Client getClient() throws Exception { - ClientConfig config = new ClientConfig(); - config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + //ClientConfig config = new ClientConfig(); + + ConfigurationImpl config = new ConfigurationImpl(RuntimeType.CLIENT); + config.setProperty(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + ClientBuilderImpl impl = new ClientBuilderImpl(); - return ClientBuilder.newClient(config) + Class.forName(org.apache.cxf.jaxrs.impl.ResponseImpl.class.getName()); + return impl.withConfig(config).build() .register(CustomJacksonJaxBJsonProvider.class); } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java index 9784356c..4e83b921 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java @@ -2893,7 +2893,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null); } - if (!roleFunction.isEmpty()) { + if (!roleFunction.isEmpty() && roleId != null) { EPAppRoleFunction apRoleFunction = new EPAppRoleFunction(); apRoleFunction.setAppId(app.getId()); apRoleFunction.setRoleId(roleId); 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 bfc232aa..ab688820 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 @@ -1084,7 +1084,7 @@ public class UserRolesCommonServiceImpl { applyChangesToUserAppRolesForMyLoginsRequest(user, appId); - boolean systemUser = newAppRolesForUser.isSystemUser(); + Boolean systemUser = (newAppRolesForUser.getIsSystemUser() != null ? newAppRolesForUser.getIsSystemUser() : false); if ((app.getCentralAuth() || app.getId().equals(PortalConstants.PORTAL_APP_ID)) && systemUser) { @@ -2303,10 +2303,15 @@ public class UserRolesCommonServiceImpl { EPApp app = appsService.getApp(appId); //If local or centralized application if (appId == PortalConstants.PORTAL_APP_ID || app.getCentralAuth()) { + Map<String, Object> params = new HashMap<>(); + params.put("id", app.getId()); + params.put("active", true); @SuppressWarnings("unchecked") - List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null); + //List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null); + //List<Object[]> userList = (List<Object[]>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null); + List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null); for (EPUser user : userList) { - UserApplicationRoles userWithAppRoles = convertToUserApplicationRoles(appId, user, app); + UserApplicationRoles userWithAppRoles = convertToUserApplicationRoles(user, app.getId()); if (userWithAppRoles.getRoles() != null && userWithAppRoles.getRoles().size() > 0) userApplicationRoles.add(userWithAppRoles); } @@ -2336,6 +2341,29 @@ public class UserRolesCommonServiceImpl { /** * + * @param user + * @param app_id + * @return + */ + private UserApplicationRoles convertToUserApplicationRoles(EPUser user, Long appId) { + UserApplicationRoles userWithRemoteAppRoles = new UserApplicationRoles(); + userWithRemoteAppRoles.setAppId(appId); + userWithRemoteAppRoles.setOrgUserId(user.getOrgUserId()); + userWithRemoteAppRoles.setFirstName(user.getFirstName()); + userWithRemoteAppRoles.setLastName(user.getLastName()); + List<RemoteRole> roleList = new ArrayList<RemoteRole>(); + for(EPUserApp userApp :user.getEPUserApps()) { + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setName(userApp.getRole().getName()); + remoteRole.setId(userApp.getRole().getId()); + roleList.add(remoteRole); + } + userWithRemoteAppRoles.setRoles(roleList); + return userWithRemoteAppRoles; + } + + /** + * * @param appId * @param user * @param appgetUsersFromAppEndpoint diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMService.java index dd03d06d..1c53a0c3 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMService.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMService.java @@ -37,17 +37,12 @@ */ package org.onap.portalapp.portal.service; -import java.util.List; - import org.onap.portalapp.portal.exceptions.NoHealthyServiceException; -import com.ecwid.consul.ConsulException; -import com.orbitz.consul.model.health.ServiceHealth; - public interface WidgetMService { /** - * This method returns the location of one healthy node if found in Consul - - * If not found in / by Consul, it falls back to 'localhost' + * This method returns the location of Widget MS - + * * * @param service * @param fallbackPortOnLocalhost @@ -56,4 +51,13 @@ public interface WidgetMService { */ public String getServiceLocation(String service, String fallbackPortOnLocalhost) throws NoHealthyServiceException; + + /** + * This method returns the location of Machine learning - + * + * + * @return Service location + */ + public String getMLServiceLocation(); + } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMServiceImpl.java index 21f1648d..29180d5e 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMServiceImpl.java @@ -39,6 +39,7 @@ package org.onap.portalapp.portal.service; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.stereotype.Component; @Component @@ -53,5 +54,13 @@ public class WidgetMServiceImpl implements WidgetMService { logger.debug(logger.debugLogger, "returned service location: "+ localFallbackServiceLocation); return localFallbackServiceLocation; } + + @Override + public String getMLServiceLocation() { + logger.debug(logger.debugLogger, "Requested Service: ML"); + String localFallbackServiceLocation = EcompPortalUtils.mlLocalOrDockerHost() + ":" + SystemProperties.getProperty("microservices.ml.port"); + logger.debug(logger.debugLogger, "returned service location: "+ localFallbackServiceLocation); + return localFallbackServiceLocation; + } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/AppWithRolesForUser.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/AppWithRolesForUser.java index cbfe1787..3d7363e2 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/AppWithRolesForUser.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/AppWithRolesForUser.java @@ -53,9 +53,8 @@ import lombok.ToString; @ToString public class AppWithRolesForUser { private String orgUserId; - private boolean isSystemUser; + private Boolean isSystemUser; private Long appId; private String appName; private List<RoleInAppForUser> appRoles; - } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/FunctionalMenuItem.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/FunctionalMenuItem.java index 14ad2f4c..a2148c2f 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/FunctionalMenuItem.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/FunctionalMenuItem.java @@ -73,7 +73,7 @@ public class FunctionalMenuItem implements Serializable { public Integer column; @Column(name = "TEXT") - @Max(value = 100) + //@Max(value = 100) @SafeHtml @NotNull public String text; @@ -83,13 +83,13 @@ public class FunctionalMenuItem implements Serializable { public Integer parentMenuId; @Column(name = "URL") - @Max(value = 128) + //@Max(value = 128) @SafeHtml @NotNull public String url; @Column(name="ACTIVE_YN") - @Max(value = 1) + //@Max(value = 1) @SafeHtml @NotNull public String active_yn; @@ -134,4 +134,5 @@ public class FunctionalMenuItem implements Serializable { public void setRestrictedApp(Boolean restrictedApp) { this.restrictedApp = restrictedApp; } + } 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 e253bfcf..981a2ac6 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 @@ -90,6 +90,9 @@ public class EPCommonSystemProperties extends SystemProperties { public static final String WIDGET_MS_PROTOCOL = "microservices.widget.protocol"; public static final String WIDGET_MS_HOSTNAME = "microservices.widget.hostname"; + public static final String WIDGET_ML_PROTOCOL = "microservices.ml.protocol"; + public static final String WIDGET_ML_HOSTNAME = "microservices.ml.hostname"; + public static final String WIDGET_ML_PORT = "microservices.ml.port"; public static final String REMOTE_CENTRALIZED_SYSTEM_ACCESS = "remote_centralized_system_access"; public static final String APP_DISPLAY_PASSWORD = "*******"; @@ -102,4 +105,7 @@ public class EPCommonSystemProperties extends SystemProperties { public static final String PASSWORD = "password"; public static final String PORTAL_LEFT_MENU = "portal_left_menu"; + public static final String EPSERVICE_COOKIE_SECURE = "epsservice.cookie.secure"; + public static final String MULTI_FACTOR_AUTH_FRONTEND_URL = "frontend_url"; + } 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 30eeac04..7c9aa76b 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 @@ -376,6 +376,15 @@ public class EcompPortalUtils { public static String widgetMsProtocol() { return getPropertyOrDefault(EPCommonSystemProperties.WIDGET_MS_PROTOCOL, "https"); } + + /** + * Answers the protocol to use. + * + * @return Protocol name from property file; defaults to https. + */ + public static String widgetMLProtocol() { + return getPropertyOrDefault(EPCommonSystemProperties.WIDGET_ML_PROTOCOL, "https"); + } /** * Answers the host to use. @@ -385,6 +394,15 @@ public class EcompPortalUtils { public static String localOrDockerHost() { return getPropertyOrDefault(EPCommonSystemProperties.WIDGET_MS_HOSTNAME, "localhost"); } + + /** + * Answers the host to use. + * + * @return Host name from property file; defaults to localhost. + */ + public static String mlLocalOrDockerHost() { + return getPropertyOrDefault(EPCommonSystemProperties.WIDGET_ML_HOSTNAME, "localhost"); + } /** * It returns headers where username and password of external central auth is diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java index 988b97a5..891f6d78 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepository.java @@ -50,6 +50,20 @@ import org.springframework.security.web.csrf.CsrfTokenRepository; import org.springframework.security.web.csrf.DefaultCsrfToken; import org.springframework.util.StringUtils; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; + public final class MusicCookieCsrfTokenRepository implements CsrfTokenRepository { static final String CSRF_COOKIE_NAME = "XSRF-TOKEN"; @@ -111,12 +125,22 @@ public final class MusicCookieCsrfTokenRepository implements CsrfTokenRepository return new MusicCookieCsrfTokenRepository(result); } - private String getSessionIdFromCookie (HttpServletRequest request){ + private String getSessionIdFromCookie (HttpServletRequest request) throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException, CipherUtilException{ Cookie cookies[] = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (EP_SERVICE.equals(cookie.getName())) { - return cookie.getValue(); + ObjectMapper mapper = new ObjectMapper(); + Map<String,String> epServiceCookieValueMap = mapper.readValue(URLDecoder.decode(cookie.getValue(), "UTF-8"),HashMap.class); + String sessionId = null; + if(epServiceCookieValueMap!=null) { + String multifactorauthfrontendurl = EPCommonSystemProperties.getProperty(EPCommonSystemProperties.MULTI_FACTOR_AUTH_FRONTEND_URL); + String encryptedJSessionId = epServiceCookieValueMap.get(multifactorauthfrontendurl); + if(encryptedJSessionId != null) { + sessionId = CipherUtil.decryptPKC(encryptedJSessionId); + } + } + return sessionId; } } } |