diff options
author | statta <statta@research.att.com> | 2019-08-23 16:49:45 -0400 |
---|---|---|
committer | statta <statta@research.att.com> | 2019-08-23 16:51:05 -0400 |
commit | a3a04c5887779e9ca8024a3e87ece109b8d9b0c1 (patch) | |
tree | d4c36f55aaba1f5a76bdf95308a0dc5ff21b425a /ecomp-portal-BE-common/src/main | |
parent | 7ce177cd99096772ff42ef89d8820070c687fd9b (diff) |
Onboarding Page Account Admin Change
Issue-ID: PORTAL-644
Change-Id: I95e43b1a2d12dcb5a4bc56d374cc6d30d8aae3f3
Signed-off-by: statta <statta@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
20 files changed, 543 insertions, 105 deletions
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 46493d86..7d9f297c 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 @@ -61,6 +61,7 @@ import org.onap.portalapp.portal.logging.aop.EPAuditLog; import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice; import org.onap.portalapp.portal.logging.logic.EPLogUtil; import org.onap.portalapp.portal.service.ExternalAccessRolesService; +import org.onap.portalsdk.core.service.UserService; import org.onap.portalapp.portal.transport.CentralRole; import org.onap.portalapp.portal.transport.CentralRoleFunction; import org.onap.portalapp.portal.transport.CentralUser; @@ -113,19 +114,14 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAccessRolesController.class); private static final DataValidator DATA_VALIDATOR = new DataValidator(); + @Autowired private AuditService auditService; - private ExternalAccessRolesService externalAccessRolesService; - private UserServiceCentalizedImpl userservice; @Autowired - public ExternalAccessRolesController(AuditService auditService, - ExternalAccessRolesService externalAccessRolesService, - UserServiceCentalizedImpl userservice) { - this.auditService = auditService; - this.externalAccessRolesService = externalAccessRolesService; - this.userservice = userservice; - } + private ExternalAccessRolesService externalAccessRolesService; + @Autowired + private UserService userservice = new UserServiceCentalizedImpl(); @ApiOperation(value = "Gets user role for an application.", response = CentralUser.class, responseContainer="List") @RequestMapping(value = { diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/MicroserviceController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/MicroserviceController.java index 2f956cc3..3f507726 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/MicroserviceController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/MicroserviceController.java @@ -55,7 +55,7 @@ import org.onap.portalapp.portal.domain.WidgetServiceHeaders; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; import org.onap.portalapp.portal.logging.aop.EPAuditLog; -import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.WidgetMService; import org.onap.portalapp.portal.service.MicroserviceService; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalsdk.core.util.SystemProperties; @@ -84,7 +84,7 @@ public class MicroserviceController extends EPRestrictedBaseController { RestTemplate template = new RestTemplate(); @Autowired - private ConsulHealthService consulHealthService; + private WidgetMService widgetMService; @Autowired private MicroserviceService microserviceService; @@ -153,7 +153,7 @@ public class MicroserviceController extends EPRestrictedBaseController { }; // If this service is assoicated with widgets, cannnot be deleted ResponseEntity<List<WidgetCatalog>> ans = template.exchange( - EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + EcompPortalUtils.widgetMsProtocol() + "://" + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + "/widget/microservices/widgetCatalog/service/" + serviceId, HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef); List<WidgetCatalog> widgets = ans.getBody(); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java index 9a525b51..ad164721 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java @@ -517,6 +517,7 @@ public class RoleManageController extends EPRestrictedBaseController { return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Data is not valid", "ERROR"); } } + EPUser user = EPUserUtils.getUserSession(request); boolean saveOrUpdateResponse = false; try { @@ -691,6 +692,7 @@ public class RoleManageController extends EPRestrictedBaseController { return null; } } + EPUser user = EPUserUtils.getUserSession(request); List<CentralizedApp> applicationsList = null; if (adminRolesService.isAccountAdmin(user) || adminRolesService.isSuperAdmin(user) 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 f1192f92..a3f4d301 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 @@ -55,7 +55,7 @@ import org.onap.portalapp.portal.logging.aop.EPAuditLog; import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice; import org.onap.portalapp.portal.logging.logic.EPLogUtil; import org.onap.portalapp.portal.service.AppsCacheService; -import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.WidgetMService; import org.onap.portalapp.portal.transport.Analytics; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; @@ -89,7 +89,7 @@ import org.springframework.web.client.AsyncRestTemplate; @EPAuditLog @NoArgsConstructor public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseController { - private ConsulHealthService consulHealthService; + private WidgetMService widgetMService; private AppsCacheService appCacheService; private static final String MACHINE_LEARNING_SERVICE_CTX = "/ml_api"; @@ -102,9 +102,9 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl private final FailureCallback failureCallback = arg -> logger.error(EELFLoggerDelegate.errorLogger, "storeAuxAnalytics failed", arg); @Autowired - public WebAnalyticsExtAppController(AppsCacheService appCacheService, ConsulHealthService consulHealthService) { + public WebAnalyticsExtAppController(AppsCacheService appCacheService, WidgetMService consulHealthService) { this.appCacheService = appCacheService; - this.consulHealthService = consulHealthService; + this.widgetMService = consulHealthService; } /** @@ -129,8 +129,8 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl } if (app != null) { String restEndPoint = app.getAppRestEndpoint(); - if(restEndPoint.contains("/api")) { - version = restEndPoint.substring(restEndPoint.indexOf("/api")+4); + if(restEndPoint.indexOf("/api")!=-1) { + version = restEndPoint.substring(restEndPoint.indexOf("api")); } } String endPoint = "/storeAnalytics"; @@ -242,7 +242,7 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl // send it! ListenableFuture<ResponseEntity<String>> out = restTemplate.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(CONSUL_ML_SERVICE_ID, + + widgetMService.getServiceLocation(CONSUL_ML_SERVICE_ID, SystemProperties.getProperty("microservices.m-learn.local.port")) + REGISTER_ACTION, HttpMethod.POST, entity, String.class); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetMSController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetMSController.java new file mode 100644 index 00000000..eab811ab --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetMSController.java @@ -0,0 +1,79 @@ +/*- + * ============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.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.controller.EPRestrictedBaseController; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.service.WidgetMService; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/portalApi/consul") +public class WidgetMSController extends EPRestrictedBaseController { + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetMSController.class); + + @Autowired + private WidgetMService widgetMService; + + // Get location of a healthy node running our service + @RequestMapping(value = { "/service/{service}" }, method = RequestMethod.GET, produces = "application/json") + public PortalRestResponse<String> getServiceLocation(HttpServletRequest request, HttpServletResponse response, + @PathVariable("service") String service) { + + try { + return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Success!", + widgetMService.getServiceLocation(service, null)); + } + catch (Exception e) { + logger.error(logger.errorLogger, "Couldn't get the service location"); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Error!", + "Couldn't get the service location"); + + } + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java index a7ce3557..57c73a89 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java @@ -60,7 +60,7 @@ import org.onap.portalapp.portal.domain.WidgetServiceHeaders; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; import org.onap.portalapp.portal.logging.aop.EPAuditLog; -import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.WidgetMService; import org.onap.portalapp.portal.service.MicroserviceService; import org.onap.portalapp.portal.service.WidgetParameterService; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; @@ -108,7 +108,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { private String whatService = "widgets-service"; @Autowired - private ConsulHealthService consulHealthService; + private WidgetMService widgetMService; @Autowired private MicroserviceService microserviceService; @@ -138,7 +138,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { try { ResponseEntity<List> ans = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + loginName, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), List.class); @@ -158,7 +158,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { try { ResponseEntity<List> ans = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog", HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), List.class); @@ -177,7 +177,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { public void updateWidgetCatalog(@RequestBody WidgetCatalog newWidgetCatalog, @PathVariable("widgetId") long widgetId) throws Exception { template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + widgetId, HttpMethod.PUT, new HttpEntity<>(newWidgetCatalog, WidgetServiceHeaders.getInstance()), String.class); @@ -187,7 +187,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { public void deleteOnboardingWidget(@PathVariable("widgetId") long widgetId) throws Exception { template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + widgetId, HttpMethod.DELETE, new HttpEntity<>(WidgetServiceHeaders.getInstance()), String.class); @@ -218,7 +218,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { multipartRequest.add("widget", request.getParameter("newWidget")); respond = template.postForObject( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + widgetId, new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class); @@ -269,7 +269,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { respond = template.postForObject( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog", new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class); @@ -291,7 +291,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { @RequestMapping(value = "/portalApi/microservices/{widgetId}/framework.js", method = RequestMethod.GET) public String getWidgetFramework(@PathVariable("widgetId") long widgetId) throws Exception { return template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/" + widgetId + "/framework.js", String.class, WidgetServiceHeaders.getInstance()); @@ -300,7 +300,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { @RequestMapping(value = "/portalApi/microservices/{widgetId}/controller.js", method = RequestMethod.GET) public String getWidgetController(@PathVariable("widgetId") long widgetId) throws Exception { return template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/" + widgetId + "/controller.js", String.class, WidgetServiceHeaders.getInstance()); @@ -309,7 +309,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { @RequestMapping(value = "/portalApi/microservices/{widgetId}/style.css", method = RequestMethod.GET) public String getWidgetCSS(@PathVariable("widgetId") long widgetId) throws Exception { return template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/" + widgetId + "/styles.css", String.class, WidgetServiceHeaders.getInstance()); @@ -323,7 +323,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { List<WidgetParameterResult> list = new ArrayList<>(); Long serviceId = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/parameters/" + widgetId, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), Long.class).getBody(); @@ -370,7 +370,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { byte[] byteFile = template .exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/download/" + widgetId, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), byte[].class) diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupController.java index e01c8ee6..0c464fbf 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupController.java @@ -43,7 +43,7 @@ import javax.servlet.http.HttpServletResponse; import org.onap.portalapp.controller.EPUnRestrictedBaseController; import org.onap.portalapp.portal.domain.WidgetServiceHeaders; import org.onap.portalapp.portal.logging.aop.EPAuditLog; -import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.WidgetMService; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; @@ -69,7 +69,7 @@ public class WidgetsCatalogMarkupController extends EPUnRestrictedBaseController private final String whatService = "widgets-service"; @Autowired - private ConsulHealthService consulHealthService; + private WidgetMService widgetMService; @Bean public CommonsMultipartResolver multipartResolver() { @@ -95,7 +95,7 @@ public class WidgetsCatalogMarkupController extends EPUnRestrictedBaseController return template .getForObject( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + "/widget/microservices/markup/" + widgetId, String.class, WidgetServiceHeaders.getInstance()); 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 b684d3f1..2a93556f 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 @@ -38,7 +38,10 @@ package org.onap.portalapp.portal.service; +import java.util.List; + import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.transport.OnboardingApp; public interface AppsCacheService { @@ -59,4 +62,6 @@ public interface AppsCacheService { EPApp getAppFromUeb(String appKey); EPApp getAppFromUeb(String appKey, Integer quickCacheRefresh); + + List<OnboardingApp> getAppsFullList(); } 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 0fb92900..3a70da84 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 @@ -37,9 +37,11 @@ */ package org.onap.portalapp.portal.service; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -51,6 +53,8 @@ import org.onap.portalapp.portal.logging.aop.EPMetricsLog; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalapp.portal.service.AppsCacheService; import org.onap.portalapp.portal.service.AppsCacheServiceImple; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; @Service("appsCacheService") @org.springframework.context.annotation.Configuration @@ -133,6 +137,24 @@ public class AppsCacheServiceImple implements AppsCacheService { return null; } + @SuppressWarnings("unchecked") + @Override + public List<OnboardingApp> getAppsFullList() { + refreshAppsMap(quickRefreshCacheConf); + List<EPApp> appList = new ArrayList<EPApp> (appsMap.values()); + appList.removeIf(app -> app.getId() == 1); + List<EPApp> appsFinalList = appList.stream() + .filter(app -> app.getEnabled() == true && app.getOpen() == false).collect(Collectors.toList()); + + List<OnboardingApp> onboardingAppsList = new ArrayList<OnboardingApp>(); + for (EPApp app : appsFinalList) { + OnboardingApp onboardingApp = new OnboardingApp(); + appsService.createOnboardingFromApp(app, onboardingApp); + onboardingAppsList.add(onboardingApp); + } + return onboardingAppsList; + } + @Override public EPApp getApp(Long appId) { refreshAppsMap(quickRefreshCacheConf); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java index c3cc2864..126d6276 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java @@ -859,7 +859,6 @@ public class EPAppCommonServiceImpl implements EPAppService { List<OnboardingApp> onboardingAppsList = new ArrayList<OnboardingApp>(); for (EPApp app : apps) { OnboardingApp onboardingApp = new OnboardingApp(); - app.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD); //to hide password from get request createOnboardingFromApp(app, onboardingApp); onboardingAppsList.add(onboardingApp); } @@ -1975,3 +1974,4 @@ public class EPAppCommonServiceImpl implements EPAppService { } } + diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java index 1821421a..92cbe90e 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java @@ -65,6 +65,9 @@ public class EPRoleServiceImpl implements EPRoleService { @Autowired private DataAccessService dataAccessService; + + @Autowired + ExternalAccessRolesService externalAccessRolesService; @SuppressWarnings("unchecked") public List<RoleFunction> getRoleFunctions() { @@ -157,9 +160,16 @@ public class EPRoleServiceImpl implements EPRoleService { params.put("appId", appId.toString()); params.put("roleName", roleName); portalParams.put("appRoleName", roleName); - if (appId == 1 || roleName.equals(PortalConstants.ADMIN_ROLE)) { + + List<EPRole> roleList = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID); + EPRole role = new EPRole(); + if(roleList.size()>0){ + role = roleList.get(0);} + logger.debug(EELFLoggerDelegate.debugLogger, "Requested RoleName is "+role.getName()); + + if (appId == 1 || roleName.equals(role.getName())) { roles = (List<EPRole>) dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null); - } else if (appId != 1 && !roleName.equals(PortalConstants.ADMIN_ROLE)) { + } else if (appId != 1 && !roleName.equals(role.getName())) { roles = (List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null); } int resultsCount = (roles == null ? 0 : roles.size()); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java index d064545d..53a7a5f5 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java @@ -509,4 +509,6 @@ public interface ExternalAccessRolesService { */ public List<EcompRole> missingUserApplicationRoles(String uebkey, String loginId, Set<EcompRole> CurrentUserRoles) throws Exception; + List<EPRole> getPortalAppRoleInfo(Long roleId); + } 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 d5a873a2..3d234012 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 @@ -1308,8 +1308,9 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic return roleInfo; } + @Override @SuppressWarnings("unchecked") - private List<EPRole> getPortalAppRoleInfo(Long roleId) { + public List<EPRole> getPortalAppRoleInfo(Long roleId) { List<EPRole> roleInfo; final Map<String, Long> getPortalAppRoleParams = new HashMap<>(); getPortalAppRoleParams.put("roleId", roleId); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java index 72f6a8d7..31cb8a45 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java @@ -76,7 +76,7 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { private static final String ADD_MARK = "&"; @Autowired - private ConsulHealthService consulHealthService; + private WidgetMService widgetMService; @Autowired MicroserviceService microserviceService; @Autowired @@ -104,7 +104,7 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { @SuppressWarnings({ "rawtypes", "unchecked" }) ResponseEntity<Long> ans = (ResponseEntity<Long>) template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" - + consulHealthService.getServiceLocation(whatService, + + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + "/widget/microservices/widgetCatalog/parameters/" + widgetId, HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), Long.class); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PortalAdminServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PortalAdminServiceImpl.java index 2aba0a42..a6aaea30 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PortalAdminServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PortalAdminServiceImpl.java @@ -52,6 +52,7 @@ import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; import org.onap.portalapp.portal.service.SearchService; import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPRole; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.logging.aop.EPMetricsLog; import org.onap.portalapp.portal.transport.ExternalAccessUser; @@ -96,6 +97,9 @@ public class PortalAdminServiceImpl implements PortalAdminService { RestTemplate template = new RestTemplate(); + @Autowired + ExternalAccessRolesService externalAccessRolesService; + @PostConstruct private void init() { SYS_ADMIN_ROLE_ID = SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID); @@ -162,7 +166,13 @@ public class PortalAdminServiceImpl implements PortalAdminService { transaction.commit(); // Add role in the external central auth system if(user != null && EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { - addPortalAdminInExternalCentralAuth(user.getOrgUserId(), PortalConstants.PORTAL_ADMIN_ROLE); + List<EPRole> roleList = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.SYS_ADMIN_ROLE_ID); + EPRole role = new EPRole(); + if(roleList.size()>0){ + role = roleList.get(0);} + logger.debug(EELFLoggerDelegate.debugLogger, "Requested RoleName is "+role.getName()); + + addPortalAdminInExternalCentralAuth(user.getOrgUserId(), role.getName()); } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "createPortalAdmin failed", e); @@ -228,7 +238,13 @@ public class PortalAdminServiceImpl implements PortalAdminService { "user_id='" + userId + "' AND role_id='" + SYS_ADMIN_ROLE_ID + "'", null); transaction.commit(); if(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()){ - deletePortalAdminInExternalCentralAuth(userId, PortalConstants.PORTAL_ADMIN_ROLE); + + List<EPRole> roleList = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.SYS_ADMIN_ROLE_ID); + EPRole role = new EPRole(); + if(roleList.size()>0){ + role = roleList.get(0);} + logger.debug(EELFLoggerDelegate.debugLogger, "Requested RoleName is "+role.getName()); + deletePortalAdminInExternalCentralAuth(userId, role.getName()); } } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "deletePortalAdmin failed", e); 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 522579d8..bfc232aa 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 @@ -189,8 +189,7 @@ public class UserRolesCommonServiceImpl { transaction = localSession.beginTransaction(); @SuppressWarnings("unchecked") List<EPUser> userList = localSession - .createQuery("from :name where orgUserId=:userId") - .setParameter("name",EPUser.class.getName()) + .createQuery("from EPUser where orgUserId=:userId") .setParameter("userId",userId) .list(); if (userList.size() == 0) { @@ -269,32 +268,37 @@ public class UserRolesCommonServiceImpl { * set to false if request is from users page otherwise true * @throws Exception */ + @SuppressWarnings("unchecked") protected void syncUserRoles(SessionFactory sessionFactory, String userId, Long appId, - EcompRole[] userAppRoles, Boolean extRequestValue, String reqType) throws Exception { + EcompRole[] userAppRoles, Boolean extRequestValue, String reqType,boolean checkIfUserisRoleAdmin,EcompRole[] appRoles) throws Exception { Session localSession = null; Transaction transaction = null; String roleActive = null; final Map<String, String> userAppParams = new HashMap<>(); final Map<String, String> appParams = new HashMap<>(); HashMap<Long, EcompRole> newUserAppRolesMap = hashMapFromEcompRoles(userAppRoles); - + List<EPRole> roleInfo = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID); + + EPRole adminRole = new EPRole(); + if(roleInfo.size()>0) + { + adminRole = roleInfo.get(0); + logger.debug(EELFLoggerDelegate.debugLogger, "Admin RoleName form DB: " + adminRole.getName()); + } try { localSession = sessionFactory.openSession(); transaction = localSession.beginTransaction(); @SuppressWarnings("unchecked") List<EPUser> userList = localSession - .createQuery("from :name where orgUserId=:userId") - .setParameter("name",EPUser.class.getName()) + .createQuery("from EPUser where orgUserId=:userId") .setParameter("userId",userId) .list(); if (userList.size() > 0) { EPUser client = userList.get(0); roleActive = ("DELETE".equals(reqType)) ? "" : " and role.active = 'Y'"; @SuppressWarnings("unchecked") - List<EPUserApp> userRoles = localSession.createQuery("from :name where app.id=:appId :roleActive and userId=:userId") - .setParameter("name",EPUserApp.class.getName()) + List<EPUserApp> userRoles = localSession.createQuery("from EPUserApp where app.id=:appId and userId=:userId" + roleActive) .setParameter("appId",appId) - .setParameter("roleActive",roleActive) .setParameter("userId",client.getId()) .list(); @@ -304,13 +308,32 @@ public class UserRolesCommonServiceImpl { userAppParams.put("appId", String.valueOf(appId)); appParams.put("appRoleName", userAppRoleList.getRole().getName()); @SuppressWarnings("unchecked") - List<EPRole> rolesList = (!userAppRoleList.getRole().getName().equals(PortalConstants.ADMIN_ROLE)) ? (List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", userAppParams, null) : (List<EPRole>) dataAccessService.executeNamedQuery("getPortalAppRoles", appParams, null); + List<EPRole> rolesList = (!userAppRoleList.getRole().getName().equals(adminRole.getName())) ? (List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", userAppParams, null) : (List<EPRole>) dataAccessService.executeNamedQuery("getPortalAppRoles", appParams, null); if(rolesList.size() > 0 || !rolesList.isEmpty()){ checkIfRoleInactive(rolesList.get(0)); } } } + + if (appRoles != null) { + List<EcompRole> appRolesList = Arrays.stream(appRoles).collect(Collectors.toList()); + List<EPUserApp> finalUserRolesList = new ArrayList<>(); + if (checkIfUserisRoleAdmin) { + for (EcompRole role : appRolesList) { + for (EPUserApp userAppRoleList : userRoles) { + if (userAppRoleList.getRole().getName().equals(role.getName())) + + { + finalUserRolesList.add(userAppRoleList); + } + } + } + userRoles = new ArrayList<>(); + userRoles.addAll(finalUserRolesList); + } + } + for (EPUserApp userRole : userRoles) { if (!userRole.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID) && userRole.getRoleId() != PortalConstants.SYS_ADMIN_ROLE_ID && !extRequestValue){ syncUserRolesExtension(userRole, appId, localSession, userAppRoles, newUserAppRolesMap); @@ -322,6 +345,8 @@ public class UserRolesCommonServiceImpl { syncUserRolesExtension(userRole, appId, localSession, userAppRoles, newUserAppRolesMap); } } + + Collection<EcompRole> newRolesToAdd = newUserAppRolesMap.values(); if (newRolesToAdd.size() > 0) { EPApp app = (EPApp) localSession.get(EPApp.class, appId); @@ -342,8 +367,7 @@ public class UserRolesCommonServiceImpl { } else { // remote app @SuppressWarnings("unchecked") List<EPRole> roles = localSession - .createQuery("from :name where appId=:appId") - .setParameter("name",EPRole.class.getName()) + .createQuery("from EPRole where appId=:appId") .setParameter("appId",appId) .list(); for (EPRole role : roles) { @@ -358,7 +382,7 @@ public class UserRolesCommonServiceImpl { EPRole role = null; for (EcompRole userRole : newRolesToAdd) { EPUserApp userApp = new EPUserApp(); - if (("PUT".equals(reqType) || "POST".equals(reqType)) && userRole.getName().equals(PortalConstants.ADMIN_ROLE)) { + if (("PUT".equals(reqType) || "POST".equals(reqType)) && userRole.getName().equals(adminRole.getName())) { role = (EPRole) localSession.get(EPRole.class, new Long(PortalConstants.ACCOUNT_ADMIN_ROLE_ID)); userApp.setRole(role); } else if ((userRole.getId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID)) && !extRequestValue){ @@ -507,8 +531,7 @@ public class UserRolesCommonServiceImpl { // active! @SuppressWarnings("unchecked") - List<EPRole> currentAppRoles = localSession.createQuery("from :name where appId = :appId") - .setParameter("name",EPRole.class.getName()) + List<EPRole> currentAppRoles = localSession.createQuery("from EPRole where appId = :appId") .setParameter("appId",appId) .list(); @@ -549,8 +572,7 @@ public class UserRolesCommonServiceImpl { // Delete from fn_user_role @SuppressWarnings("unchecked") List<EPUserApp> userRoles = localSession.createQuery( - "from :name where app.id=:appId and role_id=:roleId") - .setParameter("name",EPUserApp.class.getName()) + "from EPUserApp where app.id=:appId and role_id=:roleId") .setParameter("appId",appId) .setParameter("roleId",roleId) .list(); @@ -567,8 +589,7 @@ public class UserRolesCommonServiceImpl { // Delete from fn_menu_functional_roles @SuppressWarnings("unchecked") List<FunctionalMenuRole> funcMenuRoles = localSession - .createQuery("from :name where roleId=:roleId") - .setParameter("name",FunctionalMenuRole.class.getName()) + .createQuery("from FunctionalMenuRole where roleId=:roleId") .setParameter("roleId",roleId) .list(); int numMenuRoles = funcMenuRoles.size(); @@ -581,8 +602,7 @@ public class UserRolesCommonServiceImpl { // so must null out the url too, to be consistent @SuppressWarnings("unchecked") List<FunctionalMenuRole> funcMenuRoles2 = localSession - .createQuery("from :name where menuId=:menuId") - .setParameter("name",FunctionalMenuRole.class.getName()) + .createQuery("from FunctionalMenuRole where menuId=:menuId") .setParameter("menuId",menuId) .list(); int numMenuRoles2 = funcMenuRoles2.size(); @@ -597,8 +617,8 @@ public class UserRolesCommonServiceImpl { "syncAppRoles: There is exactly 1 menu item for this role, so emptying the url"); @SuppressWarnings("unchecked") List<FunctionalMenuItem> funcMenuItems = localSession - .createQuery( - "from " + FunctionalMenuItem.class.getName() + " where menuId=" + menuId) + .createQuery("from FunctionalMenuItem where menuId=:menuId") + .setParameter("menuId",menuId) .list(); if (funcMenuItems.size() > 0) { logger.debug(EELFLoggerDelegate.debugLogger, "got the menu item"); @@ -773,7 +793,7 @@ public class UserRolesCommonServiceImpl { * set to false if requests from Users page otherwise true * @return true on success, false otherwise */ - protected boolean applyChangesInUserRolesForAppToEcompDB(RolesInAppForUser rolesInAppForUser, boolean externalSystemRequest, String reqType,boolean isSystemUser) throws Exception { + protected boolean applyChangesInUserRolesForAppToEcompDB(RolesInAppForUser rolesInAppForUser, boolean externalSystemRequest, String reqType,boolean isSystemUser,Set<EcompRole> rolesDeletedByApprover ,boolean isLoggedInUserRoleAdminOfApp ) throws Exception { boolean result = false; String userId = rolesInAppForUser.orgUserId; Long appId = rolesInAppForUser.appId; @@ -792,7 +812,16 @@ public class UserRolesCommonServiceImpl { userAppRoles[i] = role; } try { - syncUserRoles(sessionFactory, userId, appId, userAppRoles, externalSystemRequest, reqType); + EcompRole[] applicationRoles = null; + + if(isLoggedInUserRoleAdminOfApp){ + List<EcompRole> roles = Arrays.stream(userAppRoles).collect(Collectors.toList()); + List<EcompRole> roles1 = rolesDeletedByApprover.stream().collect(Collectors.toList()); + roles.addAll(roles1); + applicationRoles = roles.stream().toArray(n -> new EcompRole[n]); + } + + syncUserRoles(sessionFactory, userId, appId, userAppRoles, externalSystemRequest, reqType,isLoggedInUserRoleAdminOfApp,applicationRoles); result = true; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, @@ -1027,15 +1056,36 @@ public class UserRolesCommonServiceImpl { } Long appId = newAppRolesForUser.getAppId(); List<RoleInAppForUser> roleInAppForUserList = newAppRolesForUser.getAppRoles(); + + + if (userId.length() > 0 ) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { EPApp app = appsService.getApp(appId); + + boolean checkIfUserisApplicationAccAdmin = adminRolesService.isAccountAdminOfApplication(user, + app); + Set<EcompRole> rolesGotDeletedFromApprover = new TreeSet<EcompRole>(); + + boolean checkIfUserisOnlyRoleAdmin = adminRolesService.isRoleAdmin(user) && !checkIfUserisApplicationAccAdmin; + if (checkIfUserisOnlyRoleAdmin) { + for (RoleInAppForUser roleInAppForUser : roleInAppForUserList) { + if (!roleInAppForUser.isApplied) { + EcompRole ecompRole = new EcompRole(); + ecompRole.setId(roleInAppForUser.roleId); + ecompRole.setName(roleInAppForUser.roleName); + rolesGotDeletedFromApprover.add(ecompRole); + } + } + } + applyChangesToUserAppRolesForMyLoginsRequest(user, appId); boolean systemUser = newAppRolesForUser.isSystemUser(); + if ((app.getCentralAuth() || app.getId().equals(PortalConstants.PORTAL_APP_ID)) && systemUser) { Set<EcompRole> userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList, mapper, @@ -1043,13 +1093,15 @@ public class UserRolesCommonServiceImpl { RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(userId, appId, userRolesInLocalApp); List<RoleInAppForUser> roleAppUserList = rolesInAppForUser.roles; + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); if (EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { // Apply changes in external Access system + updateUserRolesInExternalSystem(app, rolesInAppForUser.orgUserId, roleAppUserList, - epRequestValue, systemUser); + epRequestValue, systemUser,rolesGotDeletedByApprover,false); } result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, "Portal", - systemUser); + systemUser,rolesGotDeletedByApprover,false); }else if (!app.getCentralAuth() && systemUser) { @@ -1068,11 +1120,12 @@ public class UserRolesCommonServiceImpl { userRolesInLocalApp); List<RoleInAppForUser> roleAppUserList = rolesInAppForUser.roles; if (EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { + // Apply changes in external Access system updateUserRolesInExternalSystem(app, rolesInAppForUser.orgUserId, roleAppUserList, - epRequestValue,false); + epRequestValue,false,rolesGotDeletedFromApprover,checkIfUserisOnlyRoleAdmin); } - result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, "Portal", systemUser); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, "Portal", systemUser,rolesGotDeletedFromApprover,checkIfUserisOnlyRoleAdmin); } // In case if portal is not centralized then follow existing approach else if(!app.getCentralAuth() && app.getId().equals(PortalConstants.PORTAL_APP_ID)){ @@ -1080,7 +1133,8 @@ public class UserRolesCommonServiceImpl { applicationsRestClientService, appId, userId); RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(userId, appId, userRolesInLocalApp); - result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, "Portal",false); + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, "Portal",false,rolesGotDeletedByApprover,false); } else{// remote app EPUser remoteAppUser = null; if(!app.getCentralAuth() && !app.getId().equals(PortalConstants.PORTAL_APP_ID)){ @@ -1094,7 +1148,8 @@ public class UserRolesCommonServiceImpl { applicationsRestClientService, appId, userId,systemUser); RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(userId, appId, userRolesInRemoteApp); - result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, null,false); + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, epRequestValue, null,false,rolesGotDeletedByApprover,false); // If no roles remain, request app to set user inactive. if (userRolesInRemoteApp.size() == 0) { @@ -1137,7 +1192,7 @@ public class UserRolesCommonServiceImpl { * @param roleInAppUser Contains list of active roles */ @SuppressWarnings("unchecked") - private void updateUserRolesInExternalSystem(EPApp app, String orgUserId, List<RoleInAppForUser> roleInAppUser, boolean isPortalRequest,boolean isSystemUser) throws Exception + private void updateUserRolesInExternalSystem(EPApp app, String orgUserId, List<RoleInAppForUser> roleInAppUser, boolean isPortalRequest,boolean isSystemUser,Set<EcompRole> deletedRolesByApprover,boolean isLoggedInUserRoleAdminofApp) throws Exception { try { // check if user exists @@ -1159,6 +1214,8 @@ public class UserRolesCommonServiceImpl { HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth(); HttpEntity<String> getUserRolesEntity = new HttpEntity<>(headers); ResponseEntity<String> getResponse = externalAccessRolesService.getUserRolesFromExtAuthSystem(name, getUserRolesEntity); + + List<ExternalAccessUserRoleDetail> userRoleDetailList = new ArrayList<>(); String res = getResponse.getBody(); JSONObject jsonObj = null; @@ -1190,6 +1247,7 @@ public class UserRolesCommonServiceImpl { List<ExternalAccessUserRoleDetail> userRoleListMatchingInExtAuthAndLocal = CheckIfRoleAreMatchingInUserRoleDetailList(userRoleDetailList,app); + List<EcompUserAppRoles> userAppList = new ArrayList<>(); // If request coming from portal not from external role approval system then we have to check if user already // have account admin or system admin as GUI will not send these roles if (!isPortalRequest) { @@ -1199,7 +1257,7 @@ public class UserRolesCommonServiceImpl { final Map<String, Long> params = new HashMap<>(); params.put("appId", app.getId()); params.put("userId", user.getId()); - List<EcompUserAppRoles> userAppList = dataAccessService.executeNamedQuery("getUserAppExistingRoles", + userAppList = dataAccessService.executeNamedQuery("getUserAppExistingRoles", params, null); if (!roleInAppUser.isEmpty()) { for (EcompUserAppRoles userApp : userAppList) { @@ -1216,7 +1274,7 @@ public class UserRolesCommonServiceImpl { } List<RoleInAppForUser> roleInAppUserNonDupls = roleInAppUser.stream().distinct() .collect(Collectors.toList()); - final Map<String, RoleInAppForUser> currentUserRolesToUpdate = new HashMap<>(); + Map<String, RoleInAppForUser> currentUserRolesToUpdate = new HashMap<>(); for (RoleInAppForUser roleInAppUserNew : roleInAppUserNonDupls) { currentUserRolesToUpdate.put(roleInAppUserNew.getRoleName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"), roleInAppUserNew); } @@ -1224,6 +1282,35 @@ public class UserRolesCommonServiceImpl { for (ExternalAccessUserRoleDetail extAccessUserRole : userRoleListMatchingInExtAuthAndLocal) { currentUserRolesInExternalSystem.put(extAccessUserRole.getName(), extAccessUserRole); } + + if (isLoggedInUserRoleAdminofApp) { + if (deletedRolesByApprover.size() > 0) { + List<ExternalAccessUserRoleDetail> newUpdatedRoles = new ArrayList<>(); + Set<EcompRole> roles = new HashSet<>(); + for (ExternalAccessUserRoleDetail userRole : userRoleListMatchingInExtAuthAndLocal) { + for (EcompRole role : deletedRolesByApprover) { + if ((userRole.getName().substring(app.getNameSpace().length() + 1)).equals(role.getName())) { + roles.add(role); + newUpdatedRoles.add(userRole); + } + } + } + if (newUpdatedRoles.size() > 0) { + userRoleListMatchingInExtAuthAndLocal = new ArrayList<>(); + userRoleListMatchingInExtAuthAndLocal.addAll(newUpdatedRoles); + } else { + userRoleListMatchingInExtAuthAndLocal = new ArrayList<>(); + currentUserRolesToUpdate = new HashMap<>(); + + } + + } else { + userRoleListMatchingInExtAuthAndLocal = new ArrayList<>(); + currentUserRolesToUpdate = new HashMap<>(); + + } + } + // Check if user roles does not exists in local but still there in External Central Auth System delete them all for (ExternalAccessUserRoleDetail userRole : userRoleListMatchingInExtAuthAndLocal) { if (!(currentUserRolesToUpdate @@ -1575,13 +1662,15 @@ public class UserRolesCommonServiceImpl { RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(), userRolesInLocalApp); List<RoleInAppForUser> roleAppUserList = rolesInAppForUser.roles; + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + if(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) { // Apply changes in external Access system - updateUserRolesInExternalSystem(app, rolesInAppForUser.orgUserId, roleAppUserList, externalSystemRequest,false); + updateUserRolesInExternalSystem(app, rolesInAppForUser.orgUserId, roleAppUserList, externalSystemRequest,false,rolesGotDeletedByApprover,false); } logger.info(EELFLoggerDelegate.debugLogger, "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}", logMessage, newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId()); - result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,false); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,false,rolesGotDeletedByApprover,false); } // If local application is not centralized else if(!app.getCentralAuth() && app.getId().equals(PortalConstants.PORTAL_APP_ID)){ @@ -1589,7 +1678,9 @@ public class UserRolesCommonServiceImpl { applicationsRestClientService, app.getId(), orgUserId); RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(orgUserId, app.getId(), userRolesInLocalApp); - result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,false); + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, reqType,false,rolesGotDeletedByApprover,false); } else {// remote app // If adding just account admin role don't do remote application user call if (!((roleInAppForUserList.size() == 1 || reqType.equals("DELETE")) && checkIfAdminRoleExists)) { @@ -1609,8 +1700,10 @@ public class UserRolesCommonServiceImpl { logger.info(EELFLoggerDelegate.debugLogger, "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}", logMessage, newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId()); + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, - reqType,false); + reqType,false,rolesGotDeletedByApprover,false); // If no roles remain, request app to set user inactive. /* * if (userRolesInRemoteApp.size() == 0) { @@ -1632,8 +1725,10 @@ public class UserRolesCommonServiceImpl { userRolesInRemoteApp); logger.info(EELFLoggerDelegate.debugLogger, "setExternalRequestUserAppRole: {} user app roles: for app {}, user {}", logMessage, newAppRolesForUser.getApplicationName(), newAppRolesForUser.getLoginId()); + Set<EcompRole> rolesGotDeletedByApprover = new TreeSet<>(); + result = applyChangesInUserRolesForAppToEcompDB(rolesInAppForUser, externalSystemRequest, - reqType,false); + reqType,false,rolesGotDeletedByApprover,false); } if(!result){ reqMessage = "Failed to save the user app role(s)"; @@ -1705,7 +1800,15 @@ public class UserRolesCommonServiceImpl { roleInAppForUserList); throw new Exception(roleInAppForUser.getRoleName() + " role is unavailable for "+ appName + " application"); } else { - ecompRole.roleId = (appId == 1 || roleInAppForUser.getRoleName().equals(PortalConstants.ADMIN_ROLE)) ? existingAppRole.getId() : existingAppRole.getAppRoleId(); + + List<EPRole> roleInfo = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID); + EPRole adminRole = new EPRole(); + if(roleInfo.size()>0) + { + adminRole = roleInfo.get(0); + logger.debug(EELFLoggerDelegate.debugLogger, "Admin RoleName form DB: " + adminRole.getName()); + } + ecompRole.roleId = (appId == 1 || roleInAppForUser.getRoleName().equals(adminRole.getName())) ? existingAppRole.getId() : existingAppRole.getAppRoleId(); ecompRole.roleName = roleInAppForUser.getRoleName(); ecompRole.isApplied = true; existingUserRoles.add(ecompRole); @@ -1817,6 +1920,7 @@ public class UserRolesCommonServiceImpl { } EcompRole[] appRoles = null; + boolean checkIfUserisApplicationAccAdmin = false; List<EcompRole> roles = new ArrayList<>(); if (app.getCentralAuth()) { final Map<String, Long> appParams = new HashMap<>(); @@ -1825,7 +1929,7 @@ public class UserRolesCommonServiceImpl { appParams, null); EPApp application = appService.getApp(appId); - boolean checkIfUserisApplicationAccAdmin = adminRolesService.isAccountAdminOfApplication(user, + checkIfUserisApplicationAccAdmin = adminRolesService.isAccountAdminOfApplication(user, application); List<EPRole> rolesetwithfunctioncds = new ArrayList<EPRole>(); @@ -1959,19 +2063,23 @@ public class UserRolesCommonServiceImpl { EcompRole epRole = appRolesList.stream() .filter(x -> role.getName().equals(x.getName())).findAny().orElse(null); List<RoleFunction> roleFunList = new ArrayList<>(); - if(epRole.getRoleFunctions().size()>0) - roleFunList.addAll(epRole.getRoleFunctions()); - boolean checkIfFunctionsExits = roleFunList.stream().anyMatch( - roleFunction -> roleFunction.getType().equalsIgnoreCase("Approver")); - if (checkIfFunctionsExits) { - finalUserAppRolesList.add(role); - List<RoleFunction> filteredList = roleFunList.stream() - .filter(x -> "Approver".equalsIgnoreCase(x.getType())) - .collect(Collectors.toList()); - roleNames = filteredList.stream().map(RoleFunction::getCode) - .collect(Collectors.toList()); + + if (epRole != null) { + if (epRole.getRoleFunctions().size() > 0) + roleFunList.addAll(epRole.getRoleFunctions()); + boolean checkIfFunctionsExits = roleFunList.stream().anyMatch( + roleFunction -> roleFunction.getType().equalsIgnoreCase("Approver")); + if (checkIfFunctionsExits) { + finalUserAppRolesList.add(role); + List<RoleFunction> filteredList = roleFunList.stream() + .filter(x -> "Approver".equalsIgnoreCase(x.getType())) + .collect(Collectors.toList()); + roleNames = filteredList.stream().map(RoleFunction::getCode) + .collect(Collectors.toList()); + }else{ + roleNames.add(epRole.getName()); + } } - for (String name : roleNames) { EcompRole ecompRole = appRolesList.stream() .filter(x -> name.equals(x.getName())).findAny().orElse(null); @@ -2036,9 +2144,12 @@ public class UserRolesCommonServiceImpl { } EcompRole[] userAppRolesActive = activeRoles.toArray(new EcompRole[activeRoles.size()]); + + boolean checkIfUserisRoleAdmin = adminRolesService.isRoleAdmin(user) && !checkIfUserisApplicationAccAdmin; + // If the remote application isn't down we MUST sync user // roles here in case we have this user here! - syncUserRoles(sessionFactory, userId, appId, userAppRolesActive, extRequestValue, null); + syncUserRoles(sessionFactory, userId, appId, userAppRolesActive, extRequestValue, null,checkIfUserisRoleAdmin,appRoles); } catch (Exception e) { // TODO: we may need to check if user exists, maybe remote // app is down. 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 new file mode 100644 index 00000000..dd03d06d --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMService.java @@ -0,0 +1,59 @@ +/*- + * ============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.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' + * + * @param service + * @param fallbackPortOnLocalhost + * value provided by the calling service + * @return Service location + */ + public String getServiceLocation(String service, String fallbackPortOnLocalhost) throws NoHealthyServiceException; + +} 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 new file mode 100644 index 00000000..21f1648d --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/WidgetMServiceImpl.java @@ -0,0 +1,57 @@ +/*- + * ============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.service; + +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.stereotype.Component; + +@Component +public class WidgetMServiceImpl implements WidgetMService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetMServiceImpl.class); + + @Override + public String getServiceLocation(String service, String fallbackPortOnLocalHost) { + logger.debug(logger.debugLogger, "Requested Service: "+ service); + String localFallbackServiceLocation = EcompPortalUtils.localOrDockerHost() + ":" + fallbackPortOnLocalHost; + logger.debug(logger.debugLogger, "returned service location: "+ localFallbackServiceLocation); + return localFallbackServiceLocation; + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java index e0396e34..805e04a4 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java @@ -41,23 +41,33 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletResponse; +import org.onap.portalapp.portal.domain.EPApp; import org.onap.portalapp.portal.logging.aop.EPAuditLog; import org.onap.portalapp.portal.logging.aop.EPMetricsLog; 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.transport.OnboardingApp; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalapp.util.SystemType; import org.onap.portalsdk.core.exception.UrlAccessRestrictedException; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; +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.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; +import org.apache.commons.lang.StringUtils; import com.att.eelf.configuration.Configuration; @@ -66,6 +76,10 @@ import com.att.eelf.configuration.Configuration; @EnableAspectJAutoProxy public class SessionCommunication { EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SessionCommunication.class); + @Autowired + private AppsCacheService appsCacheService; + + private static final String BASIC_AUTHENTICATION_HEADER = "Authorization"; @EPAuditLog public String sendGet(OnboardingApp app) throws Exception { @@ -90,9 +104,18 @@ public class SessionCommunication { con.setConnectTimeout(3000); con.setReadTimeout(8000); // add request header + Map<String,String> headers = getHeaders(app); + appUserName =headers.get("username"); + encriptedPwdDB = headers.get("password"); + con.setRequestProperty("username", appUserName); con.setRequestProperty("password", encriptedPwdDB); + + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + encriptedPwdDB).getBytes()); + String encodingStr = "Basic " + encoding; + con.setRequestProperty(BASIC_AUTHENTICATION_HEADER, encodingStr); + // con.set responseCode = con.getResponseCode(); logger.debug(EELFLoggerDelegate.debugLogger, "Response Code : " + responseCode); @@ -153,9 +176,16 @@ public class SessionCommunication { con.setConnectTimeout(3000); con.setReadTimeout(15000); - // add request header + Map<String,String> headers = getHeaders(app); + appUserName =headers.get("username"); + encriptedPwdDB = headers.get("password"); + con.setRequestProperty("username", appUserName); con.setRequestProperty("password", encriptedPwdDB); + + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + encriptedPwdDB).getBytes()); + String encodingStr = "Basic " + encoding; + con.setRequestProperty(BASIC_AUTHENTICATION_HEADER, encodingStr); con.setRequestProperty("sessionMap", sessionTimeoutMap); con.setDoInput(true); @@ -209,11 +239,17 @@ public class SessionCommunication { con.setConnectTimeout(3000); con.setReadTimeout(15000); - // add request header + Map<String,String> headers = getHeaders(app); + appUserName =headers.get("username"); + encriptedPwdDB = headers.get("password"); + con.setRequestProperty("username", appUserName); con.setRequestProperty("password", encriptedPwdDB); - - // con.setRequestProperty("portalJSessionId", portalJSessionId); + + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + encriptedPwdDB).getBytes()); + String encodingStr = "Basic " + encoding; + con.setRequestProperty(BASIC_AUTHENTICATION_HEADER, encodingStr); + con.setDoInput(true); con.setDoOutput(true); con.getOutputStream().flush(); @@ -287,4 +323,43 @@ public class SessionCommunication { MDC.remove(EPCommonSystemProperties.PARTNER_NAME); } } -} + + public Map<String,String> getHeaders(OnboardingApp app) + { + String encriptedPwdDB = ""; + String appUserName = ""; + + + Map<String,String> headersMap = new HashMap<>(); + EPApp externalApp = null; + + if(app.appPassword.isEmpty() || app.appPassword==null){ + logger.debug(EELFLoggerDelegate.debugLogger, "Entering in the externalApp get app password contains null : {}"); + externalApp = appsCacheService.getApp(1L); + logger.debug(EELFLoggerDelegate.debugLogger, "external App Information : {}",externalApp); + + String mechidUsername=externalApp.getUsername(); + logger.debug(EELFLoggerDelegate.debugLogger, "external App mechidUsername Information : {}",mechidUsername); + + String password=externalApp.getAppPassword(); + String decreptedexternalAppPwd = StringUtils.EMPTY; + try { + decreptedexternalAppPwd = CipherUtil.decryptPKC(password, + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (CipherUtilException e) { + logger.error(EELFLoggerDelegate.errorLogger, "failed to decreptedexternalAppPwd when external app pwd is null", e); + } + + appUserName =mechidUsername; + encriptedPwdDB = decreptedexternalAppPwd; + + }else{ + appUserName = app.username; + encriptedPwdDB = app.appPassword; + } + + headersMap.put("username", appUserName); + headersMap.put("password", encriptedPwdDB); + return headersMap; + } +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/TimeoutHandler.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/TimeoutHandler.java index fe1d29d6..c855a8dc 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/TimeoutHandler.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/TimeoutHandler.java @@ -54,6 +54,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean; import org.onap.portalapp.portal.logging.aop.EPMetricsLog; 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.EPAppService; import org.onap.portalapp.portal.transport.OnboardingApp; import org.onap.portalapp.portal.utils.EcompPortalUtils; @@ -89,6 +90,7 @@ public class TimeoutHandler extends QuartzJobBean { @Autowired private SessionCommunication sessionCommunication; + @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { try { @@ -102,8 +104,9 @@ public class TimeoutHandler extends QuartzJobBean { ManageService manageService = (ManageService) applicationContext.getBean("manageService"); EPAppService appService = (EPAppService) applicationContext.getBean("epAppService"); - - List<OnboardingApp> appList = appService.getEnabledNonOpenOnboardingApps(); + AppsCacheService appsCacheService = (AppsCacheService)applicationContext.getBean("appsCacheService"); + + List<OnboardingApp> appList = appsCacheService.getAppsFullList(); onboardedAppList = appList; TypeReference<Hashtable<String, TimeoutVO>> typeRef = new TypeReference<Hashtable<String, TimeoutVO>>() { }; |