02f237d76d7d742decf1a437a4a16728b45d4cae
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / RoleManageController.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.controller;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
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;
43
44 /**
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.
48  */
49 @RestController
50 @org.springframework.context.annotation.Configuration
51 @EnableAspectJAutoProxy
52 @EPAuditLog
53 public class RoleManageController extends EPRestrictedBaseController {
54         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
55
56         @Autowired
57         private RoleController roleController;
58
59         @Autowired
60         private RoleListController roleListController;
61
62         @Autowired
63         private RoleFunctionListController roleFunctionListController;
64
65
66         @Autowired
67         ExternalAccessRolesService externalAccessRolesService;
68         /**
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.
73          * 
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
76          * string.
77          * 
78          * @param request
79          * @param response
80          */
81         @RequestMapping(value = { "/portalApi/get_roles" }, method = RequestMethod.GET)
82         public void getRoles(HttpServletRequest request, HttpServletResponse response) {
83                 getRoleListController().getRoles(request, response);
84         }
85
86         @RequestMapping(value = { "/portalApi/role_list/toggleRole" }, method = RequestMethod.POST)
87         public PortalRestResponse<String> toggleRole(HttpServletRequest request, HttpServletResponse response) {
88                 PortalRestResponse<String> portalRestResponse = null;
89                 try{
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());
94                 }
95                 return portalRestResponse;              
96         }
97
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);
101         }
102
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);
106         }
107
108         @RequestMapping(value = { "/portalApi/role/removeRoleFunction" }, method = RequestMethod.POST)
109         public ModelAndView removeRoleRoleFunction(HttpServletRequest request, HttpServletResponse response)
110                         throws Exception {
111                 return getRoleController().removeRoleFunction(request, response);
112         }
113
114         @RequestMapping(value = { "/portalApi/role/addRoleFunction" }, method = RequestMethod.POST)
115         public ModelAndView addRoleRoRoleFunction(HttpServletRequest request, HttpServletResponse response)
116                         throws Exception {
117                 return getRoleController().addRoleFunction(request, response);
118         }
119
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);
123         }
124
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);
128         }
129
130         @RequestMapping(value = { "/portalApi/get_role" }, method = RequestMethod.GET)
131         public void getRole(HttpServletRequest request, HttpServletResponse response) throws Exception{
132                 getRoleController().getRole(request, response);
133         }
134
135         @RequestMapping(value = { "/portalApi/get_role_functions" }, method = RequestMethod.GET)
136         public void getRoleFunctionList(HttpServletRequest request, HttpServletResponse response) {
137                 getRoleFunctionListController().getRoleFunctionList(request, response);
138         }
139
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);
143         }
144
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);
148         }
149
150         public RoleListController getRoleListController() {
151                 return roleListController;
152         }
153
154         public void setRoleListController(RoleListController roleListController) {
155                 this.roleListController = roleListController;
156         }
157
158         public RoleController getRoleController() {
159                 return roleController;
160         }
161
162         public void setRoleController(RoleController roleController) {
163                 this.roleController = roleController;
164         }
165
166         public RoleFunctionListController getRoleFunctionListController() {
167                 return roleFunctionListController;
168         }
169
170         public void setRoleFunctionListController(RoleFunctionListController roleFunctionListController) {
171                 this.roleFunctionListController = roleFunctionListController;
172         }
173
174         @RequestMapping(value = { "/portalApi/syncRoles" }, method = RequestMethod.GET)
175         public void  syncRoles(EPApp app)
176         {
177                 try {
178                         externalAccessRolesService.syncApplicationRolesWithEcompDB(app);
179                 } catch (Exception e) {
180                         logger.error(EELFLoggerDelegate.debugLogger, "failed syncRoles");
181                 }
182         }
183 }