From 3e7145fc12ed8475ba10bb2a3c63004d41aa42bc Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Fri, 7 Jul 2017 07:21:10 -0400 Subject: [PORTAL-25] Role Centralization Bump EP SDK version to 1.3.0-SNAPSHOT Support Role Centralization & Common Set of Roles across All ONAP On-Boarded Applications Change-Id: Icfc1bbfddaf2c7c7176b4cf7bb7017d853c63100 Signed-off-by: Christopher Lott (cl778h) --- ecomp-sdk/epsdk-analytics/README.md | 2 +- ecomp-sdk/epsdk-analytics/pom.xml | 2 +- .../portalsdk/analytics/system/Globals.java | 8 - .../portalsdk/analytics/util/AppConstants.java | 13 +- ecomp-sdk/epsdk-app-common/pom.xml | 4 +- .../controller/core/BootstrapSampleController.java | 43 + .../controller/core/PostSearchController.java | 2 +- .../controller/core/ProfileController.java | 18 +- .../portalapp/controller/core/RoleController.java | 56 +- .../core/RoleFunctionListController.java | 34 +- .../controller/core/RoleListController.java | 30 +- .../controller/core/SingleSignOnController.java | 9 +- .../controller/core/UserProfileController.java | 2 +- .../service/OnBoardingApiServiceImpl.java | 6 +- .../portalapp/service/ProfileServiceTest.java | 2 +- ecomp-sdk/epsdk-app-os/pom.xml | 4 +- .../ds2/css/digital-ng-library/ecomp-ionicons.css | 75 +- ecomp-sdk/epsdk-app-overlay/README.md | 1 + ecomp-sdk/epsdk-app-overlay/pom.xml | 2 +- .../src/main/webapp/WEB-INF/conf/raptor.properties | 3 - .../webapp/WEB-INF/fusion/defs/definitions.xml | 3 + .../webapp/WEB-INF/fusion/raptor/wizard_chart.jsp | 1335 ---- .../bootstrap-3.3.7/css/bootstrap-theme.css | 587 ++ .../bootstrap-3.3.7/css/bootstrap-theme.css.map | 1 + .../bootstrap-3.3.7/css/bootstrap-theme.min.css | 6 + .../css/bootstrap-theme.min.css.map | 1 + .../external/bootstrap-3.3.7/css/bootstrap.css | 6757 ++++++++++++++++++++ .../external/bootstrap-3.3.7/css/bootstrap.css.map | 1 + .../external/bootstrap-3.3.7/css/bootstrap.min.css | 6 + .../bootstrap-3.3.7/css/bootstrap.min.css.map | 1 + .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 20127 bytes .../fonts/glyphicons-halflings-regular.svg | 288 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 45404 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 23424 bytes .../fonts/glyphicons-halflings-regular.woff2 | Bin 0 -> 18028 bytes .../external/bootstrap-3.3.7/js/bootstrap.js | 2377 +++++++ .../external/bootstrap-3.3.7/js/bootstrap.min.js | 7 + .../app/fusion/external/bootstrap-3.3.7/js/npm.js | 13 + .../ds2-bootstrap/b2b-bootstrap-common.css | 34 + .../scripts/DS2-controllers/admin-controller.js | 85 +- .../DS2-controllers/bootstrap-sample-controller.js | 5 + .../DS2-controllers/bootstrap-sample-route.js | 7 + .../fusion/scripts/DS2-services/adminService.js | 4 +- .../DS2-view-models/bootstrap-sample-content.html | 146 + .../DS2-view-models/bootstrap-sample-page.html | 146 + .../ds2-admin/modals/role-child-add-confirm.html | 12 +- .../modals/role-functions-child-roles-modal.html | 11 +- .../scripts/DS2-view-models/ds2-admin/role.html | 7 +- .../report-wizard-report-name-validation.html | 20 + .../ds2-reports/wz_steps/json/step1.json | 2 +- ecomp-sdk/epsdk-core/pom.xml | 2 +- .../portalsdk/core/auth/LoginStrategy.java | 11 +- .../openecomp/portalsdk/core/conf/AppConfig.java | 9 +- .../org/openecomp/portalsdk/core/domain/Role.java | 2 +- .../portalsdk/core/domain/RoleFunction.java | 4 +- .../core/interceptor/ResourceInterceptor.java | 7 +- .../core/service/AccessConfiguration.java | 132 + .../core/service/CentralAccessCondition.java | 30 + .../core/service/LocalAccessCondition.java | 19 + .../portalsdk/core/service/LoginService.java | 18 + .../core/service/LoginServiceCentralizedImpl.java | 221 + .../portalsdk/core/service/LoginServiceImpl.java | 9 +- .../portalsdk/core/service/ProfileService.java | 30 +- .../service/ProfileServiceCentralizedImpl.java | 73 + .../portalsdk/core/service/ProfileServiceImpl.java | 3 - .../core/service/RestApiRequestBuilder.java | 136 + .../portalsdk/core/service/RoleService.java | 101 +- .../core/service/RoleServiceCentralizedAccess.java | 169 + .../portalsdk/core/service/RoleServiceImpl.java | 30 +- .../core/service/UrlAccessCentalizedImpl.java | 77 + .../portalsdk/core/service/UrlAccessImpl.java | 48 + .../portalsdk/core/service/UrlAccessService.java | 15 + .../service/UserProfileServiceCentalizedImpl.java | 137 + .../core/service/UserProfileServiceImpl.java | 4 +- .../portalsdk/core/util/SystemProperties.java | 2 + .../portalsdk/core/web/support/UserUtils.java | 73 +- ecomp-sdk/epsdk-fw/pom.xml | 2 +- .../onboarding/crossapi/IPortalRestAPIService.java | 4 +- .../onboarding/crossapi/PortalRestAPIProxy.java | 13 +- .../core/onboarding/rest/FavoritesClient.java | 2 +- .../core/onboarding/rest/FunctionalMenuClient.java | 2 +- .../core/onboarding/rest/RestWebServiceClient.java | 174 +- .../core/onboarding/util/PortalApiConstants.java | 2 + ecomp-sdk/epsdk-workflow/pom.xml | 2 +- ecomp-sdk/pom.xml | 2 +- 85 files changed, 12098 insertions(+), 1645 deletions(-) create mode 100644 ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/BootstrapSampleController.java delete mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap-theme.css create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap-theme.css.map create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap-theme.min.css create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap-theme.min.css.map create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap.css create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap.css.map create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap.min.css create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/css/bootstrap.min.css.map create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/fonts/glyphicons-halflings-regular.eot create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/fonts/glyphicons-halflings-regular.svg create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/fonts/glyphicons-halflings-regular.ttf create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/fonts/glyphicons-halflings-regular.woff create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/fonts/glyphicons-halflings-regular.woff2 create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/js/bootstrap.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/js/bootstrap.min.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/bootstrap-3.3.7/js/npm.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/external/ds2-bootstrap/b2b-bootstrap-common.css create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/bootstrap-sample-controller.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/bootstrap-sample-route.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/bootstrap-sample-content.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/bootstrap-sample-page.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-report-name-validation.html create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java diff --git a/ecomp-sdk/epsdk-analytics/README.md b/ecomp-sdk/epsdk-analytics/README.md index 5fd6d23d..89094655 100644 --- a/ecomp-sdk/epsdk-analytics/README.md +++ b/ecomp-sdk/epsdk-analytics/README.md @@ -11,6 +11,6 @@ features including charts, maps and reports ("Raptor"). Version 1.1.0 - [Portal-7] Improvements added as part of the rebasing process - +- [PORTAL-17] Remove jfree related items Version 1.0.0 - Initial release diff --git a/ecomp-sdk/epsdk-analytics/pom.xml b/ecomp-sdk/epsdk-analytics/pom.xml index 057e4a08..4f612f90 100644 --- a/ecomp-sdk/epsdk-analytics/pom.xml +++ b/ecomp-sdk/epsdk-analytics/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/Globals.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/Globals.java index 77487dfa..008789fc 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/Globals.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/Globals.java @@ -111,8 +111,6 @@ public class Globals extends org.openecomp.portalsdk.analytics.RaptorObject { private static String sheet_name = "Raptor Reports"; - private static String jFreeVersion = AppConstants.JFV_0911; - private static boolean allowSQLBasedReports = true; // whether to allow // SQL-based report // definition (security @@ -478,8 +476,6 @@ public class Globals extends org.openecomp.portalsdk.analytics.RaptorObject { systemName = nvls(raptorProperties.getProperty("system_name"), "MSA Databank"); baseTitle = nvls(raptorProperties.getProperty("base_title"), "ANALYSIS"); - jFreeVersion = nvls(raptorProperties.getProperty("jfree_version"), - AppConstants.JFV_0911); allowSQLBasedReports = nvls( raptorProperties.getProperty("allow_sql_based_reports"), "yes") @@ -658,10 +654,6 @@ public class Globals extends org.openecomp.portalsdk.analytics.RaptorObject { return baseTitle; } - public static String getJFreeVersion() { - return jFreeVersion; - } - public static String getSystemName() { return systemName; } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java index c7a8d76f..f37d6fb7 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java @@ -390,13 +390,9 @@ public class AppConstants { public final static String GT_FLEX_TIME_CHARTS = "FlexTimeChart"; // Non-standard chart types - public final static String GT_MTD_BAR = "MTDBarChart"; - - // JFree latest version only chart type - public final static String GT_METER = "MeterChart"; - + public final static String GT_STACK_BAR = "StackedBarChart"; - + public static Color GREEN_COLOR = new Color(0, 128, 0); // chart filter @@ -583,11 +579,6 @@ public class AppConstants { public static final String OJ_JOINED = "JOINED"; // cur_table = // join_table (+) - // JFree versions - public static final String JFV_0911 = "0.9.11"; - - public static final String JFV_LATEST = "latest"; - // List of Available Total Functions public static final String TOTAL_SUM_ID = "SUM("; diff --git a/ecomp-sdk/epsdk-app-common/pom.xml b/ecomp-sdk/epsdk-app-common/pom.xml index b4ad2d75..f315974a 100644 --- a/ecomp-sdk/epsdk-app-common/pom.xml +++ b/ecomp-sdk/epsdk-app-common/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT @@ -18,7 +18,7 @@ UTF-8 - 1.1.0-SNAPSHOT + 1.3.0-SNAPSHOT 4.2.0.RELEASE 4.3.11.Final diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/BootstrapSampleController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/BootstrapSampleController.java new file mode 100644 index 00000000..794af760 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/BootstrapSampleController.java @@ -0,0 +1,43 @@ +/*- + * ================================================================================ + * ECOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller.core; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for welcome view. The view is restricted to authenticated users. + * The view name defaults to the request name with no suffix, "bootstrap_sample", which + * resolves to page welcome.jsp. + */ +@Controller +@RequestMapping("/") +public class BootstrapSampleController extends RestrictedBaseController { + @RequestMapping(value = { "/bootstrap_sample" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/PostSearchController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/PostSearchController.java index 2da1e6a6..39fae4f5 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/PostSearchController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/PostSearchController.java @@ -111,7 +111,7 @@ public class PostSearchController extends RestrictedBaseController { } @SuppressWarnings({ "unchecked", "rawtypes" }) - private HashMap getExistingUsers() { + private HashMap getExistingUsers() throws Exception { HashMap existingUsers = new HashMap(); // get the list of user ids in the system diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/ProfileController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/ProfileController.java index a774274c..a40b20ac 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/ProfileController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/ProfileController.java @@ -64,9 +64,10 @@ public class ProfileController extends RestrictedBaseController { private String viewName; @RequestMapping(value = { "/profile" }, method = RequestMethod.GET) - public ModelAndView profile(HttpServletRequest request) { + public ModelAndView profile(HttpServletRequest request, HttpServletResponse response) { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); User profile = null; Long profileId = null; @@ -83,7 +84,7 @@ public class ProfileController extends RestrictedBaseController { model.put("stateList", mapper.writeValueAsString(getStates())); model.put("countries", mapper.writeValueAsString(getCountries())); model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); model.put("profile", mapper.writeValueAsString(profile)); model.put("profileId", mapper.writeValueAsString(profileId)); } catch (Exception e) { @@ -99,6 +100,7 @@ public class ProfileController extends RestrictedBaseController { User profile = null; Long profileId = null; + User user = UserUtils.getUserSession(request); profile = UserUtils.getUserSession(request); profileId = profile.getId(); @@ -108,7 +110,7 @@ public class ProfileController extends RestrictedBaseController { model.put("stateList", mapper.writeValueAsString(getStates())); model.put("countries", mapper.writeValueAsString(getCountries())); model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); model.put("profile", mapper.writeValueAsString(profile)); model.put("profileId", mapper.writeValueAsString(profileId)); } catch (Exception e) { @@ -121,6 +123,7 @@ public class ProfileController extends RestrictedBaseController { public void getSelfProfile(HttpServletRequest request, HttpServletResponse response) { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); User profile = null; Long profileId = null; @@ -133,7 +136,7 @@ public class ProfileController extends RestrictedBaseController { model.put("stateList", mapper.writeValueAsString(getStates())); model.put("countries", mapper.writeValueAsString(getCountries())); model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); model.put("profile", mapper.writeValueAsString(profile)); model.put("profileId", mapper.writeValueAsString(profileId)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); @@ -148,6 +151,7 @@ public class ProfileController extends RestrictedBaseController { @RequestMapping(value = { "/get_profile" }, method = RequestMethod.GET) public void GetUser(HttpServletRequest request, HttpServletResponse response) { Map model = new HashMap(); + User user = UserUtils.getUserSession(request); ObjectMapper mapper = new ObjectMapper(); try { User profile = null; @@ -162,7 +166,7 @@ public class ProfileController extends RestrictedBaseController { model.put("stateList", mapper.writeValueAsString(getStates())); model.put("countries", mapper.writeValueAsString(getCountries())); model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); model.put("profile", mapper.writeValueAsString(profile)); model.put("profileId", mapper.writeValueAsString(profileId)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); @@ -345,8 +349,8 @@ public class ProfileController extends RestrictedBaseController { } @SuppressWarnings("rawtypes") - public List getAvailableRoles() { - return roleService.getAvailableRoles(); + public List getAvailableRoles(String requestedLoginId) throws Exception { + return roleService.getAvailableRoles(requestedLoginId); } } \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleController.java index ca902c49..0fc4edc4 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleController.java @@ -32,11 +32,13 @@ import org.json.JSONObject; import org.openecomp.portalsdk.core.controller.RestrictedBaseController; import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.logging.aspect.EELFLoggerAdvice; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.service.RoleService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -53,23 +55,26 @@ import com.fasterxml.jackson.databind.type.TypeFactory; @Controller @RequestMapping("/") public class RoleController extends RestrictedBaseController { - private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleController.class); @Autowired RoleService roleService; private String viewName; + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleController.class); + @RequestMapping(value = { "/role" }, method = RequestMethod.GET) - public ModelAndView role(HttpServletRequest request) { + public ModelAndView role(HttpServletRequest request) throws Exception { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + - Role role = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role role = roleService.getRole(user.getOrgUserId(),new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); logger.info("role_id" + role.getId()); try { - model.put("availableRoleFunctions", mapper.writeValueAsString(roleService.getRoleFunctions())); - model.put("availableRoles", mapper.writeValueAsString(roleService.getAvailableChildRoles(role.getId()))); + model.put("availableRoleFunctions", mapper.writeValueAsString(roleService.getRoleFunctions(user.getOrgUserId()))); + model.put("availableRoles", mapper.writeValueAsString(roleService.getAvailableChildRoles(user.getOrgUserId(),role.getId()))); model.put("role", mapper.writeValueAsString(role)); } catch (Exception e) { logger.error("role: failed", e); @@ -79,15 +84,16 @@ public class RoleController extends RestrictedBaseController { } @RequestMapping(value = { "/get_role" }, method = RequestMethod.GET) - public void getRole(HttpServletRequest request, HttpServletResponse response) { + public void getRole(HttpServletRequest request, HttpServletResponse response) throws Exception { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); - Role role = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role role = roleService.getRole(user.getOrgUserId(),new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); logger.info(EELFLoggerDelegate.applicationLogger, "role_id" + role.getId()); try { - model.put("availableRoleFunctions", mapper.writeValueAsString(roleService.getRoleFunctions())); - model.put("availableRoles", mapper.writeValueAsString(roleService.getAvailableChildRoles(role.getId()))); + model.put("availableRoleFunctions", mapper.writeValueAsString(roleService.getRoleFunctions(user.getOrgUserId()))); + model.put("availableRoles", mapper.writeValueAsString(roleService.getAvailableChildRoles(user.getOrgUserId(),role.getId()))); model.put("role", mapper.writeValueAsString(role)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); @@ -111,6 +117,7 @@ public class RoleController extends RestrictedBaseController { @RequestMapping(value = { "/role/saveRole" }, method = RequestMethod.POST) public ModelAndView saveRole(HttpServletRequest request, HttpServletResponse response) throws IOException { JSONObject j = null; + User user = UserUtils.getUserSession(request); logger.debug(EELFLoggerDelegate.debugLogger, "RoleController.save"); try { ObjectMapper mapper = new ObjectMapper(); @@ -127,14 +134,14 @@ public class RoleController extends RestrictedBaseController { Role domainRole = null; if (role.getId() != null) { doAuditLog("saveRole: updating existing role {}", role.getId()); - domainRole = roleService.getRole(role.getId()); + domainRole = roleService.getRole(user.getOrgUserId(),role.getId()); domainRole.setName(role.getName()); domainRole.setPriority(role.getPriority()); } else { doAuditLog("saveRole: creating new role", role.getName()); // check for existing role of same name - List roles = roleService.getAvailableRoles(); + List roles = roleService.getAvailableRoles(user.getOrgUserId()); for (Role existRole : roles) if (existRole.getName().equalsIgnoreCase(role.getName())) throw new Exception("role already exists: " + existRole.getName()); @@ -154,7 +161,7 @@ public class RoleController extends RestrictedBaseController { } } - roleService.saveRole(domainRole); + roleService.saveRole(user.getOrgUserId(),domainRole); String responseString = mapper.writeValueAsString(domainRole); j = new JSONObject("{role: " + responseString + "}"); @@ -173,7 +180,7 @@ public class RoleController extends RestrictedBaseController { @RequestMapping(value = { "/role/removeRoleFunction" }, method = RequestMethod.POST) public ModelAndView removeRoleFunction(HttpServletRequest request, HttpServletResponse response) throws Exception { - + User user = UserUtils.getUserSession(request); logger.info(EELFLoggerDelegate.applicationLogger, "RoleController.removeRoleFunction"); try { @@ -182,13 +189,13 @@ public class RoleController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); RoleFunction roleFunction = mapper.readValue(root.get("roleFunction").toString(), RoleFunction.class); - Role domainRole = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role domainRole = roleService.getRole(user.getOrgUserId(),new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); doAuditLog("Remove role function {} from role {}", roleFunction.getCode(), ServletRequestUtils.getIntParameter(request, "role_id", 0)); domainRole.removeRoleFunction(roleFunction.getCode()); - roleService.saveRole(domainRole); + roleService.saveRole(user.getOrgUserId(),domainRole); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); @@ -209,7 +216,7 @@ public class RoleController extends RestrictedBaseController { @RequestMapping(value = { "/role/addRoleFunction" }, method = RequestMethod.POST) public ModelAndView addRoleFunction(HttpServletRequest request, HttpServletResponse response) throws Exception { - + User user = UserUtils.getUserSession(request); logger.info(EELFLoggerDelegate.applicationLogger, "RoleController.removeRoleFunction"); try { @@ -218,11 +225,11 @@ public class RoleController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); RoleFunction roleFunction = mapper.readValue(root.get("roleFunction").toString(), RoleFunction.class); - Role domainRole = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role domainRole = roleService.getRole(user.getOrgUserId(),new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); domainRole.addRoleFunction(roleFunction); - roleService.saveRole(domainRole); + roleService.saveRole(user.getOrgUserId(),domainRole); doAuditLog("Add role function {} to role {}", roleFunction.getCode(), ServletRequestUtils.getIntParameter(request, "role_id", 0)); @@ -245,7 +252,7 @@ public class RoleController extends RestrictedBaseController { @RequestMapping(value = { "/role/removeChildRole" }, method = RequestMethod.POST) public ModelAndView removeChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception { - + User user = UserUtils.getUserSession(request); logger.info(EELFLoggerDelegate.applicationLogger, "RoleController.removeChileRole"); try { ObjectMapper mapper = new ObjectMapper(); @@ -253,13 +260,13 @@ public class RoleController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); Role childRole = mapper.readValue(root.get("childRole").toString(), Role.class); - Role domainRole = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role domainRole = roleService.getRole(user.getOrgUserId(),new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); domainRole.removeChildRole(childRole.getId()); doAuditLog("remove child role {} from role {}", childRole.getId(), ServletRequestUtils.getIntParameter(request, "role_id", 0)); - roleService.saveRole(domainRole); + roleService.saveRole(user.getOrgUserId(),domainRole); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); @@ -280,7 +287,7 @@ public class RoleController extends RestrictedBaseController { @RequestMapping(value = { "/role/addChildRole" }, method = RequestMethod.POST) public ModelAndView addChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception { - + User user = UserUtils.getUserSession(request); logger.info(EELFLoggerDelegate.applicationLogger, "RoleController.addChileRole"); try { @@ -288,12 +295,13 @@ public class RoleController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); Role childRole = mapper.readValue(root.get("childRole").toString(), Role.class); + long role_id = new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)); - Role domainRole = roleService.getRole(new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0))); + Role domainRole = roleService.getRole(user.getOrgUserId(),role_id ); domainRole.addChildRole(childRole); - roleService.saveRole(domainRole); + roleService.saveRole(user.getOrgUserId(),domainRole); doAuditLog("Add child role {} to role {}", childRole.getId(), ServletRequestUtils.getIntParameter(request, "role_id", 0)); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleFunctionListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleFunctionListController.java index 13b3a7c8..0014d0a5 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleFunctionListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleFunctionListController.java @@ -29,9 +29,11 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.openecomp.portalsdk.core.controller.RestrictedBaseController; import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.service.RoleService; import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -44,6 +46,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller @RequestMapping("/") public class RoleFunctionListController extends RestrictedBaseController { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleFunctionListController.class); @Autowired @@ -54,10 +58,12 @@ public class RoleFunctionListController extends RestrictedBaseController { @RequestMapping(value = {"/role_function_list" }, method = RequestMethod.GET) public ModelAndView welcome(HttpServletRequest request) { Map model = new HashMap(); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + try { - model.put("availableRoleFunctions", mapper.writeValueAsString(service.getRoleFunctions())); + model.put("availableRoleFunctions", mapper.writeValueAsString(service.getRoleFunctions(user.getOrgUserId()))); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "welcome failed", e); } @@ -69,9 +75,11 @@ public class RoleFunctionListController extends RestrictedBaseController { public void getRoleFunctionList(HttpServletRequest request,HttpServletResponse response) { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + try { - model.put("availableRoleFunctions", mapper.writeValueAsString(service.getRoleFunctions())); + model.put("availableRoleFunctions", mapper.writeValueAsString(service.getRoleFunctions(user.getOrgUserId()))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -85,16 +93,18 @@ public class RoleFunctionListController extends RestrictedBaseController { public void saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception { ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + String restCallStatus = ""; try { String data = roleFunc; RoleFunction availableRoleFunction = mapper.readValue(data, RoleFunction.class); String code = availableRoleFunction.getCode(); - RoleFunction domainRoleFunction = service.getRoleFunction(code); + RoleFunction domainRoleFunction = service.getRoleFunction(user.getOrgUserId(),code); domainRoleFunction.setName(availableRoleFunction.getName()); domainRoleFunction.setCode(code); restCallStatus="success"; - service.saveRoleFunction(domainRoleFunction); + service.saveRoleFunction(user.getOrgUserId(),domainRoleFunction); } catch (Exception e) { restCallStatus="fail"; logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e); @@ -108,16 +118,18 @@ public class RoleFunctionListController extends RestrictedBaseController { public void addRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception { ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + String restCallStatus = ""; boolean canSave=true; try { String data = roleFunc; RoleFunction availableRoleFunction = mapper.readValue(data, RoleFunction.class); String code = availableRoleFunction.getCode(); - RoleFunction domainRoleFunction = service.getRoleFunction(code); + RoleFunction domainRoleFunction = service.getRoleFunction(user.getOrgUserId(),code); domainRoleFunction.setName(availableRoleFunction.getName()); domainRoleFunction.setCode(code); - List currentRoleFunction = service.getRoleFunctions(); + List currentRoleFunction = service.getRoleFunctions(user.getOrgUserId()); restCallStatus="success"; for(RoleFunction roleF:currentRoleFunction){ if(roleF.getCode().equals(code)){ @@ -127,7 +139,7 @@ public class RoleFunctionListController extends RestrictedBaseController { } } if(canSave) - service.saveRoleFunction(domainRoleFunction); + service.saveRoleFunction(user.getOrgUserId(),domainRoleFunction); } catch (Exception e) { restCallStatus="fail"; logger.error(EELFLoggerDelegate.errorLogger, "addRoleFunction failed", e); @@ -141,15 +153,17 @@ public class RoleFunctionListController extends RestrictedBaseController { public void removeRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception { ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + String restCallStatus = ""; try { String data = roleFunc; RoleFunction availableRoleFunction = mapper.readValue(data, RoleFunction.class); - RoleFunction domainRoleFunction = service.getRoleFunction(availableRoleFunction.getCode()); + RoleFunction domainRoleFunction = service.getRoleFunction(user.getOrgUserId(),availableRoleFunction.getCode()); - service.deleteRoleFunction(domainRoleFunction); + service.deleteRoleFunction(user.getOrgUserId(),domainRoleFunction); logger.info(EELFLoggerDelegate.auditLogger, "Remove role function " + domainRoleFunction.getName()); restCallStatus="success"; } catch (Exception e) { diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleListController.java index be08d4e9..9ccff764 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/RoleListController.java @@ -29,9 +29,11 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.openecomp.portalsdk.core.controller.RestrictedBaseController; import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.service.RoleService; import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -46,6 +48,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @RequestMapping("/") public class RoleListController extends RestrictedBaseController { + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleListController.class); @Autowired RoleService service; @@ -56,9 +59,11 @@ public class RoleListController extends RestrictedBaseController { public ModelAndView getRoleList(HttpServletRequest request) { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + try { - model.put("availableRoles", mapper.writeValueAsString(service.getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(service.getAvailableRoles(user.getOrgUserId()))); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getRoleList failed", e); } @@ -69,10 +74,12 @@ public class RoleListController extends RestrictedBaseController { @RequestMapping(value = {"/get_roles" }, method = RequestMethod.GET) public void getRoles(HttpServletRequest request, HttpServletResponse response) { Map model = new HashMap(); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); + User user = UserUtils.getUserSession(request); + try { - model.put("availableRoles", mapper.writeValueAsString(service.getAvailableRoles())); + model.put("availableRoles", mapper.writeValueAsString(service.getAvailableRoles(user.getOrgUserId()))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -85,6 +92,8 @@ public class RoleListController extends RestrictedBaseController { @RequestMapping(value = {"/role_list/toggleRole" }, method = RequestMethod.POST) public ModelAndView toggleRole(HttpServletRequest request, HttpServletResponse response) throws Exception { + User user = UserUtils.getUserSession(request); + try { ObjectMapper mapper = new ObjectMapper(); @@ -92,12 +101,12 @@ public class RoleListController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); Role role = mapper.readValue(root.get("role").toString(), Role.class); - Role domainRole = service.getRole(role.getId()); + Role domainRole = service.getRole(user.getOrgUserId(),role.getId()); //role. toggle active ind boolean active = domainRole.getActive(); domainRole.setActive(!active); - service.saveRole(domainRole); + service.saveRole(user.getOrgUserId(),domainRole); logger.info(EELFLoggerDelegate.auditLogger, "Toggle active status for role " + domainRole.getId()); response.setCharacterEncoding("UTF-8"); @@ -105,7 +114,7 @@ public class RoleListController extends RestrictedBaseController { request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - String responseString = mapper.writeValueAsString(service.getAvailableRoles()); + String responseString = mapper.writeValueAsString(service.getAvailableRoles(user.getOrgUserId())); JSONObject j = new JSONObject("{availableRoles: "+responseString+"}"); out.write(j.toString()); @@ -125,6 +134,7 @@ public class RoleListController extends RestrictedBaseController { @RequestMapping(value = {"/role_list/removeRole" }, method = RequestMethod.POST) public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws Exception { + User user = UserUtils.getUserSession(request); try { @@ -133,10 +143,10 @@ public class RoleListController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); Role role = mapper.readValue(root.get("role").toString(), Role.class); - Role domainRole = service.getRole(role.getId()); + Role domainRole = service.getRole(user.getOrgUserId(),role.getId()); - service.deleteDependcyRoleRecord(role.getId()); - service.deleteRole(domainRole); + service.deleteDependcyRoleRecord(user.getOrgUserId(),role.getId()); + service.deleteRole(user.getOrgUserId(),domainRole); logger.info(EELFLoggerDelegate.auditLogger, "Remove role " + domainRole.getId()); response.setCharacterEncoding("UTF-8"); @@ -145,7 +155,7 @@ public class RoleListController extends RestrictedBaseController { PrintWriter out = response.getWriter(); - String responseString = mapper.writeValueAsString(service.getAvailableRoles()); + String responseString = mapper.writeValueAsString(service.getAvailableRoles(user.getOrgUserId())); JSONObject j = new JSONObject("{availableRoles: "+responseString+"}"); out.write(j.toString()); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/SingleSignOnController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/SingleSignOnController.java index 9ffa1d1d..64ff160e 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/SingleSignOnController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/SingleSignOnController.java @@ -22,6 +22,7 @@ package org.openecomp.portalapp.controller.core; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.http.Cookie; @@ -31,6 +32,7 @@ import javax.servlet.http.HttpSession; import org.openecomp.portalsdk.core.auth.LoginStrategy; import org.openecomp.portalsdk.core.command.LoginBean; import org.openecomp.portalsdk.core.controller.UnRestrictedBaseController; +import org.openecomp.portalsdk.core.domain.RoleFunction; import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.menu.MenuProperties; @@ -38,6 +40,7 @@ import org.openecomp.portalsdk.core.onboarding.listener.PortalTimeoutHandler; import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; import org.openecomp.portalsdk.core.service.LoginService; +import org.openecomp.portalsdk.core.service.RoleService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.AppUtils; import org.openecomp.portalsdk.core.web.support.UserUtils; @@ -70,6 +73,9 @@ public class SingleSignOnController extends UnRestrictedBaseController { public void setWelcomeView(String welcomeView) { this.welcomeView = welcomeView; } + + @Autowired + RoleService roleService; /** * Handles requests directed to the single sign-on page by the session @@ -102,6 +108,7 @@ public class SingleSignOnController extends UnRestrictedBaseController { commandBean = getLoginService().findUser(commandBean, (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), additionalParamsMap); + List roleFunctionList= roleService.getRoleFunctions(user.getLoginId()); if (commandBean.getUser() == null) { String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() @@ -123,7 +130,7 @@ public class SingleSignOnController extends UnRestrictedBaseController { loginMethod = SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_WEB_JUNCTION); } UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), - commandBean.getBusinessDirectMenu(), loginMethod); + commandBean.getBusinessDirectMenu(), loginMethod, roleFunctionList); initateSessionMgtHandler(request); logger.debug(EELFLoggerDelegate.debugLogger, "singleSignOnLogin: create new user session for expired user {}; user {} exists in the system", diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/UserProfileController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/UserProfileController.java index cee60e48..cb67c93d 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/UserProfileController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/controller/core/UserProfileController.java @@ -52,7 +52,7 @@ public class UserProfileController extends RestrictedBaseController { ProfileService service; @RequestMapping(value = { "/user_profile" }, method = RequestMethod.GET) - public ModelAndView userProfile(HttpServletRequest request) { + public ModelAndView userProfile(HttpServletRequest request) throws Exception { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); List profileList = service.findAll(); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImpl.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImpl.java index cb822494..7303cfc4 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImpl.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImpl.java @@ -222,9 +222,9 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { } @Override - public List getAvailableRoles() throws PortalAPIException { + public List getAvailableRoles(String requestedLoginId) throws PortalAPIException { try { - List roles = roleService.getActiveRoles(); + List roles = roleService.getActiveRoles(requestedLoginId); List ecompRoles = new ArrayList(); for (Role role : roles) ecompRoles.add(UserUtils.convertToEcompRole(role)); @@ -251,7 +251,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService { */ SortedSet roles = new TreeSet(); for (EcompRole role : rolesJson) { - roles.add(roleService.getRole(role.getId())); + roles.add(roleService.getRole(loginId,role.getId())); } // Replace existing roles with new ones replaceExistingRoles(roles, user); diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/openecomp/portalapp/service/ProfileServiceTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/openecomp/portalapp/service/ProfileServiceTest.java index ea78a779..2b8ca99d 100644 --- a/ecomp-sdk/epsdk-app-common/src/test/java/org/openecomp/portalapp/service/ProfileServiceTest.java +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/openecomp/portalapp/service/ProfileServiceTest.java @@ -23,7 +23,7 @@ public class ProfileServiceTest extends MockApplicationContextTestSuite { UserProfileService userProfileService; @Test - public void testFindAll() { + public void testFindAll() throws Exception{ List profiles = service.findAll(); Assert.assertTrue(profiles.size() > 0); diff --git a/ecomp-sdk/epsdk-app-os/pom.xml b/ecomp-sdk/epsdk-app-os/pom.xml index 7d07e392..868fff4d 100644 --- a/ecomp-sdk/epsdk-app-os/pom.xml +++ b/ecomp-sdk/epsdk-app-os/pom.xml @@ -6,14 +6,14 @@ This is NOT the Portal - but it is developed and supported by the Portal team. --> org.openecomp.ecompsdkos epsdk-app-os - 1.1.0 + 1.3.0-SNAPSHOT war ECOMP SDK Webapp for OpenSource ECOMP SDK Web Application for public release UTF-8 - 1.1.0 + 1.3.0-SNAPSHOT 4.2.0.RELEASE 4.3.11.Final diff --git a/ecomp-sdk/epsdk-app-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css b/ecomp-sdk/epsdk-app-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css index dacd5edf..bb691d6d 100644 --- a/ecomp-sdk/epsdk-app-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css +++ b/ecomp-sdk/epsdk-app-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css @@ -1,7 +1,74 @@ @charset "UTF-8"; @font-face { font-family: "Ionicons"; src: url("../fonts/ionicons.eot?v=2.0.0"); src: url("../fonts/ionicons.eot?v=2.0.0#iefix") format("embedded-opentype"), url("../fonts/ionicons.ttf?v=2.0.0") format("truetype"), url("../fonts/ionicons.woff?v=2.0.0") format("woff"), url("../fonts/ionicons.svg?v=2.0.0#Ionicons") format("svg"); font-weight: normal; font-style: normal; } -.ionicons,.icon-controls-upPRIMARY, .icon-arrows-download:before, .icon-securityalerts-alertL:before, .icon-controls-add-maximize:before, .icon-controls-add-maximize-circle:before, .icon-misc-time:before, .icoSecurityalerts:before,.icon-apps-marketplace:before ,.icon-content-grid:before, .icon-documents-archive:before, .icon-arrows-vertical-arrow-down:before,.icoArrows-download:before, .icoArrows-incoming-call:before, .icon-arrows-outgoing-call:before, .icon-arrows-upload:before, .icon-arrows-straight-arrow:before,.icoArrows-vertical-arrow:before, .icon-people-userbookmark:before, .icon-controls-check:before, .icon-chevron-down:before, .icon-controls-down:before, .icon-controls-left:before, .icon-controls-right:before, .icon-chevron-up:before, .icoDocuments-report:before, .icon-edit:before,.icon-misc-pen:before, .icon-controls-up:before, .icon-overview:before, .icon-settings:before,.icon-building-home:before,.icon-documents-book:before, .icoDocuments-book-outline:before, .icoDocuments-bookmarks:before, .icoDocuments-bookmarks-outline:before,.icon-add-widget:before , .icon-documents-copy:before,.icon-content-flag:before,.icon-primary-accordion-minus:before, .icon-misc-piechart:before,.icon-misc-piechart-outline:before,.icon-primary-accordion-plus:before,.icon-star:before,.icon-building-door:before,.icon-content-gridguide:before,.icon-user:before, .icon-people-oneperson:before, .icon-people-oneperson-add:before, .icon-people-oneperson-stalker:before, .icon-controls-pointer:before, .icon-arrows-replay-restart:before, .icon-content-star:before, .icon-misc-trash:before, .icon-arrows-upload:before { display: inline-block; font-family: "Ionicons"; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; text-rendering: auto; line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } +.ionicons, +.icon-controls-upPRIMARY, +.icon-arrows-download:before, +.icon-securityalerts-alertL:before, +.icon-controls-add-maximize:before, +.icon-controls-add-maximize-circle:before, +.icon-misc-time:before, +.icoSecurityalerts:before, +.icon-apps-marketplace:before, +.icon-content-grid:before, +.icon-documents-archive:before, +.icon-arrows-vertical-arrow-down:before, +.icoArrows-download:before, +.icoArrows-incoming-call:before, +.icon-arrows-outgoing-call:before, +.icon-arrows-upload:before, +.icon-arrows-straight-arrow:before, +.icoArrows-vertical-arrow:before, +.icon-people-userbookmark:before, +.icon-controls-check:before, +.icon-chevron-down:before, +.icon-controls-down:before, +.icon-controls-left:before, +.icon-controls-right:before, +.icon-chevron-up:before, +.icoDocuments-report:before, +.icon-edit:before, +.icon-controls-up:before, +.icon-overview:before, +.icon-settings:before, +.icon-building-home:before, +.icon-documents-book:before, +.icoDocuments-book-outline:before, +.icoDocuments-bookmarks:before, +.icoDocuments-bookmarks-outline:before, +.icon-add-widget:before, +.icon-documents-copy:before, +.icon-content-flag:before, +.icon-primary-accordion-minus:before, +.icon-misc-piechart:before, +.icon-misc-piechart-outline:before, +.icon-primary-accordion-plus:before, +.icon-star:before, +.icon-building-door:before, +.icon-content-gridguide:before, +.icon-user:before, +.icon-people-oneperson:before, +.icon-people-oneperson-add:before, +.icon-people-oneperson-stalker:before, +.icon-controls-pointer:before, +.icon-arrows-replay-restart:before, +.icon-content-star:before, +.icon-misc-trash:before, +.icon-misc-pen:before, +.ion-navicon:before, +.icon-arrows-upload:before { + display: inline-block; + font-family: "Ionicons"; + speak: none; + font-style: normal; + font-weight: normal; + font-variant: normal; + text-transform: none; + text-rendering: auto; + line-height: 1; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + } @@ -103,4 +170,8 @@ .icon-add-widget:before { content: "\f3f0"; } -.icon-controls-upPRIMARY:before { content: "\f3d8"; } \ No newline at end of file +.icon-controls-upPRIMARY:before { content: "\f3d8"; } + +.icon-misc-pen:before { content: "\f2bf"; } + +.ion-navicon:before { content: "\f20e"; } \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/README.md b/ecomp-sdk/epsdk-app-overlay/README.md index affe1b9c..dd8b1d42 100644 --- a/ecomp-sdk/epsdk-app-overlay/README.md +++ b/ecomp-sdk/epsdk-app-overlay/README.md @@ -20,6 +20,7 @@ AngularJS version 1.5.0. Version 1.1.0 [Portal-7] Improvements added as part of the rebasing process [Portal-10] Enhancing Drill Down Capabilities of EcompSDK Analytics +[PORTAL-17] Remove jfree related items Version 1.0.0 - Initial release diff --git a/ecomp-sdk/epsdk-app-overlay/pom.xml b/ecomp-sdk/epsdk-app-overlay/pom.xml index 8b3772a5..29d1cc5b 100644 --- a/ecomp-sdk/epsdk-app-overlay/pom.xml +++ b/ecomp-sdk/epsdk-app-overlay/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/conf/raptor.properties b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/conf/raptor.properties index d566f027..1491e4ad 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/conf/raptor.properties +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/conf/raptor.properties @@ -69,9 +69,6 @@ can_copy_on_read_only=yes ##C## Determines the no of decimals to be displayed in Totals column #max_decimals_on_totals=-1 => don't truncate, display all decimal digits max_decimals_on_totals=2 -##C## Determines which JFreeChart to use. -jfree_version=latest -#jfree_version=0.9.11 # Added this restriction so that heavily used system which contain # more than 1000 users can enable this feature not to display whole # users in the drop down menu diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/defs/definitions.xml b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/defs/definitions.xml index 2e9c8bf6..14a59ea5 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/defs/definitions.xml +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/defs/definitions.xml @@ -105,6 +105,9 @@ + + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp deleted file mode 100644 index 959adc23..00000000 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp +++ /dev/null @@ -1,1335 +0,0 @@ -<%-- - ================================================================================ - eCOMP Portal SDK - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ================================================================================ - --%> -<%-- - Name: wizard_chart.jsp - Use : This JSP is invoked when chart tab is selected. This is used for creating chart configuration for the report. - - Change Log - ========== - - 12-Aug-2009 : Version 8.5 (Sundar); -
    -
  • For Line Chart Category can be configured. For this UI is added.
  • -
  • Line Chart can be displayed as 3D or 2D.
  • -
- 29-Jun-2009 : Version 8.4 (Sundar); -
    -
  • For Bar Chart Last Series/Category can be configured as Line Chart or Bar Chart. For this UI is added.
  • -
  • UI options for compare to prev year chart has been added.
  • -
- - 23-Jun-2009 : Version 8.4 (Sundar); -
    -
  • Hiding/ Unhiding parameters based on chart type is checked throughly and missing elements were added.
  • -
  • Table width is made 100% for special input parameters
  • -
- - 22-Jun-2009 : Version 8.4 (Sundar); - -
    -
  • Calendar JS and CSS were added to this page as it is used in customizable input parameters for Time Difference Chart.
  • -
  • JS method and configurable input parameters were added for Multiple Pie Chart, Bar Chart 3D, Pareto, Time Difference Chart and Multiple - Time Series Chart.
  • -
---%> -<%@page import="org.openecomp.portalsdk.analytics.model.runtime.FormField"%> -<%@page import="org.openecomp.portalsdk.analytics.model.runtime.ReportFormFields"%> -<%@page import="org.openecomp.portalsdk.analytics.model.runtime.ReportRuntime"%> -<%@page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue"%> -<%@page import="org.openecomp.portalsdk.analytics.model.DataCache"%> -<%@page import="org.openecomp.portalsdk.analytics.model.ReportHandler"%> -<%@page import="java.util.Vector"%> -<%@ page import="java.util.List" %> -<%@ page import="java.util.ArrayList" %> -<%@ page import="java.util.Iterator" %> -<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> -<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> -<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> -<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> -<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> -<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> -<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.Reports"%> - -<% - ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); - WizardSequence ws = rdef.getWizardSequence(); - boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); - boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED) || rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN); - - String legendColId = null; - String valueColId = null; - - //String firstColId = null; - //String firstNumColId = null; - - List reportCols = rdef.getAllColumns(); - List chartValueCols = rdef.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); - - ArrayList unusedNumCols = new ArrayList(reportCols.size()); - int numColsCount = 0; - for(Iterator iter=reportCols.iterator(); iter.hasNext(); ) { - DataColumnType dct = (DataColumnType) iter.next(); - - if(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) - legendColId = dct.getColId(); - - if(isSQLBased||nvl(dct.getColType()).equals(AppConstants.CT_NUMBER)) { - numColsCount++; - if(nvl(dct.getColOnChart()).length()==0) //dct.getChartSeq()<0) - unusedNumCols.add(dct); - } // if - -/* if(dct.getChartSeq()>0) - valueColId = dct.getColId(); - - if(firstColId==null) - firstColId = dct.getColId(); - if(firstNumColId==null) - if(isSQLBased) - firstNumColId = dct.getColId(); - else - if(nvl(dct.getColType()).equals(AppConstants.CT_NUMBER)) - firstNumColId = dct.getColId();*/ - } // for - - String chartType = nvl(rdef.getChartType()); %> - - - - - - - - -
- - - - - - -<% if(numColsCount==0) { %> - - - - - - - -<% } else { %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<% if(chartValueCols.size()==0) { %> - - - - - -<% } else { - int count = 1; - String colIdx = ""; - for(Iterator iterV=chartValueCols.iterator(); iterV.hasNext(); count++) { - colIdx = ""; - DataColumnType dctV = (DataColumnType) iterV.next(); - colIdx = dctV.getColId(); - int colAxisIdx = 0; - boolean newChart = false; - try { - colAxisIdx = Integer.parseInt(dctV.getColOnChart()); - } catch(Exception e) {} - newChart = (dctV.isCreateInNewChart()!=null)?dctV.isCreateInNewChart().booleanValue():false; - %> - - - - - - - - -<% } // for - } // else (chartValueCols.size()==0) - if(unusedNumCols.size()>0) { %> - - - - - - -<% } // if(unusedNumCols.size()==0) - if(chartValueCols.size()>1 || rdef.hasSeriesColumn()) { %> - - - - - - - - -<% } // if(chartValueCols.size()>1) -%> - - - - - - - + - +
Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
No numeric columns found - chart not available
- - - - - - -
Chart Type: - - > -  Do NOT allow user to change chart type at runtime -
-
Chart Width (px): - " size="10" maxlength="4">
Chart Height (px): - " size="10" maxlength="4">
Domain Axis: -
Category: -
last Category display As Line Chart - - > -
last Category display As Bar Chart - - > -
Multi Series - 0? (AppUtils.getRequestNvlValue(request, "multiSeries").equals("Y")? " checked ":""): (rdef.isMultiSeries() ? " checked ":" checked ")) %>>Yes - 0? (AppUtils.getRequestNvlValue(request, "multiSeries").equals("N")? " checked ":""): (!rdef.isMultiSeries() ? " checked":"")) %>>No -
Range Axis: - - <% String sValue = ""; %> - -
Range Axis <%= count %>: - - <% if(count>1) { %> -   - - <% } %> -   - - <% - String chartGroupOrg = dctV.getChartGroup(); - String yAxisGroup = dctV.getYAxis(); - String chartGroup = (chartGroupOrg!=null && chartGroupOrg.length()>0 && chartGroupOrg.indexOf("|")!= -1)?chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|")):""; - String yAxis = (yAxisGroup!=null && yAxisGroup.length()>0 && yAxisGroup.indexOf("|")!= -1)?yAxisGroup.substring(0,yAxisGroup.lastIndexOf("|")):""; - %> -
- Chart Title:"/> - YAxis:"/> -
- -
- <% String sValue = nvl(dctV.getChartColor()); %> - - - <% if(count>1) { %> -
- > -  Create in New Chart -
- 0)?" checked":"" %>> -  Use secondary axis (Line chart only) - <% } %> -  
Add Values Column: - - - <% String sValue = ""; %> - - - -  Use secondary axis (Line chart only) -
Primary Axis Label: - -  (Multi-series Chart Only)
Secondary Axis Label: - -  (Multi-series Chart Only)
  - Note: Some chart types (like Pie) will only display Series 1 Values.
- - - - - - - - - - - - - - - - - - - Role
- + {{ roleFunction.name }}{{ role.name }}
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-admin/role.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-admin/role.html index 12d8df70..e2aa188a 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-admin/role.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-admin/role.html @@ -49,9 +49,10 @@
-
+ +
Manage Role Functions

diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-report-name-validation.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-report-name-validation.html new file mode 100644 index 00000000..50132ecf --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-report-name-validation.html @@ -0,0 +1,20 @@ +
+
+

Warning

+
+ +
+
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json index 091d47e5..66562d4b 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json @@ -15,7 +15,7 @@ { "input": "text", "name": "reportName", - "displayName": "Report Name:", + "displayName": "Report Name *:", "defaultValue": "" }, { diff --git a/ecomp-sdk/epsdk-core/pom.xml b/ecomp-sdk/epsdk-core/pom.xml index f37bdc85..9a88f73a 100644 --- a/ecomp-sdk/epsdk-core/pom.xml +++ b/ecomp-sdk/epsdk-core/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/auth/LoginStrategy.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/auth/LoginStrategy.java index 0378101a..673201fb 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/auth/LoginStrategy.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/auth/LoginStrategy.java @@ -20,6 +20,7 @@ package org.openecomp.portalsdk.core.auth; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.http.Cookie; @@ -27,10 +28,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.openecomp.portalsdk.core.command.LoginBean; +import org.openecomp.portalsdk.core.domain.RoleFunction; import org.openecomp.portalsdk.core.menu.MenuProperties; import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; import org.openecomp.portalsdk.core.onboarding.listener.PortalTimeoutHandler; import org.openecomp.portalsdk.core.service.LoginService; +import org.openecomp.portalsdk.core.service.RoleService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.AppUtils; import org.openecomp.portalsdk.core.web.support.UserUtils; @@ -50,6 +53,9 @@ public abstract class LoginStrategy { @Autowired private LoginService loginService; + + @Autowired + RoleService roleService; public abstract ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception; @@ -77,6 +83,9 @@ public abstract class LoginStrategy { **/ commandBean = loginService.findUser(commandBean, (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), additionalParamsMap); + List roleFunctionList= roleService.getRoleFunctions(loginId); + + if (commandBean.getUser() == null) { String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() @@ -92,7 +101,7 @@ public abstract class LoginStrategy { // store the currently logged in user's information in the session UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), commandBean.getBusinessDirectMenu(), - SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR)); + SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR), roleFunctionList); initateSessionMgtHandler(request); // user has been authenticated, now take them to the welcome page diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/conf/AppConfig.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/conf/AppConfig.java index 10d71872..fac79bc4 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/conf/AppConfig.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/conf/AppConfig.java @@ -33,13 +33,17 @@ import org.openecomp.portalsdk.core.menu.MenuBuilder; import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; import org.openecomp.portalsdk.core.service.DataAccessService; import org.openecomp.portalsdk.core.service.DataAccessServiceImpl; +import org.openecomp.portalsdk.core.service.LocalAccessCondition; +import org.openecomp.portalsdk.core.service.RestApiRequestBuilder; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.AppUtils; import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -135,14 +139,15 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, public MenuBuilder menuBuilder() { return new MenuBuilder(); } - + /** * Creates and returns a new instance of a {@link UserUtils} class. * * @return New instance of {@link UserUtils}. */ @Bean - public UserUtils userUtil() { + public UserUtils userUtil() + { return new UserUtils(); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/Role.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/Role.java index a56fe672..cc9f0f8a 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/Role.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/Role.java @@ -170,5 +170,5 @@ public class Role extends DomainVo { return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2); } - + } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/RoleFunction.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/RoleFunction.java index e6735763..9fee520f 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/RoleFunction.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/domain/RoleFunction.java @@ -66,6 +66,6 @@ public class RoleFunction extends DomainVo { private String code; private String name; - private String editUrl; - + private String editUrl; + } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/interceptor/ResourceInterceptor.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/interceptor/ResourceInterceptor.java index ec6e4b6c..5a631198 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/interceptor/ResourceInterceptor.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/interceptor/ResourceInterceptor.java @@ -38,9 +38,9 @@ import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; import org.openecomp.portalsdk.core.service.DataAccessService; import org.openecomp.portalsdk.core.service.LoginService; +import org.openecomp.portalsdk.core.service.UrlAccessService; import org.openecomp.portalsdk.core.service.WebServiceCallService; import org.openecomp.portalsdk.core.util.SystemProperties; -import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -59,6 +59,9 @@ public class ResourceInterceptor extends HandlerInterceptorAdapter { private AbstractCacheManager cacheManager; + @Autowired + UrlAccessService urlAccessService; + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @@ -87,7 +90,7 @@ public class ResourceInterceptor extends HandlerInterceptorAdapter { return false; } } - if (!UserUtils.isUrlAccessible(request, url)) { + if (!urlAccessService.isUrlAccessible(request, url)) { logger.error(EELFLoggerDelegate.errorLogger, "Error accesing URL. Un-authorized",AlarmSeverityEnum.MINOR); throw new UrlAccessRestrictedException(); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java new file mode 100644 index 00000000..ae6bd309 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java @@ -0,0 +1,132 @@ +package org.openecomp.portalsdk.core.service; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AccessConfiguration { + + + + /** + * + * @returns RoleServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public RoleService roleServiceImpl() { + return new RoleServiceImpl(); + } + + + /** + * + * @returns RoleServiceCentralizedAccess bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public RoleService roleServiceCentralizedAccess() { + return new RoleServiceCentralizedAccess(); + } + + + /** + * + * @returns LoginServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public LoginService loginServiceImpl() { + return new LoginServiceImpl(); + } + + + /** + * + * @returns LoginServiceCentralizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public LoginService loginServiceCEntralizedImpl() { + return new LoginServiceCentralizedImpl(); + } + + /** + * + * @returns UserProfileServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public UserProfileService userProfileServiceImpl() { + return new UserProfileServiceImpl(); + } + + + /** + * + * @returns returns UserProfileServiceCentalizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public UserProfileService userProfileServiceCentalizedImpl() { + return new UserProfileServiceCentalizedImpl(); + } + + + + /** + * + * @returns returns ProfileServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public ProfileService profileServiceImpl() { + return new ProfileServiceImpl(); + } + + + /** + * + * @returns returns ProfileServiceCentralizedImpl bean if CentralAccessCondition is true + */ + + @Bean + @Conditional(CentralAccessCondition.class) + public ProfileService profileServiceCentralizedImpl() { + return new ProfileServiceCentralizedImpl(); + } + + /** + * + * @returns returns UrlAccessCentalizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public UrlAccessService userUtilsCentalizedImpl() { + return new UrlAccessCentalizedImpl(); + } + + + /** + * + * @returns returns UrlAccessImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public UrlAccessService urlAccessImpl() { + return new UrlAccessImpl(); + } + + + /** + * + * @returns returns RestApiRequestBuilder bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public RestApiRequestBuilder restApiRequestBuilder() { + return new RestApiRequestBuilder(); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java new file mode 100644 index 00000000..9cefd5e1 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java @@ -0,0 +1,30 @@ +package org.openecomp.portalsdk.core.service; + +import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + + +public class CentralAccessCondition implements Condition { + + /** + * returns true if the application is centralized + */ + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + boolean isRemote = false; + + if(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) == null) + { + isRemote = false; + } + else if(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) != null && PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED).equals("remote")){ + isRemote = true; + } + + return isRemote; + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java new file mode 100644 index 00000000..68a9626a --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java @@ -0,0 +1,19 @@ +package org.openecomp.portalsdk.core.service; + +import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +public class LocalAccessCondition implements Condition{ + + /** + * returns true if the application is not centralized + */ + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + return PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) == null || (PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) != null && ! PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED).equals("remote")); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java index 4f004108..5baa86ef 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java @@ -27,10 +27,28 @@ import org.openecomp.portalsdk.core.command.*; public interface LoginService { + /** + * + * @param bean + * @param menuPropertiesFilename + * @param additionalParams + * @return returns login user bean + * @throws Exception + */ // validate user exists in the system @SuppressWarnings("rawtypes") LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams) throws Exception; + + /** + * + * @param bean + * @param menuPropertiesFilename + * @param additionalParams + * @param matchPassword + * @return returns login user bean + * @throws Exception + */ @SuppressWarnings("rawtypes") LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, boolean matchPassword) throws Exception; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java new file mode 100644 index 00000000..45eff80c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java @@ -0,0 +1,221 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.openecomp.portalsdk.core.command.LoginBean; +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.domain.UserApp; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.menu.MenuBuilder; +import org.openecomp.portalsdk.core.service.support.FusionService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class LoginServiceCentralizedImpl extends FusionService implements LoginService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginServiceCentralizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + private DataAccessService dataAccessService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @SuppressWarnings("unused") + private MenuBuilder menuBuilder; + + @Override + public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams) + throws Exception { + return findUser(bean, menuPropertiesFilename, additionalParams, true); + } + + @SuppressWarnings("rawtypes") + public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, + boolean matchPassword) throws Exception { + User user = null; + User userCopy = null; + + if (bean.getUserid() != null && bean.getUserid() != null) { + user = (User) findUser(bean); + } else { + if (matchPassword) + user = (User) findUser(bean.getLoginId(), bean.getLoginPwd()); + else + user = (User) findUserWithoutPwd(bean.getLoginId()); + } + + if (user != null) { + + if (AppUtils.isApplicationLocked() + && !UserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_APPLICATION_LOCKED); + } + + // raise an error if the user is inactive + if (!user.getActive()) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE); + } + + if (!userHasActiveRoles(user)) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE); + } + // only login the user if no errors have occurred + if (bean.getLoginErrorMessage() == null) { + + // this will be a snapshot of the user's information as + // retrieved from the database + userCopy = (User) user.clone(); + + User appuser = getUser(userCopy); + + appuser.setLastLoginDate(new Date()); + + // update the last logged in date for the user + // user.setLastLoginDate(new Date()); + getDataAccessService().saveDomainObject(appuser, additionalParams); + + // update the audit log of the user + // Check for the client device type and set log attributes + // appropriately + + // save the above changes to the User and their audit trail + + // create the application menu based on the user's privileges + + Set appMenu = getMenuBuilder().getMenu( + SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME), dataAccessService); + bean.setMenu(appMenu != null ? appMenu : new HashSet()); + System.out.println(appMenu); + Set businessDirectMenu = getMenuBuilder().getMenu( + SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME), + dataAccessService); + bean.setBusinessDirectMenu(businessDirectMenu != null ? businessDirectMenu : new HashSet()); + + bean.setUser(userCopy); + } + } + + return bean; + } + + private boolean userHasActiveRoles(User user) { + boolean hasActiveRole = false; + Iterator roles = user.getRoles().iterator(); + while (roles.hasNext()) { + Role role = (Role) roles.next(); + if (role.getActive()) { + hasActiveRole = true; + break; + } + } + return hasActiveRole; + } + + @SuppressWarnings("null") + public User findUser(LoginBean bean) throws Exception { + + User user = null; + + ObjectMapper mapper = new ObjectMapper(); + HashSet rolefun = null; + + String repsonse = restApiRequestBuilder.getViaREST("/getUser/" + bean.getUserid(), true, bean.getUserid()); + + user = mapper.readValue(repsonse, User.class); + + @SuppressWarnings("unchecked") + Set setAppsObj = user.getUserApps(); + + Iterator it = setAppsObj.iterator(); + while (it.hasNext()) { + Object next = it.next(); + + UserApp nextApp = mapper.convertValue(next, UserApp.class); + rolefun = new HashSet<>(); + Role role = nextApp.getRole(); + + Set roleFunctionList = role.getRoleFunctions(); + Set roleFunctionListNew = new HashSet<>(); + Iterator itetaror = roleFunctionList.iterator(); + while (itetaror.hasNext()) { + Object nextValue = itetaror.next(); + RoleFunction roleFunction = mapper.convertValue(nextValue, RoleFunction.class); + roleFunctionListNew.add(roleFunction); + } + + role.setRoleFunctions(roleFunctionListNew); + nextApp.setRole(role); + nextApp.getRole().getRoleFunctions(); + SortedSet UserAppSet = new TreeSet<>(); + UserAppSet.add(nextApp); + user.setUserApps(UserAppSet); + } + + return user; + } + + public User findUser(String loginId, String password) { + + List list = null; + + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(loginId).append("'").append(" and login_pwd = '").append(password) + .append("'"); + + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + } + + private User findUserWithoutPwd(String loginId) { + List list = null; + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(loginId).append("'"); + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + } + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + public MenuBuilder getMenuBuilder() { + return new MenuBuilder(); + } + + public void setMenuBuilder(MenuBuilder menuBuilder) { + this.menuBuilder = menuBuilder; + } + + public User getUser(User user) { + List list = null; + + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(user.getLoginId()).append("'"); + + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java index e0a4b7c6..a38a16ff 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java @@ -29,17 +29,14 @@ import java.util.Set; import org.openecomp.portalsdk.core.command.LoginBean; import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.domain.UserApp; import org.openecomp.portalsdk.core.menu.MenuBuilder; import org.openecomp.portalsdk.core.service.support.FusionService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.AppUtils; import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("loginService") @Transactional public class LoginServiceImpl extends FusionService implements LoginService { @@ -113,9 +110,6 @@ public class LoginServiceImpl extends FusionService implements LoginService { // save the above changes to the User and their audit trail - - - // create the application menu based on the user's privileges Set appMenu = getMenuBuilder().getMenu(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME),dataAccessService); @@ -133,7 +127,8 @@ public class LoginServiceImpl extends FusionService implements LoginService { private boolean userHasActiveRoles(User user) { boolean hasActiveRole = false; - Iterator roles = user.getRoles().iterator(); + @SuppressWarnings("rawtypes") + Iterator roles = user.getRoles().iterator(); while (roles.hasNext()) { Role role = (Role)roles.next(); if (role.getActive()) { diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java index 61bd3b6e..3eda4cfc 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java @@ -26,11 +26,35 @@ import org.openecomp.portalsdk.core.domain.User; public interface ProfileService { - List findAll(); - Profile getProfile(int id); + /** + * + * @return returns list of profiles + * @throws Exception + */ + List findAll() throws Exception; - User getUser(String id); + /** + * + * @param id + * @return returns profile of requested ID + * @throws Exception + */ + Profile getProfile(int id) throws Exception; + + /** + * + * @param id loginId + * @return returns User info of requested ID + * @throws Exception + */ + User getUser(String id) throws Exception; + + /** + * + * @param user + *saveUser method saves the user object + */ void saveUser(User user); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java new file mode 100644 index 00000000..c4da3338 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java @@ -0,0 +1,73 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.List; + +import org.openecomp.portalsdk.core.domain.Profile; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + +public class ProfileServiceCentralizedImpl implements ProfileService{ + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProfileServiceCentralizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + private DataAccessService dataAccessService; + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + @Autowired + RestApiRequestBuilder restApiRequestBuilder ; + + @Override + public List findAll() throws Exception{ + + List profileList =null; + ObjectMapper mapper = new ObjectMapper(); + + String user = restApiRequestBuilder.getViaREST("/findAllProfiles", true,null); + profileList = mapper.readValue(user, + TypeFactory.defaultInstance().constructCollectionType(List.class, Profile.class)); + return profileList; + } + + @Override + public Profile getProfile(int id) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + Profile user = null; + String responseString = restApiRequestBuilder.getViaREST("/getProfile/" + id, true,Integer.toString(id)); + user = mapper.readValue(responseString, Profile.class); + return user; + } + + @Override + public User getUser(String id) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + User user = new User(); + String responseString =restApiRequestBuilder.getViaREST("/getUser/" + id, true,id); + user = mapper.readValue(responseString, User.class); + + return user; + } + + @Override + public void saveUser(User user) { + try { + getDataAccessService().saveDomainObject(user, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveUser failed", e); + } + } +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java index 2d6fcfee..e0785567 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java @@ -24,12 +24,9 @@ import java.util.List; import org.openecomp.portalsdk.core.dao.ProfileDao; import org.openecomp.portalsdk.core.domain.Profile; import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.service.DataAccessService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("profileService") @Transactional public class ProfileServiceImpl implements ProfileService{ diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java new file mode 100644 index 00000000..6a2f7a47 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java @@ -0,0 +1,136 @@ +package org.openecomp.portalsdk.core.service; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; + +import org.openecomp.portalsdk.core.domain.App; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.rest.RestWebServiceClient; +import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; + +public class RestApiRequestBuilder { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleServiceCentralizedAccess.class); + + @Autowired + AppService appService; + + public static String content_type = "application/json"; + + public String getViaREST(String restEndPoint, boolean isBasicAuth,String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for GET" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + String response = null; + try { + response = RestWebServiceClient.getInstance().getPortalContent(restEndPoint, userId,appName, requestId, appUserName, + decryptedPwd, isBasicAuth); + } catch (Exception ex) { + response = "Failed to get roles " + ex.toString(); + } + logger.debug(EELFLoggerDelegate.debugLogger, "getRoles response: {}", response); + return response; + } + + public void postViaREST(String restEndPoint, boolean isBasicAuth, String content,String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for POST" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + + try { + RestWebServiceClient.getInstance().postPortalContent(restEndPoint, userId, appName, requestId, appUserName, + decryptedPwd, content_type, content, isBasicAuth); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.debugLogger, "POST response: {}", ex); + } + logger.debug(EELFLoggerDelegate.debugLogger, "POST response: {}"); + + } + + public void deleteViaRest(String restEndPoint, boolean isBasicAuth, String content, String filter , String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for DELETE" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + + try { + RestWebServiceClient.getInstance().deletePortalContent(restEndPoint, userId, appName, requestId, appUserName, + decryptedPwd, content_type, content, isBasicAuth, filter); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.debugLogger, "DELETE response: {}", ex); + } + logger.debug(EELFLoggerDelegate.debugLogger, "DELETE response: {}"); + + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java index 01367ecd..f05adf64 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java @@ -26,25 +26,104 @@ import org.openecomp.portalsdk.core.domain.RoleFunction; public interface RoleService { - List getRoleFunctions(); + /** + * + * @param requestedLoginId loginId + * @return returns List of RoleFunction + * @throws Exception + * Method getRoleFunctions returns list of Role Functions + */ + List getRoleFunctions(String requestedLoginId) throws Exception; - List getAvailableChildRoles(Long roleId); - Role getRole(Long id); + /** + * + * @param requestedLoginId + * @param roleId + * @return returns List of Role + * @throws Exception + * Method getAvailableChildRoles returns list of avialable child roles + */ + List getAvailableChildRoles(String requestedLoginId,Long roleId) throws Exception; - void saveRole(Role domainRole); - void deleteRole(Role domainRole); + /** + * + * @param requestedLoginId + * @param id roleId + * @return returns role + * @throws Exception + * Method getRole returns Role object if requested roleID + */ + Role getRole(String requestedLoginId,Long id) throws Exception; - List getAvailableRoles(); + /** + * + * @param requestedLoginId + * @param domainRole Object to be saved + * Method saveRole saves the Role Object + */ + void saveRole(String requestedLoginId,Role domainRole); - List getActiveRoles(); + /** + * + * @param requestedLoginId + * @param domainRole Object to be removed + * Method deleteRole deletes the requested Role Object + */ + void deleteRole(String requestedLoginId,Role domainRole); + + /** + * + * @param requestedLoginId + * @return returns list of available roles + * @throws Exception + * Method getAvailableRoles gets the list of available roles + */ + + List getAvailableRoles(String requestedLoginId) throws Exception; + + /** + * + * @param requestedLoginId + * @return + * @throws Exception + * Method getActiveRoles gets the list of active roles of application + * + */ + List getActiveRoles(String requestedLoginId) throws Exception; - RoleFunction getRoleFunction(String code); + /** + * + * @param requestedLoginId + * @param code function code + * @return + * @throws Exception + * Method getRoleFunction returns RoleFunction of requested function code + */ + RoleFunction getRoleFunction(String requestedLoginId,String code) throws Exception; - void saveRoleFunction(RoleFunction domainRoleFunction); + /** + * + * @param requestedLoginId + * @param domainRoleFunction + * Method saveRoleFunction saves the requested RoleFunction object + */ + void saveRoleFunction(String requestedLoginId,RoleFunction domainRoleFunction); - void deleteRoleFunction(RoleFunction domainRoleFunction); + /** + * + * @param requestedLoginId + * @param domainRoleFunction + * Method deleteRoleFunction deletes the requested RoleFunction object + */ + void deleteRoleFunction(String requestedLoginId,RoleFunction domainRoleFunction); - void deleteDependcyRoleRecord(Long id); + /** + * + * @param requestedLoginId + * @param id + * Method deleteDependcyRoleRecord deletes the requested object + */ + void deleteDependcyRoleRecord(String requestedLoginId,Long id); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java new file mode 100644 index 00000000..f507a7fc --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java @@ -0,0 +1,169 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + +@Transactional +public class RoleServiceCentralizedAccess implements RoleService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleServiceCentralizedAccess.class); + + @Autowired + AppService appService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @Override + public List getRoleFunctions(String loginId) throws Exception { + + List roleFunctionList = null; + String role_function_list = ""; + role_function_list = restApiRequestBuilder.getViaREST("/getAllRoleFunctions", true, loginId); + ObjectMapper mapper = new ObjectMapper(); + roleFunctionList = mapper.readValue(role_function_list, + TypeFactory.defaultInstance().constructCollectionType(List.class, RoleFunction.class)); + return roleFunctionList; + } + + @Override + public List getAvailableChildRoles(String loginId, Long roleId) throws Exception { + List availableChildRoles = getAvailableRoles(loginId); + if (roleId == null || roleId == 0) { + return availableChildRoles; + } + + Role currentRole = getRole(loginId, roleId); + Set allParentRoles = new TreeSet(); + allParentRoles = getAllParentRolesAsList(loginId, currentRole, allParentRoles); + + Iterator availableChildRolesIterator = availableChildRoles.iterator(); + while (availableChildRolesIterator.hasNext()) { + Role role = availableChildRolesIterator.next(); + if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) { + availableChildRolesIterator.remove(); + } + } + return availableChildRoles; + } + + @SuppressWarnings("unchecked") + private Set getAllParentRolesAsList(String loginId, Role role, Set allParentRoles) { + Set parentRoles = role.getParentRoles(); + allParentRoles.addAll(parentRoles); + Iterator parentRolesIterator = parentRoles.iterator(); + while (parentRolesIterator.hasNext()) { + getAllParentRolesAsList(loginId, parentRolesIterator.next(), allParentRoles); + } + return allParentRoles; + } + + @Override + public Role getRole(String loginId, Long id) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + + String roleString = restApiRequestBuilder.getViaREST("/role/" + id, true, loginId); + Role role = null; + + role = mapper.readValue(roleString, Role.class); + + logger.info(EELFLoggerDelegate.applicationLogger, "role_id" + role.getId()); + return role; + + } + + @Override + public void saveRole(String loginId, Role domainRole) { + try { + restApiRequestBuilder.postViaREST("/saveRole", true, domainRole.toString(), loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRole Failed", e); + } + } + + @Override + public void deleteRole(String loginId, Role domainRole) { + + String filter = " where active_yn = 'Y' "; + try { + restApiRequestBuilder.deleteViaRest("/deleteRole", true, domainRole.toString(), filter, loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRole Failed", e); + } + } + + @Override + public List getAvailableRoles(String requestedLoginId) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + + String roleList = restApiRequestBuilder.getViaREST("/getRoles", true, requestedLoginId); + List roles = null; + roles = mapper.readValue(roleList, + TypeFactory.defaultInstance().constructCollectionType(List.class, Role.class)); + return roles; + } + + @Override + public List getActiveRoles(String requestedLoginId) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String roleString = restApiRequestBuilder.getViaREST("/activeRoles?active_yn = 'Y'", true, requestedLoginId); + List roles = null; + roles = mapper.readValue(roleString, + TypeFactory.defaultInstance().constructCollectionType(List.class, Role.class)); + return roles; + + } + + @Override + public RoleFunction getRoleFunction(String requestedLoginId, String code) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + String responseString = restApiRequestBuilder.getViaREST("/getRoleFunction/" + code, true, requestedLoginId); + RoleFunction roleFunction = null; + roleFunction = mapper.readValue(responseString, RoleFunction.class); + return roleFunction; + } + + @Override + public void saveRoleFunction(String requestedLoginId, RoleFunction domainRoleFunction) { + try { + restApiRequestBuilder.postViaREST("/saveRoleFunction", true, domainRoleFunction.toString(), + requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction Failed", e); + } + } + + @Override + public void deleteRoleFunction(String requestedLoginId, RoleFunction domainRoleFunction) { + + try { + restApiRequestBuilder.deleteViaRest("/deleteRoleFucntion", true, domainRoleFunction.toString(), null, + requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction Failed", e); + } + } + + @Override + public void deleteDependcyRoleRecord(String requestedLoginId, Long id) { + + try { + restApiRequestBuilder.deleteViaRest("/deleteDependcyRoleRecord/" + id, true, null, null, requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord Failed", e); + } + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java index 2e780998..eab20f56 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java @@ -33,10 +33,8 @@ import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.RoleFunction; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("roleService") @Transactional public class RoleServiceImpl implements RoleService { @@ -57,13 +55,13 @@ public class RoleServiceImpl implements RoleService { } @SuppressWarnings("unchecked") - public List getRoleFunctions() { + public List getRoleFunctions(String loginId) { // List msgDB = getDataAccessService().getList(Profile.class, null); return getDataAccessService().getList(RoleFunction.class, null); } @SuppressWarnings("unchecked") - public List getAvailableChildRoles(Long roleId) { + public List getAvailableChildRoles(String loginId,Long roleId) { List availableChildRoles = (List) getDataAccessService().getList(Role.class, null); if (roleId == null || roleId == 0) { return availableChildRoles; @@ -71,7 +69,7 @@ public class RoleServiceImpl implements RoleService { Role currentRole = (Role) getDataAccessService().getDomainObject(Role.class, roleId, null); Set allParentRoles = new TreeSet(); - allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles); + allParentRoles = getAllParentRolesAsList(loginId,currentRole, allParentRoles); Iterator availableChildRolesIterator = availableChildRoles.iterator(); while (availableChildRolesIterator.hasNext()) { @@ -84,48 +82,48 @@ public class RoleServiceImpl implements RoleService { } @SuppressWarnings("unchecked") - private Set getAllParentRolesAsList(Role role, Set allParentRoles) { + private Set getAllParentRolesAsList(String loginId,Role role, Set allParentRoles) { Set parentRoles = role.getParentRoles(); allParentRoles.addAll(parentRoles); Iterator parentRolesIterator = parentRoles.iterator(); while (parentRolesIterator.hasNext()) { - getAllParentRolesAsList(parentRolesIterator.next(), allParentRoles); + getAllParentRolesAsList( loginId,parentRolesIterator.next(), allParentRoles); } return allParentRoles; } - public RoleFunction getRoleFunction(String code) { + public RoleFunction getRoleFunction(String loginId,String code) { return (RoleFunction) getDataAccessService().getDomainObject(RoleFunction.class, code, null); } - public void saveRoleFunction(RoleFunction domainRoleFunction) { + public void saveRoleFunction(String loginId,RoleFunction domainRoleFunction) { getDataAccessService().saveDomainObject(domainRoleFunction, null); } - public void deleteRoleFunction(RoleFunction domainRoleFunction) { + public void deleteRoleFunction(String loginId,RoleFunction domainRoleFunction) { getDataAccessService().deleteDomainObject(domainRoleFunction, null); } - public Role getRole(Long id) { + public Role getRole(String loginId,Long id) { return (Role) getDataAccessService().getDomainObject(Role.class, id, null); } - public void saveRole(Role domainRole) { + public void saveRole(String loginId,Role domainRole) { getDataAccessService().saveDomainObject(domainRole, null); } - public void deleteRole(Role domainRole) { + public void deleteRole(String loginId,Role domainRole) { getDataAccessService().deleteDomainObject(domainRole, null); } @SuppressWarnings("unchecked") - public List getAvailableRoles() { + public List getAvailableRoles(String loginId) { return getDataAccessService().getList(Role.class, null); } @SuppressWarnings("unchecked") @Override - public List getActiveRoles() { + public List getActiveRoles(String loginId) { String filter = " where active_yn = 'Y' "; return getDataAccessService().getList(Role.class, filter, null, null); } @@ -139,7 +137,7 @@ public class RoleServiceImpl implements RoleService { } @Override - public void deleteDependcyRoleRecord(Long id) { + public void deleteDependcyRoleRecord(String loginId,Long id) { Connection conn = null; Statement stmt = null; try { diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java new file mode 100644 index 00000000..c0275b87 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java @@ -0,0 +1,77 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.exception.SessionExpiredException; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +public class UrlAccessCentalizedImpl implements UrlAccessService { + + @Autowired + AppService appService; + + @Autowired + RoleService roleService; + + + @Override + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) { + + boolean isAccessible = false; + User user = UserUtils.getUserSession(request); + + + HttpSession session = AppUtils.getSession(request); + + if (session == null) { + throw new SessionExpiredException(); + } + + @SuppressWarnings("unchecked") + List allRoleFunctionsList = (List) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTION_LIST)); + + List allUrls = new ArrayList(); + + for (int i = 0; i < allRoleFunctionsList.size(); i++) { + if (allRoleFunctionsList.get(i).getCode() != null && ((String) allRoleFunctionsList.get(i).getCode()).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) { + String functionCd = ((String) allRoleFunctionsList.get(i).getCode()).substring(4).toUpperCase(); + allUrls.add(functionCd); + } + } + + @SuppressWarnings("unchecked") + Set roleFunction = UserUtils.getRoleFunctions(request); + List list = new ArrayList<>(roleFunction); + List UserURLlist = new ArrayList(); + + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) != null && ((String) list.get(i)).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) { + String functionCd = ((String) list.get(i)).substring(4).toUpperCase(); + UserURLlist.add(functionCd); + } + } + } + + if((!UserURLlist.contains(currentUrl) && !allUrls.contains(currentUrl)) || (UserURLlist.contains(currentUrl) && allUrls.contains(currentUrl))) + { + isAccessible = true; + }else { + isAccessible = false; + } + return isAccessible; + + } + + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java new file mode 100644 index 00000000..e01abfbb --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java @@ -0,0 +1,48 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.domain.UrlsAccessible; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +public class UrlAccessImpl implements UrlAccessService{ + + @Autowired + DataAccessService dataAccessService; + + + + @Override + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) { + boolean isAccessible = false; + Map params = new HashMap<>(); + params.put("current_url", currentUrl); + List list = dataAccessService.executeNamedQuery("restrictedUrls", params, null); + + // loop through the list of restricted URL's + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + /* + * Object[] restrictedUrl = (Object[])list.get(i); + * + * String url = (String)restrictedUrl[0]; String functionCd = + * (String)restrictedUrl[1]; + */ + UrlsAccessible urlFunctions = (UrlsAccessible) list.get(i); + // String url = (String) urlFunctions.getUrl(); + String functionCd = (String) urlFunctions.getFunctionCd(); + if (UserUtils.isAccessible(request, functionCd)) { + isAccessible = true; + } + } + return isAccessible; + } + return true; + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java new file mode 100644 index 00000000..bb815f5d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java @@ -0,0 +1,15 @@ +package org.openecomp.portalsdk.core.service; + +import javax.servlet.http.HttpServletRequest; + +public interface UrlAccessService { + + /** + * Answers whether the specified URL is accessible. + * + * @param request + * @param currentUrl + * @return true if yes, false if no. + */ + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl); +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java new file mode 100644 index 00000000..3e7b2b14 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java @@ -0,0 +1,137 @@ +package org.openecomp.portalsdk.core.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.SortedSet; + +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.domain.support.CollaborateList; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + + +@Transactional +public class UserProfileServiceCentalizedImpl implements UserProfileService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserProfileServiceCentalizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @Autowired + private DataAccessService dataAccessService; + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + @Override + public List findAll() { + List roles = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + + String user = restApiRequestBuilder.getViaREST("/findAll", true,null); + try { + roles = mapper.readValue(user, + TypeFactory.defaultInstance().constructCollectionType(List.class, User.class)); + } catch (JsonParseException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json parsing failed", e); + } catch (JsonMappingException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json mapping failed", e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "IO exception", e); + } + + return roles; + } + + @Override + public User getUser(String id) { + ObjectMapper mapper = new ObjectMapper(); + User user = new User(); + String responseString = restApiRequestBuilder.getViaREST("/getUser/" + id, true,id); + try { + + user = mapper.readValue(responseString, User.class); + } catch (JsonParseException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json parsing failed", e); + } catch (JsonMappingException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json mapping failed", e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "IO exception", e); + } + + return user; + } + + @Override + public User getUserByLoginId(String loginId) { + return getUser(loginId); + } + + @Override + public void saveUser(User user) { + try { + getDataAccessService().saveDomainObject(user, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveUser Failed", e); + } + } + + @Override + public List findAllUserWithOnOffline(String originOrgUserId) { + HashSet onlineUser = CollaborateList.getInstance().getAllUserName(); + List users = findAll(); + for (User u : users) { + if (onlineUser.contains(u.getOrgUserId())) + u.setOnline(true); + if (u.getOrgUserId() != null) { + if (originOrgUserId.compareTo(u.getOrgUserId()) > 0) { + u.setChatId(originOrgUserId + "-" + u.getOrgUserId()); + } else + u.setChatId(u.getOrgUserId() + "-" + originOrgUserId); + } + } + return users; + } + + @Override + public List findAllActive() { + List users = findAll(); + Iterator itr = users.iterator(); + while (itr.hasNext()) { + User u = (User) itr.next(); + if (!u.getActive()) + itr.remove();// if not active remove user from list + else { + SortedSet roles = u.getRoles(); + Iterator itrRoles = roles.iterator(); + while (itrRoles.hasNext()) { + Role role = (Role) itrRoles.next(); + if (!role.getActive()) + u.removeRole(role.getId());// if not active remove role + // from list + } + } + } + return users; + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java index 2d134725..866318c5 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java @@ -31,10 +31,8 @@ import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.domain.support.CollaborateList; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("userProfileService") @Transactional public class UserProfileServiceImpl implements UserProfileService{ @@ -42,6 +40,7 @@ public class UserProfileServiceImpl implements UserProfileService{ @Autowired private DataAccessService dataAccessService; + @SuppressWarnings("unchecked") public List findAll() { return getDataAccessService().getList(User.class, null); } @@ -94,6 +93,7 @@ public class UserProfileServiceImpl implements UserProfileService{ } public List findAllActive() { + @SuppressWarnings("unchecked") List users = getDataAccessService().getList(User.class, null); Iterator itr = users.iterator(); while(itr.hasNext()){ diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/util/SystemProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/util/SystemProperties.java index 2dacae84..20dfec90 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/util/SystemProperties.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/util/SystemProperties.java @@ -209,6 +209,8 @@ public class SystemProperties { public static final String LOGIN_METHOD_WEB_JUNCTION = "login_method_web_junction"; public static final String LOGIN_METHOD_BACKDOOR = "login_method_backdoor"; public static final String LOGIN_METHOD_ATTRIBUTE_NAME = "login_method_attribute_name"; + public static final String ROLE_FUNCTION_LIST = "role_function_list"; + // login error message keys public static final String MESSAGE_KEY_LOGIN_ERROR_COOKIE_EMPTY = "login.error.hrid.empty"; diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java index 37eaccad..6b3dc4dc 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java @@ -46,12 +46,13 @@ import org.openecomp.portalsdk.core.menu.MenuBuilder; import org.openecomp.portalsdk.core.restful.domain.EcompRole; import org.openecomp.portalsdk.core.restful.domain.EcompUser; import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.service.UrlAccessService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("rawtypes") public class UserUtils { - + static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserUtils.class); public static final String KEY_USER_ROLES_CACHE = "userRoles"; @@ -59,7 +60,7 @@ public class UserUtils { private static DataAccessService dataAccessService; public static void setUserSession(HttpServletRequest request, User user, Set applicationMenuData, - Set businessDirectMenuData, String loginMethod) { + Set businessDirectMenuData, String loginMethod , List roleFunctionList) { HttpSession session = request.getSession(true); UserUtils.clearUserSession(request); // let's clear the current user @@ -77,6 +78,8 @@ public class UserUtils { session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_NAME), user.getFullName()); session.setAttribute(SystemProperties.FIRST_NAME, user.getFirstName()); session.setAttribute(SystemProperties.LAST_NAME, user.getLastName()); + session.setAttribute(SystemProperties.ROLE_FUNCTION_LIST, roleFunctionList); + ServletContext context = session.getServletContext(); int licenseVarificationFlag = 3; try { @@ -125,12 +128,14 @@ public class UserUtils { session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)); session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME)); session.removeAttribute(SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_ATTRIBUTE_NAME)); + session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTION_LIST)); + } @SuppressWarnings("unchecked") public static Set getRoleFunctions(HttpServletRequest request) { HashSet roleFunctions = null; - +// HashSet rolefun = null; HttpSession session = request.getSession(); roleFunctions = (HashSet) session .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME)); @@ -152,11 +157,12 @@ public class UserUtils { roleFunctions.add(function.getCode()); } } - session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME), roleFunctions); } - + + + return roleFunctions; } @@ -228,38 +234,7 @@ public class UserUtils { } - /** - * Answers whether the specified URL is accessible. - * - * @param request - * @param currentUrl - * @return true if yes, false if no. - */ - public static boolean isUrlAccessible(HttpServletRequest request, String currentUrl) { - boolean isAccessible = false; - Map params = new HashMap<>(); - params.put("current_url", currentUrl); - List list = getDataAccessService().executeNamedQuery("restrictedUrls", params, null); - // loop through the list of restricted URL's - if (list != null && list.size() > 0) { - for (int i = 0; i < list.size(); i++) { - /* - * Object[] restrictedUrl = (Object[])list.get(i); - * - * String url = (String)restrictedUrl[0]; String functionCd = - * (String)restrictedUrl[1]; - */ - UrlsAccessible urlFunctions = (UrlsAccessible) list.get(i); - // String url = (String) urlFunctions.getUrl(); - String functionCd = (String) urlFunctions.getFunctionCd(); - if (UserUtils.isAccessible(request, functionCd)) { - isAccessible = true; - } - } - return isAccessible; - } - return true; - } + public static boolean hasRole(HttpServletRequest request, String roleKey) { return getRoles(request).keySet().contains(new Long(roleKey)); @@ -308,10 +283,11 @@ public class UserUtils { return userId; } - private static final Object stackTraceLock = new Object(); + /** - * Serializes a stack trace of the specified throwable and returns it as a string. + * Serializes a stack trace of the specified throwable and returns it as a + * string. * * TODO: why is synchronization required? * @@ -328,7 +304,8 @@ public class UserUtils { } /** - * Gets the full URL of the request by joining the request and any query string. + * Gets the full URL of the request by joining the request and any query + * string. * * @param request * @return Full URL of the request including query parameters @@ -362,8 +339,8 @@ public class UserUtils { while (headerNames.hasMoreElements()) { String headerName = (String) headerNames.nextElement(); if (logger.isTraceEnabled()) - logger.trace(EELFLoggerDelegate.debugLogger, - "getRequestId: header {} = {}", headerName, request.getHeader(headerName)); + logger.trace(EELFLoggerDelegate.debugLogger, "getRequestId: header {} = {}", headerName, + request.getHeader(headerName)); if (headerName.equalsIgnoreCase(SystemProperties.ECOMP_REQUEST_ID)) { requestId = request.getHeader(headerName); break; @@ -380,7 +357,8 @@ public class UserUtils { } /** - * Converts a Hibernate-mapped User object to a JSON-serializable EcompUser object. + * Converts a Hibernate-mapped User object to a JSON-serializable EcompUser + * object. * * @param user * @return EcompUser with a subset of fields. @@ -408,7 +386,8 @@ public class UserUtils { } /** - * Converts a Hibernate-mapped Role object to a JSON-serializable EcompRole object. + * Converts a Hibernate-mapped Role object to a JSON-serializable EcompRole + * object. * * @param role * @return EcompRole with a subset of fields: ID and name @@ -419,5 +398,7 @@ public class UserUtils { ecompRole.setName(role.getName()); return ecompRole; } - -} + + } + + diff --git a/ecomp-sdk/epsdk-fw/pom.xml b/ecomp-sdk/epsdk-fw/pom.xml index 359b6c4c..42019604 100644 --- a/ecomp-sdk/epsdk-fw/pom.xml +++ b/ecomp-sdk/epsdk-fw/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java index 0efd1ce4..b2d5ef3d 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java @@ -102,11 +102,13 @@ public interface IPortalRestAPIService { * library will catch the exception and send an appropriate response to * Portal. * + * @param requestedLoginId + * requested userloginId to fetch available roles * @return List of role attribute objects; empty list if none are found. * @throws PortalAPIException * If an unexpected error occurs while processing the request. */ - public List getAvailableRoles() throws PortalAPIException; + public List getAvailableRoles(String requestedLoginId) throws PortalAPIException; /** * Updates roles for the user with the specified loginId to the list of diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java index 02d35ae9..01337f78 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java @@ -110,7 +110,6 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (portalRestApiServiceImpl == null) { // Should never happen due to checks in init() logger.error("doPost: no service class instance"); @@ -145,7 +144,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer bodyMap.put("userid", userId); requestBody = mapper.writeValueAsString(bodyMap); responseJson = RestWebServiceClient.getInstance().postPortalContent(storeAnalyticsContextPath, - userId, credential, null, credential, credential, "application/json", requestBody); + userId, credential, null, credential, credential, "application/json", requestBody, true); if (logger.isDebugEnabled()) logger.debug("doPost: postPortalContent returns " + responseJson); response.setStatus(HttpServletResponse.SC_OK); @@ -321,8 +320,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer String credential = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); // for now lets also pass uebkey as user name and password contentType = "text/javascript"; + responseString = RestWebServiceClient.getInstance().getPortalContent(webAnalyticsContextPath, - userId, credential, null, credential, credential); + userId, credential, null, credential, credential,true); if (logger.isDebugEnabled()) logger.debug("doGet: " + webAnalyticsContextPath + ": " + responseString); response.setStatus(HttpServletResponse.SC_OK); @@ -398,9 +398,10 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer } } else // Example: /roles <-- get all roles + if (requestUri.endsWith(PortalApiConstants.API_PREFIX + "/roles")) { try { - List roles = getAvailableRoles(); + List roles = getAvailableRoles(getUserId(request)); responseJson = mapper.writeValueAsString(roles); if (logger.isDebugEnabled()) logger.debug("doGet: getAvailableRoles: " + responseJson); @@ -484,8 +485,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer } @Override - public List getAvailableRoles() throws PortalAPIException { - return portalRestApiServiceImpl.getAvailableRoles(); + public List getAvailableRoles(String requestedLoginId) throws PortalAPIException { + return portalRestApiServiceImpl.getAvailableRoles(requestedLoginId); } @Override diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java index b4ca4755..eed49f2a 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java @@ -46,6 +46,6 @@ public class FavoritesClient { public static String getFavorites(String userId, String appName, String requestId, String appUserName, String appPassword) throws Exception { return RestWebServiceClient.getInstance().getPortalContent("/getFavorites", userId, appName, requestId, appUserName, - appPassword); + appPassword,true); } } \ No newline at end of file diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java index a3a320eb..90cbdcb4 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java @@ -48,7 +48,7 @@ public class FunctionalMenuClient { public static String getFunctionalMenu(String userId, String appName, String requestId, String appUserName, String appPassword) throws Exception { return RestWebServiceClient.getInstance().getPortalContent("/functionalMenuItemsForUser", userId, appName, - requestId, appUserName, appPassword); + requestId, appUserName, appPassword,true); } } \ No newline at end of file diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java index f01590d4..1d4feb07 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Base64; import java.util.UUID; import org.apache.commons.logging.Log; @@ -32,7 +33,7 @@ import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; /** - * Simple REST client for GET-ing content from and POST-ing content to the + * Simple REST client for GET-ing content from and POST-ing content , Delete to the * Portal application. */ public class RestWebServiceClient { @@ -86,9 +87,9 @@ public class RestWebServiceClient { * @throws Exception * on any failure */ - public String getPortalContent(String restPath, String userId, String appName, String requestId, String appUserName, - String appPassword) throws Exception { - String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + public String getPortalContent(String restPath,String userId, String appName, String requestId, String appUserName, String appPassword, boolean isBasicAuth) throws Exception { + String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + if (restURL == null) { // should never happen String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL; @@ -96,17 +97,23 @@ public class RestWebServiceClient { throw new Exception(msg); } String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); + if (appUebKey == null) { // should never happen - String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY; + String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY; + logger.error(msg); throw new Exception(msg); } final String restEndpointUrl = restURL + restPath; - return get(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword); - + if(isBasicAuth) + { + return get(restEndpointUrl, userId,appName, requestId, appUebKey, appUserName, appPassword,isBasicAuth); + } + return get(restEndpointUrl, userId,appName, requestId, appUebKey, appUserName, appPassword); } + /** * Makes a call to a Portal REST API using the specified URL and parameters. * @@ -131,8 +138,39 @@ public class RestWebServiceClient { * @throws Exception * On any failure; e.g., unknown host. */ + public String get(String url, String loginId, String appName, String requestId, String appUebKey, String appUserName, String appPassword) throws Exception { + return get(url, loginId, appName,requestId, appUebKey, appUserName, appPassword, false); + } + + + /** + * Makes a call to a Portal REST API using the specified URL and parameters. + * + * @param url + * Complete URL of the REST endpoint. + * @param loginId + * User that it should be fetching the data + * @param appName + * Application name for logging; if null or empty, defaulted to + * Unknown. + * @param requestId + * 128-bit UUID value to uniquely identify the transaction; if + * null or empty, one is generated. + * @param appUebKey + * Unique key for the application, used by Portal to authenticate + * the request + * @param appUserName + * REST API user name, used by Portal to authenticate the request + * @param appPassword + * REST API password, used by Portal to authenticate the request + * @return Content from REST endpoint + * @throws Exception + * On any failure; e.g., unknown host. + */ + public String get(String url, String loginId, String appName, String requestId, String appUebKey, + String appUserName, String appPassword, Boolean useBasicAuth) throws Exception { logger.debug("RestWebServiceClient.get (" + url + ") operation is started."); @@ -150,12 +188,17 @@ public class RestWebServiceClient { // add request header con.setRequestProperty("uebkey", appUebKey); - con.setRequestProperty("username", appUserName); - con.setRequestProperty("password", appPassword); con.setRequestProperty("LoginId", loginId); con.setRequestProperty("user-agent", appName); con.setRequestProperty("X-ECOMP-RequestID", requestId); - + con.setRequestProperty("username", appUserName); + con.setRequestProperty("password", appPassword); + + if(useBasicAuth){ + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes()); + con.setRequestProperty("Authorization", "Basic "+ encoding); + } + int responseCode = con.getResponseCode(); logger.debug("get: received response code '" + responseCode + "' while getting the '" + url + "' for user: " + loginId); @@ -181,7 +224,7 @@ public class RestWebServiceClient { logger.debug("get: url " + url + " yielded " + response); return response; } - + /** * Convenience method that fetches the URL for the Portal REST API endpoint * and the application UEB key, then calls @@ -211,25 +254,30 @@ public class RestWebServiceClient { * on any failure */ public String postPortalContent(String restPath, String userId, String appName, String requestId, - String appUserName, String appPassword, String contentType, String content) throws Exception { + String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth) throws Exception { String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + + if (restURL == null) { // should never happen String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL; + logger.error(msg); throw new Exception(msg); } String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); + if (appUebKey == null) { // should never happen String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY; + logger.error(msg); throw new Exception(msg); } final String separator = restURL.endsWith("/") || restPath.startsWith("/") ? "" : "/"; final String restEndpointUrl = restURL + separator + restPath; return post(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword, contentType, - content); + content,isBasicAuth); } /** @@ -264,7 +312,7 @@ public class RestWebServiceClient { * On any error */ public String post(String url, String loginId, String appName, String requestId, String appUebKey, - String appUserName, String appPassword, String contentType, String content) throws Exception { + String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth) throws Exception { if (logger.isDebugEnabled()) logger.debug("RestWebServiceClient.post to URL " + url); @@ -290,6 +338,99 @@ public class RestWebServiceClient { con.setRequestProperty("user-agent", appName); con.setRequestProperty("X-ECOMP-RequestID", requestId); con.setRequestProperty("Content-Type", contentType); + if(isBasicAuth){ + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes()); + con.setRequestProperty("Authorization", "Basic "+ encoding); + } + + con.setDoInput(true); + con.setDoOutput(true); + con.getOutputStream().write(content.getBytes()); + con.getOutputStream().flush(); + con.getOutputStream().close(); + + int responseCode = con.getResponseCode(); + logger.debug("Response Code : " + responseCode); + + StringBuffer sb = new StringBuffer(); + InputStreamReader in = null; + char[] buf = new char[8196]; + int bytes; + try { + in = new InputStreamReader(con.getInputStream(), "UTF-8"); + while ((bytes = in.read(buf)) > 0) + sb.append(new String(buf, 0, bytes)); + } finally { + try { + if (in != null) + in.close(); + } catch (IOException ex) { + logger.warn("get: failed to close reader", ex); + } + } + + return sb.toString(); + } + + + public String deletePortalContent(String restPath, String userId, String appName, String requestId, + String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth ,String filter) throws Exception { + String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL); + + if (restURL == null) { + // should never happen + String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL; + + logger.error(msg); + throw new Exception(msg); + } + String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); + + if (appUebKey == null) { + // should never happen + String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY; + + logger.error(msg); + throw new Exception(msg); + } + final String separator = restURL.endsWith("/") || restPath.startsWith("/") ? "" : "/"; + final String restEndpointUrl = restURL + separator + restPath; + return delete(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword, contentType, + content,isBasicAuth,filter); + } + + public String delete(String url, String loginId, String appName, String requestId, String appUebKey, + String appUserName, String appPassword, String contentType, String content,boolean isBasicAuth ,String filter) throws Exception { + + if (logger.isDebugEnabled()) + logger.debug("RestWebServiceClient.post to URL " + url); + if (appName == null || appName.trim().length() == 0) + appName = "Unknown"; + if (requestId == null || requestId.trim().length() == 0) + requestId = UUID.randomUUID().toString(); + + URL obj = new URL(url); + // Create the connection object + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + con.setRequestMethod("DELETE"); + con.setConnectTimeout(3000); + con.setReadTimeout(15000); + + // add request header + con.setRequestProperty("uebkey", appUebKey); + if (appUserName != null) + con.setRequestProperty("username", appUserName); + if (appPassword != null) + con.setRequestProperty("password", appPassword); + con.setRequestProperty("LoginId", loginId); + con.setRequestProperty("user-agent", appName); + con.setRequestProperty("X-ECOMP-RequestID", requestId); + con.setRequestProperty("Content-Type", contentType); + con.setRequestProperty("filter", filter); + if(isBasicAuth){ + String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes()); + con.setRequestProperty("Authorization", "Basic "+ encoding); + } con.setDoInput(true); con.setDoOutput(true); @@ -319,6 +460,7 @@ public class RestWebServiceClient { return sb.toString(); } + /** * Basic unit test for the client to call Portal app on localhost. @@ -330,13 +472,13 @@ public class RestWebServiceClient { public static void main(String[] args) throws Exception { RestWebServiceClient client = RestWebServiceClient.getInstance(); final String getUrl = "http://www.ecomp.openecomp.org:8080/ecompportal/auxapi/analytics"; - String get = client.get(getUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword"); + String get = client.get(getUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword", null); System.out.println("Get result:\n" + get); final String postUrl = "http://www.ecomp.openecomp.org:8080/ecompportal/auxapi/storeAnalytics"; final String content = " { " + " \"action\" : \"test1\", " + " \"page\" : \"test2\", " + " \"function\" : \"test3\", " + " \"userid\" : \"ab1234\" " + "}"; String post = client.post(postUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword", - "application/json", content); + "application/json", content, true); System.out.println("Post result:\n" + post); } } diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java index e706b7ec..196d2100 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java @@ -37,6 +37,7 @@ public interface PortalApiConstants { public static final String PORTAL_API_IMPL_CLASS = "portal.api.impl.class"; public static final String ECOMP_REDIRECT_URL = "ecomp_redirect_url"; public static final String ECOMP_REST_URL = "ecomp_rest_url"; + public static final String ROLE_ACCESS_CENTRALIZED = "role_access_centralized"; public static final String CSP_COOKIE_NAME = "csp_cookie_name"; public static final String CSP_GATE_KEEPER_PROD_KEY = "csp_gate_keeper_prod_key"; @@ -48,6 +49,7 @@ public interface PortalApiConstants { public static final String UEB_LISTENERS_ENABLE = "ueb_listeners_enable"; public static final String UEB_APP_INBOUND_MAILBOX_NAME = "ueb_app_mailbox_name"; public static final String UEB_APP_CONSUMER_GROUP_NAME = "ueb_app_consumer_group_name"; + // UebManager generates a consumer group name for special token {UUID} public static final String UEB_APP_CONSUMER_GROUP_NAME_GENERATOR = "{UUID}"; public static final String UEB_APP_KEY = "ueb_app_key"; diff --git a/ecomp-sdk/epsdk-workflow/pom.xml b/ecomp-sdk/epsdk-workflow/pom.xml index aef602f6..8fe2372b 100644 --- a/ecomp-sdk/epsdk-workflow/pom.xml +++ b/ecomp-sdk/epsdk-workflow/pom.xml @@ -5,7 +5,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT diff --git a/ecomp-sdk/pom.xml b/ecomp-sdk/pom.xml index a7ca16f2..e9e47798 100644 --- a/ecomp-sdk/pom.xml +++ b/ecomp-sdk/pom.xml @@ -6,7 +6,7 @@ org.openecomp.ecompsdkos epsdk-project - 1.1.0 + 1.3.0-SNAPSHOT pom ECOMP Portal SDK Project (parent) https://wiki.onap.org/display/DW/Portal -- cgit 1.2.3-korg