diff options
Diffstat (limited to 'ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller')
12 files changed, 1600 insertions, 53 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequest.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequest.java index 483d76ea..cef5fa74 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequest.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequest.java @@ -53,6 +53,7 @@ import org.onap.portalapp.portal.service.PortalAdminService; import org.onap.portalapp.portal.service.UserService; import org.onap.portalapp.portal.transport.FieldsValidator; import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.portal.utils.PortalConstants; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -212,6 +213,7 @@ public class AppsControllerExternalRequest implements BasicAuthenticationControl @PathVariable("appId") Long appId) { EPApp epApp = appService.getApp(appId); OnboardingApp obApp = new OnboardingApp(); + epApp.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD); //to hide password from get request appService.createOnboardingFromApp(epApp, obApp); EcompPortalUtils.logAndSerializeObject(logger, "getOnboardAppExternal", "response", obApp); return obApp; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalVersionRequest.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalVersionRequest.java new file mode 100644 index 00000000..13a6811e --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsControllerExternalVersionRequest.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import io.swagger.annotations.ApiOperation; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class AppsControllerExternalVersionRequest implements BasicAuthenticationController { + + @Autowired + AppsControllerExternalRequest appsControllerExternalRequest; + + @ApiVersion(max = "v3", service = "/v3/portalAdmin", min = 0, method = "POST") + public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response, + EPUser epUser) { + return appsControllerExternalRequest.postPortalAdmin(request, response, epUser); + } + + @ApiVersion(max = "v3", service = "/v3/onboardApp/[0-9]{1,25}$", min = 0, method = "GET") + public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, Long appId) { + return appsControllerExternalRequest.getOnboardAppExternal(request, response, appId); + } + + @ApiVersion(max = "v3", service = "/v3/onboardApp", min = 0, method = "POST") + public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, + OnboardingApp newOnboardApp) { + return appsControllerExternalRequest.postOnboardAppExternal(request, response, newOnboardApp); + + } + @ApiVersion(max = "v3", service = "/v3/onboardApp/[0-9]{1,25}$", min = 0, method = "PUT") + public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, + Long appId, OnboardingApp oldOnboardApp) { + return appsControllerExternalRequest.putOnboardAppExternal(request, response, appId, oldOnboardApp); + } +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperController.java new file mode 100644 index 00000000..60c25c65 --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperController.java @@ -0,0 +1,890 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.service.ManifestService; +import org.onap.portalapp.portal.transport.Analytics; +import org.onap.portalapp.portal.transport.CentralUser; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalapp.portal.transport.EpNotificationItem; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; +import org.onap.portalsdk.core.restful.domain.EcompRole; +import org.onap.portalsdk.core.restful.domain.EcompUser; +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.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.swagger.annotations.ApiOperation; + +@RestController +@RequestMapping("/auxapi") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class); + + ApplicationContext context = null; + int minorVersion = 0; + + @Autowired + private ManifestService manifestService; + + @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List") + @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json") + public String getUser(HttpServletRequest request, HttpServletResponse response, + @PathVariable("loginId") String loginId) throws Exception { + Map<String, Object> res = getMethod(request, response); + String answer = null; + try { + answer = (String) invokeMethod(res, request, response, loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e); + } + return answer; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json") + public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception { + Map<String, Object> res = getMethod(request, response); + request.getMethod(); + List<CentralV2Role> answer = null; + try { + answer = (List<CentralV2Role>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e); + } + return answer; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response, + @RequestBody Role role) throws Exception { + Map<String, Object> res = getMethod(request, response); + PortalRestResponse<String> out = null; + try { + out = (PortalRestResponse<String>) invokeMethod(res, request, response, role); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + return out; + } + + @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json") + public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response, + @PathVariable("role_id") Long roleId) throws Exception { + Map<String, Object> res = getMethod(request, response); + CentralV2Role role = null; + try { + role = (CentralV2Role) invokeMethod(res, request, response, roleId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e); + } + return role; + + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json") + public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response) + throws Exception { + Map<String, Object> res = getMethod(request, response); + List<EcompUser> users = null; + try { + users = (List<EcompUser>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e); + } + return users; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json") + public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response) + throws Exception { + Map<String, Object> res = getMethod(request, response); + List<CentralV2RoleFunction> roleFunctionsList = null; + try { + roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e); + } + return roleFunctionsList; + } + + @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json") + public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response, + @PathVariable("code") String code) throws Exception { + Map<String, Object> res = getMethod(request, response); + CentralV2RoleFunction roleFunction = null; + try { + roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e); + } + return roleFunction; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response, + @RequestBody String roleFunc) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleFunc); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json") + public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response, + @PathVariable("code") String code) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, code); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json") + public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response, + @PathVariable("roleId") Long roleId) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json") + public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + List<CentralV2Role> cenRole = null; + Map<String, Object> res = getMethod(request, response); + try { + cenRole = (List<CentralV2Role>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e); + } + return cenRole; + } + + @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List") + @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json") + public String getEcompUser(HttpServletRequest request, HttpServletResponse response, + @PathVariable("loginId") String loginId) throws Exception { + Map<String, Object> res = getMethod(request, response); + String answer = null; + try { + answer = (String) invokeMethod(res, request, response, loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e); + } + return answer; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List") + @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json") + public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response) + throws Exception { + Map<String, Object> res = getMethod(request, response); + List<EcompRole> answer = null; + try { + answer = (List<EcompRole>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e); + } + return answer; + } + + @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class) + @RequestMapping(value = { + "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json") + public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response) + throws Exception { + Map<String, Object> res = getMethod(request, response); + Integer ans = null; + try { + ans = (Integer) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e); + } + return ans; + } + + @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class) + @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST) + public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response, + @RequestParam String sessionMap) throws Exception { + Map<String, Object> res = getMethod(request, response); + Boolean ans = null; + try { + ans = (Boolean) invokeMethod(res, request, response, sessionMap); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e); + } + return ans; + } + + @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class) + @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript") + public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception { + Map<String, Object> res = getMethod(request, response); + String ans = null; + try { + ans = (String) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e); + } + return ans; + } + + @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class) + public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response, + @RequestBody Analytics analyticsMap) throws Exception { + Map<String, Object> res = getMethod(request, response); + PortalAPIResponse ans = new PortalAPIResponse(true, "error"); + try { + ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e); + } + return ans; + + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response) + throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response) + throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request, + HttpServletResponse response, @PathVariable Long roleId) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request, + HttpServletResponse response) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + // not using + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response, + @RequestBody List<Role> upload) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, upload); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") + @RequestMapping(value = { + "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request, + HttpServletResponse response) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json") + @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json") + public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception { + List<String> functionsList = null; + Map<String, Object> res = getMethod(request, response); + try { + functionsList = (List<String>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e); + } + return functionsList; + } + + private String getPatchNumber() { + String response = "0"; + try { + Attributes attributes = manifestService.getWebappManifest(); + response = attributes.getValue("Build-Number"); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex); + } + return response; + } + + @SuppressWarnings("rawtypes") + private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) { + Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class); + @SuppressWarnings("unchecked") + List<Object> beansList = new ArrayList(beans.values()); + return beansList; + + } + + private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) { + Method finalmethod = null; + String url = request.getRequestURI(); + String version = ""; + String service = ""; + Object currentObject = null; + Map<String, Object> res = new HashMap<String, Object>(); + String[] uriArray = url.split("/auxapi"); + List<Integer> minorversionList = new ArrayList<>(); + if (uriArray.length > 1) { + service = uriArray[1]; + } + int first = service.indexOf("/"); + int second = service.indexOf("/", first + 1); + version = service.substring(first + 1, second); + int min = minorVersion; + if (request.getHeader("MinorVersion") != null) { + min = Integer.parseInt(request.getHeader("MinorVersion")); + } + res.put("min", version+"."+min); + res.put("service", service); + List<Object> objList = getObject(request, response); + String requestedApiMethodType = request.getMethod(); + String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType); + int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType); + res.put("majorVersion", majorVersion); + res.put("latestMinorVersion", String.valueOf(latestMinorVersion)); + outerloop: for (Object obj : objList) { + final List<Method> allMethods = getAllMethodsOfClass(obj); + for (final Method method : allMethods) { + if (method.isAnnotationPresent(ApiVersion.class)) { + ApiVersion annotInstance = method.getAnnotation(ApiVersion.class); + Pattern p = Pattern.compile(annotInstance.service(), + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); + Matcher matcher = p.matcher(service); + boolean b = matcher.matches(); + logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service + + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version); + if (annotInstance.max().equals(version) && b && annotInstance.min() == min + && annotInstance.method().equals(request.getMethod())) { + finalmethod = method; + currentObject = obj; + res.put("method", method); + res.put("Obj", obj); + break outerloop; + } + } + } + } + return res; + } + + private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion, + String requestedApiMethodType) { + Integer majorVersion = 0; + String serviceEndPoint = service; + int firstindex = serviceEndPoint.indexOf("/"); + int secondindex = serviceEndPoint.indexOf("/", firstindex + 1); + serviceEndPoint = serviceEndPoint.substring(secondindex + 1); + + List<Integer> latestMajorVersionList = new ArrayList<>(); + for (Object obj : objList) { + final List<Method> allMethods = getAllMethodsOfClass(obj); + for (final Method method : allMethods) { + if (method.isAnnotationPresent(ApiVersion.class)) { + ApiVersion annotInstance = method.getAnnotation(ApiVersion.class); + String endpoint = annotInstance.service(); + int first = endpoint.indexOf("/"); + int second = endpoint.indexOf("/", first + 1); + endpoint = endpoint.substring(second + 1); + Pattern p = Pattern.compile(endpoint, + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); + Matcher matcher = p.matcher(serviceEndPoint); + boolean b = matcher.matches(); + if (b && annotInstance.method().equals(requestedApiMethodType)) { + int index1 = annotInstance.service().indexOf("/"); + int index2 = annotInstance.service().indexOf("/", index1 + 1); + String majorversion = annotInstance.service().substring(index1 + 2, index2); + latestMajorVersionList.add(Integer.parseInt(majorversion)); + } + } + } + } + majorVersion = Collections.max(latestMajorVersionList); + String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint; + int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType); + return majorVersion+"."+latestMinorVersion; + } + + private List<Method> getAllMethodsOfClass(Object obj) { + List<Method> allMethods = new ArrayList<>(); + Class<?> objClz = obj.getClass(); + if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) { + objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj); + } + allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods())); + allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class))); + return allMethods; + } + + private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion, + String requestedApiMethodType) { + Integer minVersion = 0; + String serviceEndPoint = service; + List<Integer> latestMinorVersionList = new ArrayList<>(); + for (Object obj : objList) { + final List<Method> allMethods = getAllMethodsOfClass(obj); + for (final Method method : allMethods) { + if (method.isAnnotationPresent(ApiVersion.class)) { + ApiVersion annotInstance = method.getAnnotation(ApiVersion.class); + String endpoint = annotInstance.service(); + + Pattern p = Pattern.compile(endpoint, + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); + Matcher matcher = p.matcher(serviceEndPoint); + boolean b = matcher.matches(); + if (annotInstance.max().equals(reuqestedVersion) && b + && annotInstance.method().equals(requestedApiMethodType)) { + int minorversion = annotInstance.min(); + latestMinorVersionList.add(minorversion); + } + } + } + } + minVersion = Collections.max(latestMinorVersionList); + return minVersion; + } + + private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion, + String majorVersion, String latestMinorVersion, String service) { + response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase()); + response.setHeader("X-PatchVersion", getPatchNumber()); + response.setHeader("X-LatestVersion", "V"+majorVersion); + return response; + } + + /** + * + * @param res + * @param args + * method parameters(Maintain HttpServletRequest at 0th position + * and HttpServletResponse at 1th position in args array) + * @return + * @throws Exception + */ + private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception { + Method method = (Method) res.get("method"); + Object obj = res.get("Obj"); + Object responseObj = null; + String min = res.get("min").toString(); + String majorVersion = res.get("majorVersion").toString(); + String latestMinorVersion = res.get("latestMinorVersion").toString(); + String service = res.get("service").toString(); + HttpServletRequest request = (HttpServletRequest) args[0]; + HttpServletResponse response = (HttpServletResponse) args[1]; + setResponse(response, min, majorVersion, latestMinorVersion, service); + final Map<String, String> errorMap = new HashMap<>(); + ObjectMapper mapper = new ObjectMapper(); + String reason = ""; + try { + if (method != null && obj != null) { + responseObj = method.invoke(obj, args); + } else { + errorMap.put("error", "Requested api is not available"); + reason = mapper.writeValueAsString(errorMap); + response.getWriter().write(reason); + logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI() + + "is not available with minorVersion " + request.getHeader("MinorVersion")); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e); + } + return responseObj; + } + + @Override + public void setApplicationContext(ApplicationContext context) throws BeansException { + this.context = context; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> postUserProfile(HttpServletRequest request, + @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json") + public PortalRestResponse<String> putUserProfile(HttpServletRequest request, + @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json") + public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request, + @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST) + public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response, + @RequestBody String ticketEventJson) throws Exception { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class) + @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response, + @RequestBody EPUser epUser) { + PortalRestResponse<String> result = null; + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class) + @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, + @PathVariable("appId") Long appId) { + OnboardingApp result = new OnboardingApp(); + Map<String, Object> res = getMethod(request, response); + try { + result = (OnboardingApp) invokeMethod(res, request, response, appId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e); + } + return result; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, + @RequestBody OnboardingApp newOnboardApp) { + PortalRestResponse<String> result = new PortalRestResponse<>(); + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class) + @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json") + @ResponseBody + public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response, + @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) { + PortalRestResponse<String> result = new PortalRestResponse<>(); + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e); + return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + } + + @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class) + @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public PortalAPIResponse publishNotification(HttpServletRequest request, + @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) throws Exception { + PortalAPIResponse result = new PortalAPIResponse(true, "success"); + Map<String, Object> res = getMethod(request, response); + try { + result = (PortalAPIResponse) invokeMethod(res, request, response, notificationItem); + return result; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e); + return new PortalAPIResponse(false, e.getMessage()); + } + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List") + @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json") + public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request, + HttpServletResponse response) throws Exception { + List<FavoritesFunctionalMenuItemJson> favorites = null; + Map<String, Object> res = getMethod(request, response); + try { + favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e); + } + return favorites; + } + + @SuppressWarnings("unchecked") + @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List") + @RequestMapping(value = { + "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json") + public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request, + HttpServletResponse response) throws Exception { + List<FunctionalMenuItem> fnMenuItems = null; + Map<String, Object> res = getMethod(request, response); + try { + fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e); + } + return fnMenuItems; + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java index de6ae3cf..e0bf7b01 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java @@ -69,7 +69,6 @@ import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.portal.utils.PortalConstants; import org.onap.portalsdk.core.domain.AuditLog; import org.onap.portalsdk.core.domain.Role; -import org.onap.portalsdk.core.domain.RoleFunction; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.restful.domain.EcompRole; @@ -334,6 +333,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @RequestMapping(value = { "/roleFunction" }, method = RequestMethod.POST, produces = "application/json") public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception { + String status = "Successfully saved!"; try { fieldsValidation(request); String data = roleFunc; @@ -343,7 +343,11 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); CentralV2RoleFunction availableRoleFunction = mapper.readValue(data, CentralV2RoleFunction.class); CentralV2RoleFunction domainRoleFunction = null; + boolean isCentralV2Version = false; if(availableRoleFunction.getType()!=null && availableRoleFunction.getAction()!= null) { + isCentralV2Version = true; + } + if(isCentralV2Version) { String code = availableRoleFunction.getType()+"|"+availableRoleFunction.getCode()+"|"+availableRoleFunction.getAction(); domainRoleFunction = externalAccessRolesService.getRoleFunction(code, requestedApp.getUebKey()); @@ -353,7 +357,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl } boolean saveOrUpdateResponse = false; - if (domainRoleFunction != null && domainRoleFunction.getCode().equals(availableRoleFunction.getCode()) + if (domainRoleFunction != null && isCentralV2Version && domainRoleFunction.getCode().equals(availableRoleFunction.getCode()) && domainRoleFunction.getType().equals(availableRoleFunction.getType()) && domainRoleFunction.getAction().equals(availableRoleFunction.getAction())) { domainRoleFunction.setName(availableRoleFunction.getName()); @@ -363,13 +367,15 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl availableRoleFunction.setAppId(requestedApp.getId()); saveOrUpdateResponse = externalAccessRolesService.saveCentralRoleFunction(availableRoleFunction, requestedApp); - } + } + + if(domainRoleFunction != null) { + status = "Successfully updated!"; + } if (saveOrUpdateResponse) { EPUser user = externalAccessRolesService.getUser(request.getHeader(LOGIN_ID)).get(0); EPApp app = externalAccessRolesService.getApp(request.getHeader(UEBKEY)).get(0); - CentralV2RoleFunction function = externalAccessRolesService - .getRoleFunction(availableRoleFunction.getCode(), request.getHeader(UEBKEY)); - String activityCode = (function.getCode() == null) + String activityCode = (!status.equals("Successfully updated!")) ? EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_ADD_FUNCTION : EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_UPDATE_FUNCTION; logger.info(EELFLoggerDelegate.applicationLogger, "saveRoleFunction: succeeded for app {}, function {}", @@ -401,7 +407,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl "Failed to saveRoleFunction for '" + availableRoleFunction.getCode() + "'", "Failed"); } } catch (Exception e) { - if (e.getMessage().contains(INVALID_UEB_KEY)) { + if (e.getMessage() == null ||e.getMessage().contains(INVALID_UEB_KEY)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); }else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); @@ -409,7 +415,7 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e); return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); } - return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Successfully Saved", "Success"); + return new PortalRestResponse<String>(PortalRestStatusEnum.OK, status, "Success"); } @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json") @@ -731,15 +737,16 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") @RequestMapping(value = { "/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json") - public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request, HttpServletResponse response, @RequestBody List<RoleFunction> upload) throws Exception { + public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception { + Integer addedFunctions = 0; try { - externalAccessRolesService.bulkUploadPartnerFunctions(request.getHeader(UEBKEY), upload); + addedFunctions = externalAccessRolesService.bulkUploadPartnerFunctions(request.getHeader(UEBKEY)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e); return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed"); } - return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Successfully added", "Success"); + return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Successfully added: '"+addedFunctions+"' functions", "Success"); } @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") @@ -757,15 +764,16 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json") @RequestMapping(value = { "/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json") - public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Role> upload) throws Exception { + public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception { + Integer addedRoleFunctions = 0; try { - externalAccessRolesService.bulkUploadPartnerRoleFunctions(request.getHeader(UEBKEY), upload); + addedRoleFunctions = externalAccessRolesService.bulkUploadPartnerRoleFunctions(request.getHeader(UEBKEY)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e); return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed"); } - return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Successfully added", "Success"); + return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "Successfully added: '"+addedRoleFunctions + "' role functions", "Success"); } @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json") diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulVersionController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulVersionController.java new file mode 100644 index 00000000..588a888a --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulVersionController.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.transport.EpNotificationItem; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; +import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class ExternalAppsRestfulVersionController implements BasicAuthenticationController { + + @Autowired + ExternalAppsRestfulController externalAppsRestfulController = new ExternalAppsRestfulController(); + + @ApiVersion(max = "v3", service = "/v3/publishNotification", min = 0,method = "POST") + public PortalAPIResponse publishNotification(HttpServletRequest request,HttpServletResponse response, EpNotificationItem notificationItem) + throws Exception { + return externalAppsRestfulController.publishNotification(request, notificationItem); + } + + @ApiVersion(max = "v3", service = "/v3/getFavorites", min = 0,method = "GET") + public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request, + HttpServletResponse response) throws Exception { + return externalAppsRestfulController.getFavoritesForUser(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/functionalMenuItemsForUser", min = 0,method = "GET") + public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request, + HttpServletResponse response) throws Exception { + return externalAppsRestfulController.getFunctionalMenuItemsForUser(request, response); + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java index afb5de17..f1628e02 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/HealthCheckController.java @@ -48,6 +48,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import org.onap.music.main.MusicUtil; import org.onap.portalapp.controller.EPUnRestrictedBaseController; import org.onap.portalapp.portal.listener.HealthMonitor; import org.onap.portalapp.portal.logging.aop.EPAuditLog; @@ -177,17 +178,29 @@ public class HealthCheckController extends EPUnRestrictedBaseController { dbInfo.dbPermissions = statusOk; } statusCollection.add(dbInfo); + + HealthStatusInfo CassandraStatusInfo = new HealthStatusInfo("Music-Cassandra"); + //CassandraStatusInfo.hostName = EcompPortalUtils.getMyHostName(); + CassandraStatusInfo.ipAddress = MusicUtil.getMyCassaHost(); + + if (!HealthMonitor.isCassandraStatusOk()) { + overallStatus = false; + CassandraStatusInfo.healthCheckStatus = statusDown; + CassandraStatusInfo.description = "Check the logs for more details"; + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckCassandraError); + } + statusCollection.add(CassandraStatusInfo); - HealthStatusInfo uebInfo = new HealthStatusInfo("UEB"); - if (!HealthMonitor.isUebUp()) { - // As per test case review meeting, UEB is considered as - // critical as DB. Hence commenting - // overallStatus = false; - uebInfo.healthCheckStatus = statusDown; - uebInfo.description = "Check the logs for more details"; - EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebConnectionError); + HealthStatusInfo zookeeperStatusInfo = new HealthStatusInfo("Music-zookeeper"); + //zookeeperStatusInfo.hostName = EcompPortalUtils.getMyHostName(); + zookeeperStatusInfo.ipAddress = MusicUtil.getMyZkHost(); + if (!HealthMonitor.isZookeeperStatusOk()) { + overallStatus = false; + zookeeperStatusInfo.healthCheckStatus = statusDown; + zookeeperStatusInfo.description = "Check the logs for more details"; + EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckZookeeperError); } - statusCollection.add(uebInfo); + statusCollection.add(zookeeperStatusInfo); String json = ""; try { diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java index a9f523b6..4956e3fd 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RoleManageController.java @@ -60,6 +60,7 @@ import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.domain.EcompAuditLog; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.ecomp.model.UploadRoleFunctionExtSystem; import org.onap.portalapp.portal.exceptions.DuplicateRecordException; import org.onap.portalapp.portal.exceptions.InvalidApplicationException; import org.onap.portalapp.portal.exceptions.InvalidRoleException; @@ -78,7 +79,6 @@ import org.onap.portalapp.portal.utils.PortalConstants; import org.onap.portalapp.util.EPUserUtils; import org.onap.portalsdk.core.domain.AuditLog; import org.onap.portalsdk.core.domain.Role; -import org.onap.portalsdk.core.domain.RoleFunction; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.service.AuditService; import org.onap.portalsdk.core.util.SystemProperties; @@ -194,7 +194,7 @@ public class RoleManageController extends EPRestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); CentralV2Role domainRole = externalAccessRolesService.getRoleInfo(roleId, requestedApp.getUebKey()); // role. toggle active ind - boolean active = domainRole.isActive(); + boolean active = domainRole.getActive(); domainRole.setActive(!active); String result = mapper.writeValueAsString(domainRole); @@ -329,6 +329,7 @@ public class RoleManageController extends EPRestrictedBaseController { domainRole = new CentralV2Role(); domainRole.setName(role.getName()); domainRole.setPriority(role.getPriority()); + domainRole.setActive(role.getActive()); if (role.getChildRoles() != null && role.getChildRoles().size() > 0) { for (Object childRole : childRoles) { domainRole.addChildRole((CentralV2Role) childRole); @@ -528,27 +529,7 @@ public class RoleManageController extends EPRestrictedBaseController { String activityCode = (isSave) ? EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_ADD_FUNCTION : EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_UPDATE_FUNCTION; - logger.info(EELFLoggerDelegate.applicationLogger, - "saveRoleFunction: succeeded for app {}, function {}", app.getId(), code); - AuditLog auditLog = getAuditInfo(requestedUser, activityCode); - auditLog.setComments(EcompPortalUtils.truncateString("saveRoleFunction role for app:" - + app.getId() + " and function:'" + code + "'", - PortalConstants.AUDIT_LOG_COMMENT_SIZE)); - auditService.logActivity(auditLog, null); - MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, - EPEELFLoggerAdvice.getCurrentDateTimeUTC()); - MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, - EPEELFLoggerAdvice.getCurrentDateTimeUTC()); - EcompPortalUtils.calculateDateTimeDifferenceForLog( - MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP), - MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)); - logger.info(EELFLoggerDelegate.auditLogger, - EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode, - String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(), - code)); - MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP); - MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP); - MDC.remove(SystemProperties.MDC_TIMER); + logExterlaAuthRoleFunctionActivity(code, requestedUser, app, activityCode); } } else throw new NonCentralizedAppException(requestedApp.getName() + " is not Centralized Application"); @@ -564,6 +545,30 @@ public class RoleManageController extends EPRestrictedBaseController { } return new PortalRestResponse<>(PortalRestStatusEnum.OK, "Saved Successfully!", "Success"); } + + private void logExterlaAuthRoleFunctionActivity(String code, EPUser requestedUser, EPApp app, String activityCode) { + logger.info(EELFLoggerDelegate.applicationLogger, + "saveRoleFunction: succeeded for app {}, function {}", app.getId(), code); + AuditLog auditLog = getAuditInfo(requestedUser, activityCode); + auditLog.setComments(EcompPortalUtils.truncateString("saveRoleFunction role for app:" + + app.getId() + " and function:'" + code + "'", + PortalConstants.AUDIT_LOG_COMMENT_SIZE)); + auditService.logActivity(auditLog, null); + MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, + EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, + EPEELFLoggerAdvice.getCurrentDateTimeUTC()); + EcompPortalUtils.calculateDateTimeDifferenceForLog( + MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP), + MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)); + logger.info(EELFLoggerDelegate.auditLogger, + EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode, + String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(), + code)); + MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP); + MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP); + MDC.remove(SystemProperties.MDC_TIMER); + } @@ -733,7 +738,7 @@ public class RoleManageController extends EPRestrictedBaseController { Iterator<CentralV2Role> availableChildRolesIterator = availableChildRoles.iterator(); while (availableChildRolesIterator.hasNext()) { CentralV2Role role = availableChildRolesIterator.next(); - if (!role.isActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) { + if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) { availableChildRolesIterator.remove(); } } @@ -784,4 +789,29 @@ public class RoleManageController extends EPRestrictedBaseController { EcompPortalUtils.setBadPermissions(user, response, "createAdmin"); response.getWriter().write("Unauthorized User"); } + + @RequestMapping(value = { "/portalApi/uploadRoleFunction/{appId}" }, method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> bulkUploadRoleFunc(HttpServletRequest request, HttpServletResponse response, + @RequestBody UploadRoleFunctionExtSystem data, @PathVariable("appId") Long appId) { + EPUser user = EPUserUtils.getUserSession(request); + try { + EPApp app = appService.getApp(appId); + if (isAuthorizedUser(user, app)) { + fieldsValidation(app); + externalAccessRolesService.bulkUploadRoleFunc(data, app); + String activityCode = EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_UPDATE_ROLE_AND_FUNCTION; + String code = data.getName()+","+data.getType()+ PIPE + data.getInstance() + PIPE + data.getAction(); + logExterlaAuthRoleFunctionActivity(code , user, app, activityCode); + } else { + logger.info(EELFLoggerDelegate.auditLogger, + "RoleManageController.syncRoles, Unauthorized user:" + user.getOrgUserId()); + EcompPortalUtils.setBadPermissions(user, response, "createAdmin"); + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Unauthorized User", "Failure"); + } + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed bulkUploadRoleFunc!", e); + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed"); + } + return new PortalRestResponse<>(PortalRestStatusEnum.OK, "Uploaded Role Function successfully!", "Success"); + } } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesApprovalSystemVersionController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesApprovalSystemVersionController.java new file mode 100644 index 00000000..404fb310 --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesApprovalSystemVersionController.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class RolesApprovalSystemVersionController implements BasicAuthenticationController { + + @Autowired + RolesApprovalSystemController rolesApprovalSystemController; + + @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "POST") + public PortalRestResponse<String> postUserProfile(HttpServletRequest request, + HttpServletResponse response, ExternalSystemUser extSysUser) { + return rolesApprovalSystemController.postUserProfile(request, extSysUser, response); + } + + @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "PUT") + public PortalRestResponse<String> putUserProfile(HttpServletRequest request, + HttpServletResponse response, ExternalSystemUser extSysUser) { + return rolesApprovalSystemController.putUserProfile(request, extSysUser, response); + } + + @ApiVersion(max = "v3", service = "/v3/userProfile", min = 0, method = "DELETE") + public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request, + HttpServletResponse response ,ExternalSystemUser extSysUser) { + return rolesApprovalSystemController.deleteUserProfile(request, extSysUser, response); + } +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesController.java new file mode 100644 index 00000000..c61fb43b --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/RolesController.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.transport.CentralUser; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.restful.domain.EcompRole; +import org.onap.portalsdk.core.restful.domain.EcompUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import io.swagger.annotations.ApiOperation; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class RolesController implements BasicAuthenticationController { + + final String LOGINID_PATTERN = "/v3/user/[a-zA-Z0-9]{1,25}$"; + final String FUNCTION_CD_PATTERN = "/v3/function/[a-zA-Z0-9_-]{1,75}$"; + + final String DELETE_ROLEFUNCTION = "/v3/roleFunction/[a-zA-Z0-9_-]{1,75}$"; + + @Autowired + ExternalAccessRolesController externalAccessRolesController = new ExternalAccessRolesController(); + + @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json") + @ApiVersion(max = "v3", service = "/v3/roles", min = 0, method = "GET") + public List<CentralV2Role> getV2RolesForApp(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.getV2RolesForApp(request, response); + } + + @ApiVersion(max = "v3", service = LOGINID_PATTERN, min = 0, method = "GET") + public String getV2UserList(HttpServletRequest request, HttpServletResponse response, String loginId) + throws Exception { + return externalAccessRolesController.getV2UserList(request, response, loginId); + } + + @ApiVersion(max = "v3", service = "/v3/role", min = 0, method = "POST") + public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response, Role role) + throws Exception { + return externalAccessRolesController.saveRole(request, response, role); + } + + @ApiVersion(max = "v3", service = "/v3/role/[0-9]{1,25}$", min = 0, method = "GET") + public CentralV2Role getV2RoleInfo(HttpServletRequest request, HttpServletResponse response, Long roleId) + throws Exception { + return externalAccessRolesController.getV2RoleInfo(request, response, roleId); + } + + @ApiVersion(max = "v3", service = "/v3/users", min = 0, method = "GET") + public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.getUsersOfApplication(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/functions", min = 0, method = "GET") + public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.getV2RoleFunctionsList(request, response); + } + + @ApiVersion(max = "v3", service = FUNCTION_CD_PATTERN, min = 0, method = "GET") + public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response, String code) + throws Exception { + return externalAccessRolesController.getV2RoleFunction(request, response, code); + } + + @ApiVersion(max = "v3", service = "/v3/roleFunction", min = 0, method = "POST") + public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response, + String roleFunc) throws Exception { + return externalAccessRolesController.saveRoleFunction(request, response, roleFunc); + } + + @ApiVersion(max = "v3", service = DELETE_ROLEFUNCTION, min = 0, method = "DELETE") + public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response, + String code) throws Exception { + return externalAccessRolesController.deleteRoleFunction(request, response, code); + } + + @ApiVersion(max = "v3", service = "/v3/deleteRole/[0-9]{1,25}$", min = 0, method = "DELETE") + public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response, Long roleId) + throws Exception { + return externalAccessRolesController.deleteRole(request, response, roleId); + } + + @ApiVersion(max = "v3", service = "/v3/activeRoles", min = 0, method = "GET") + public List<CentralV2Role> getV2ActiveRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.getV2ActiveRoles(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/upload/portal/functions", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.bulkUploadFunctions(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/upload/portal/roles", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.bulkUploadRoles(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/upload/portal/roleFunctions", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.bulkUploadRoleFunctions(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/upload/portal/userRoles", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.bulkUploadUserRoles(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/upload/portal/userRole/[0-9]{1,25}$", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request, + HttpServletResponse response, Long roleId) throws Exception { + return externalAccessRolesController.bulkUploadUsersSingleRole(request, response, roleId); + } + + @ApiVersion(max = "v3", service = "/v3/upload/partner/functions", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request, + HttpServletResponse response) throws Exception { + return externalAccessRolesController.bulkUploadPartnerFunctions(request, response); + } +//not using this + @ApiVersion(max = "v3", service = "/v3/upload/partner/roles", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response, + List<Role> upload) throws Exception { + return externalAccessRolesController.bulkUploadPartnerRoles(request, response, upload); + } + + @ApiVersion(max = "v3", service = "/v3/upload/partner/roleFunctions", min = 0, method = "POST") + public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request, + HttpServletResponse response) throws Exception { + return externalAccessRolesController.bulkUploadPartnerRoleFunctions(request, response); + } + + @ApiVersion(max = "v3", service = "/v3/menuFunctions", min = 0, method = "GET") + public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception { + return externalAccessRolesController.getMenuFunctions(request, response); + } + + @ApiVersion(max = "v4", service = "/v4/user/[a-zA-Z0-9]{1,25}$", min = 0, method = "GET") + public String getEcompUser(HttpServletRequest request, HttpServletResponse response, String loginId) + throws Exception { + return externalAccessRolesController.getEcompUser(request, response, loginId); + } + + @ApiVersion(max = "v4", service = "/v4/roles", min = 0, method = "GET") + public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response) + throws Exception { + return externalAccessRolesController.getEcompRolesOfApplication(request, response); + } +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/TicketEventVersionController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/TicketEventVersionController.java new file mode 100644 index 00000000..cd87507b --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/TicketEventVersionController.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class TicketEventVersionController implements BasicAuthenticationController { + + @Autowired + TicketEventController ticketEventController; + + @ApiVersion(max = "v3", service = "/v3/ticketevent", min = 0, method = "POST") + public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response, + String ticketEventJson) throws Exception { + return ticketEventController.handleRequest(request, response, ticketEventJson); + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppVersionController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppVersionController.java new file mode 100644 index 00000000..952ca75f --- /dev/null +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppVersionController.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + */ +package org.onap.portalapp.portal.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.annotation.ApiVersion; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.transport.Analytics; +import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +@ApiVersion +public class WebAnalyticsExtAppVersionController { + + @Autowired + WebAnalyticsExtAppController webAnalyticsExtAppController; + + @ApiVersion(max = "v3", service = "/v3/analytics", min = 0,method = "GET") + public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception { + return webAnalyticsExtAppController.getAnalyticsScript(request); + } + + @ApiVersion(max = "v3", service = "/v3/storeAnalytics", min = 0,method = "POST") + public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response, Analytics analyticsMap) throws Exception { + return webAnalyticsExtAppController.storeAnalyticsScript(request, analyticsMap); + } + +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java index f43930f6..d05fe014 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/WidgetsCatalogController.java @@ -49,6 +49,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.onap.portalapp.controller.EPRestrictedBaseController; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.domain.MicroserviceParameter; @@ -62,6 +63,7 @@ import org.onap.portalapp.portal.logging.aop.EPAuditLog; import org.onap.portalapp.portal.service.ConsulHealthService; import org.onap.portalapp.portal.service.MicroserviceService; import org.onap.portalapp.portal.service.WidgetParameterService; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.util.EPUserUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -98,6 +100,8 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogController.class); private static final String MS_WIDGET_LOCAL_PORT = "microservices.widget.local.port"; + + private static final String UNAUTHORIZED_OR_FORBIDDEN_FOR_A_DISABLED_USER = "Unauthorized or Forbidden for a disabled user"; private RestTemplate template = new RestTemplate(); @@ -135,7 +139,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { ResponseEntity<List> ans = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + loginName, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), List.class); widgets = ans.getBody(); @@ -155,7 +159,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { ResponseEntity<List> ans = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog", HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), List.class); widgets = ans.getBody(); @@ -215,7 +219,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { respond = template.postForObject( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/" + widgetId, new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class); File f = new File(tmpFolderName + fileName); @@ -236,6 +240,12 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { @RequestMapping(value = { "/portalApi/microservices/widgetCatalog" }, method = RequestMethod.POST) public String createWidgetCatalog(HttpServletRequest request) throws Exception { + + if (StringUtils.isNotBlank(SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_UPLOAD_FLAG)) + && SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_UPLOAD_FLAG).equalsIgnoreCase("false")) { + return UNAUTHORIZED_OR_FORBIDDEN_FOR_A_DISABLED_USER; + } + MultipartHttpServletRequest mRequest; MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>(); String fileName; @@ -260,7 +270,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { respond = template.postForObject( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog", new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class); File f = new File(tmpFolderName + fileName); @@ -314,7 +324,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { Long serviceId = template.exchange( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/widgetCatalog/parameters/" + widgetId, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), Long.class).getBody(); if (serviceId == null) { @@ -361,7 +371,7 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { .exchange( EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, - SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT)) + SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_LOCAL_PORT)) + "/widget/microservices/download/" + widgetId, HttpMethod.GET, new HttpEntity<>(WidgetServiceHeaders.getInstance()), byte[].class) .getBody(); @@ -414,4 +424,16 @@ public class WidgetsCatalogController extends EPRestrictedBaseController { } return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", ""); } + + @RequestMapping(value = { "/portalApi/microservices/uploadFlag" }, method = RequestMethod.GET) + public String getUploadFlag() { + String uplaodFlag=""; + try { + uplaodFlag = SystemProperties.getProperty(EPCommonSystemProperties.MS_WIDGET_UPLOAD_FLAG); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "uploadFlag failed", e); + return null; + } + return uplaodFlag; + } } |