2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.controller;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
43 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
44 import org.openecomp.portalapp.controller.core.RoleController;
45 import org.openecomp.portalapp.controller.core.RoleFunctionListController;
46 import org.openecomp.portalapp.controller.core.RoleListController;
47 import org.openecomp.portalapp.portal.domain.EPApp;
48 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
49 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
50 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
51 import org.openecomp.portalapp.portal.service.ExternalAccessRolesService;
52 import org.openecomp.portalapp.portal.service.ExternalAccessRolesServiceImpl;
53 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.context.annotation.EnableAspectJAutoProxy;
56 import org.springframework.web.bind.annotation.RequestBody;
57 import org.springframework.web.bind.annotation.RequestMapping;
58 import org.springframework.web.bind.annotation.RequestMethod;
59 import org.springframework.web.bind.annotation.RestController;
60 import org.springframework.web.servlet.ModelAndView;
63 * Proxies REST calls to role-management functions that arrive on paths
64 * /portalApi/* over to controller methods provided by the SDK-Core library.
65 * Those controller methods are mounted on paths not exposed by the Portal FE.
68 @org.springframework.context.annotation.Configuration
69 @EnableAspectJAutoProxy
71 public class RoleManageController extends EPRestrictedBaseController {
72 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
75 private RoleController roleController;
78 private RoleListController roleListController;
81 private RoleFunctionListController roleFunctionListController;
85 ExternalAccessRolesService externalAccessRolesService;
87 * Calls an SDK-Core library method that gets the available roles and writes
88 * them to the request object. Portal specifies a Hibernate mappings from
89 * the Role class to the fn_role_v view, which ensures that only Portal
90 * (app_id is null) roles are fetched.
92 * Any method declared void (no return value) or returning null causes the
93 * audit log aspect method to declare failure. TODO: should return a JSON
99 @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
100 public void getRoles(HttpServletRequest request, HttpServletResponse response) {
101 getRoleListController().getRoles(request, response);
104 @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
105 public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
106 PortalRestResponse<String> portalRestResponse = null;
108 getRoleListController().toggleRole(request, response);
109 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success", null);
110 }catch (Exception e) {
111 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "failure", e.getMessage());
113 return portalRestResponse;
116 @RequestMapping(value = { "/portalApi/role_list/removeRole" }, method = RequestMethod.POST)
117 public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
118 return getRoleListController().removeRole(request, response);
121 @RequestMapping(value = { "/portalApi/role/saveRole" }, method = RequestMethod.POST)
122 public ModelAndView saveRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
123 return getRoleController().saveRole(request, response);
126 @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
127 public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
129 return getRoleController().removeRoleFunction(request, response);
132 @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
133 public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
135 return getRoleController().addRoleFunction(request, response);
138 @RequestMapping(value = { "/portalApi/role/removeChildRole" }, method = RequestMethod.POST)
139 public ModelAndView removeChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
140 return getRoleController().removeChildRole(request, response);
143 @RequestMapping(value = { "/portalApi/role/addChildRole" }, method = RequestMethod.POST)
144 public ModelAndView addChildRole(HttpServletRequest request, HttpServletResponse response) throws Exception {
145 return getRoleController().addChildRole(request, response);
148 @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
149 public void getRole(HttpServletRequest request, HttpServletResponse response) throws Exception{
150 getRoleController().getRole(request, response);
153 @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
154 public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
155 getRoleFunctionListController().getRoleFunctionList(request, response);
158 @RequestMapping(value = { "/portalApi/role_function_list/saveRoleFunction" }, method = RequestMethod.POST)
159 public void saveRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
160 getRoleFunctionListController().saveRoleFunction(request, response, roleFunc);
163 @RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction" }, method = RequestMethod.POST)
164 public void removeRoleFunction(HttpServletRequest request, HttpServletResponse response, @RequestBody String roleFunc) throws Exception {
165 getRoleFunctionListController().removeRoleFunction(request, response, roleFunc);
168 public RoleListController getRoleListController() {
169 return roleListController;
172 public void setRoleListController(RoleListController roleListController) {
173 this.roleListController = roleListController;
176 public RoleController getRoleController() {
177 return roleController;
180 public void setRoleController(RoleController roleController) {
181 this.roleController = roleController;
184 public RoleFunctionListController getRoleFunctionListController() {
185 return roleFunctionListController;
188 public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
189 this.roleFunctionListController = roleFunctionListController;
192 @RequestMapping(value = { "/portalApi/syncRoles" }, method = RequestMethod.GET)
193 public void syncRoles(EPApp app)
196 externalAccessRolesService.syncApplicationRolesWithEcompDB(app);
197 } catch (Exception e) {
198 logger.error(EELFLoggerDelegate.debugLogger, "failed syncRoles");