2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.portal.controller;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
25 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
26 import org.openecomp.portalapp.controller.core.RoleController;
27 import org.openecomp.portalapp.controller.core.RoleFunctionListController;
28 import org.openecomp.portalapp.controller.core.RoleListController;
29 import org.openecomp.portalapp.portal.domain.EPApp;
30 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
31 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
32 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
33 import org.openecomp.portalapp.portal.service.ExternalAccessRolesService;
34 import org.openecomp.portalapp.portal.service.ExternalAccessRolesServiceImpl;
35 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.EnableAspectJAutoProxy;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RequestMethod;
41 import org.springframework.web.bind.annotation.RestController;
42 import org.springframework.web.servlet.ModelAndView;
45 * Proxies REST calls to role-management functions that arrive on paths
46 * /portalApi/* over to controller methods provided by the SDK-Core library.
47 * Those controller methods are mounted on paths not exposed by the Portal FE.
50 @org.springframework.context.annotation.Configuration
51 @EnableAspectJAutoProxy
53 public class RoleManageController extends EPRestrictedBaseController {
54 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
57 private RoleController roleController;
60 private RoleListController roleListController;
63 private RoleFunctionListController roleFunctionListController;
67 ExternalAccessRolesService externalAccessRolesService;
69 * Calls an SDK-Core library method that gets the available roles and writes
70 * them to the request object. Portal specifies a Hibernate mappings from
71 * the Role class to the fn_role_v view, which ensures that only Portal
72 * (app_id is null) roles are fetched.
74 * Any method declared void (no return value) or returning null causes the
75 * audit log aspect method to declare failure. TODO: should return a JSON
81 @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
82 public void getRoles(HttpServletRequest request, HttpServletResponse response) {
83 getRoleListController().getRoles(request, response);
86 @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
87 public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
88 PortalRestResponse<String> portalRestResponse = null;
90 getRoleListController().toggleRole(request, response);
91 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", null);
92 }catch (Exception e) {
93 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "failure", e.getMessage());
95 return portalRestResponse;
98 @RequestMapping(value = { "/portalApi/role_list/removeRole" }, method = RequestMethod.POST)
99 public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
100 return getRoleListController().removeRole(request, response);
103 @RequestMapping(value = { "/portalApi/role/saveRole" }, method = RequestMethod.POST)
104 public ModelAndView saveRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
105 return getRoleController().saveRole(request, response);
108 @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
109 public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
111 return getRoleController().removeRoleFunction(request, response);
114 @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
115 public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
117 return getRoleController().addRoleFunction(request, response);
120 @RequestMapping(value = { "/portalApi/role/removeChildRole" }, method = RequestMethod.POST)
121 public ModelAndView removeChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
122 return getRoleController().removeChildRole(request, response);
125 @RequestMapping(value = { "/portalApi/role/addChildRole" }, method = RequestMethod.POST)
126 public ModelAndView addChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
127 return getRoleController().addChildRole(request, response);
130 @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
131 public void getRole(HttpServletRequest request, HttpServletResponse response) throws Exception{
132 getRoleController().getRole(request, response);
135 @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
136 public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
137 getRoleFunctionListController().getRoleFunctionList(request, response);
140 @RequestMapping(value = { "/portalApi/role_function_list/saveRoleFunction" }, method = RequestMethod.POST)
141 public void saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
142 getRoleFunctionListController().saveRoleFunction(request, response, roleFunc);
145 @RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction" }, method = RequestMethod.POST)
146 public void removeRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
147 getRoleFunctionListController().removeRoleFunction(request, response, roleFunc);
150 public RoleListController getRoleListController() {
151 return roleListController;
154 public void setRoleListController(RoleListController roleListController) {
155 this.roleListController = roleListController;
158 public RoleController getRoleController() {
159 return roleController;
162 public void setRoleController(RoleController roleController) {
163 this.roleController = roleController;
166 public RoleFunctionListController getRoleFunctionListController() {
167 return roleFunctionListController;
170 public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
171 this.roleFunctionListController = roleFunctionListController;
174 @RequestMapping(value = { "/portalApi/syncRoles" }, method = RequestMethod.GET)
175 public void syncRoles(EPApp app)
178 externalAccessRolesService.SyncApplicationRolesWithEcompDB(app);
179 } catch (Exception e) {
180 logger.error(EELFLoggerDelegate.debugLogger, "failed syncRoles");