XSS Vulnerability fix in AuxApiRequestMapperController
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / AuxApiRequestMapperController.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  */
37 package org.onap.portalapp.portal.controller;
38
39 import com.fasterxml.jackson.databind.ObjectMapper;
40 import io.swagger.annotations.ApiOperation;
41 import java.lang.reflect.InvocationTargetException;
42 import java.lang.reflect.Method;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49 import java.util.jar.Attributes;
50 import java.util.regex.Matcher;
51 import java.util.regex.Pattern;
52 import javax.servlet.http.HttpServletRequest;
53 import javax.servlet.http.HttpServletResponse;
54 import org.onap.aaf.cadi.aaf.AAFPermission;
55 import org.onap.portalapp.annotation.ApiVersion;
56 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
57 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
60 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
61 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
62 import org.onap.portalapp.portal.service.ManifestService;
63 import org.onap.portalapp.portal.transport.Analytics;
64 import org.onap.portalapp.portal.transport.CentralUser;
65 import org.onap.portalapp.portal.transport.CentralV2Role;
66 import org.onap.portalapp.portal.transport.EpNotificationItem;
67 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
68 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
69 import org.onap.portalapp.portal.transport.OnboardingApp;
70 import org.onap.portalapp.validation.DataValidator;
71 import org.onap.portalapp.validation.SecureString;
72 import org.onap.portalsdk.core.domain.Role;
73 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
74 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
75 import org.onap.portalsdk.core.restful.domain.EcompRole;
76 import org.onap.portalsdk.core.restful.domain.EcompUser;
77 import org.springframework.beans.BeansException;
78 import org.springframework.beans.factory.annotation.Autowired;
79 import org.springframework.context.ApplicationContext;
80 import org.springframework.context.ApplicationContextAware;
81 import org.springframework.context.annotation.Configuration;
82 import org.springframework.context.annotation.EnableAspectJAutoProxy;
83 import org.springframework.web.bind.annotation.PathVariable;
84 import org.springframework.web.bind.annotation.RequestBody;
85 import org.springframework.web.bind.annotation.RequestMapping;
86 import org.springframework.web.bind.annotation.RequestMethod;
87 import org.springframework.web.bind.annotation.RequestParam;
88 import org.springframework.web.bind.annotation.ResponseBody;
89 import org.springframework.web.bind.annotation.RestController;
90
91 @RestController
92 @RequestMapping("/auxapi")
93 @Configuration
94 @EnableAspectJAutoProxy
95 @EPAuditLog
96 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
97
98         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
99         private DataValidator dataValidator = new DataValidator();
100
101         ApplicationContext context = null;
102         int minorVersion = 0;
103
104         @Autowired
105         private ManifestService manifestService;
106
107         @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
108         @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
109         public String getUser(HttpServletRequest request, HttpServletResponse response,
110                         @PathVariable("loginId") String loginId) throws Exception {
111                 if (loginId!=null){
112                         SecureString secureLoginId = new SecureString(loginId);
113                         if (!dataValidator.isValid(secureLoginId))
114                                 return "Provided data is not valid";
115                 }
116
117
118                 Map<String, Object> res = getMethod(request, response);
119                 String answer = null;
120                 try {
121                         answer = (String) invokeMethod(res, request, response, loginId);
122                 } catch (Exception e) {
123                         logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
124                 }
125                 return answer;
126         }
127
128         @SuppressWarnings("unchecked")
129         @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
130         @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
131         public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
132                 Map<String, Object> res = getMethod(request, response);
133                 request.getMethod();
134                 List<CentralV2Role> answer = null;
135                 try {
136                         answer = (List<CentralV2Role>) invokeMethod(res, request, response);
137                 } catch (Exception e) {
138                         logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
139                 }
140                 return answer;
141         }
142
143         @SuppressWarnings("unchecked")
144         @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
145         @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
146         public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
147                         @RequestBody Role role) throws Exception {
148                 Map<String, Object> res = getMethod(request, response);
149                 PortalRestResponse<String> out = null;
150                 try {
151                         out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
152                 } catch (Exception e) {
153                         logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
154                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
155                 }
156                 return out;
157         }
158
159         @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
160         @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
161         public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
162                         @PathVariable("role_id") Long roleId) throws Exception {
163                 Map<String, Object> res = getMethod(request, response);
164                 CentralV2Role role = null;
165                 try {
166                         role = (CentralV2Role) invokeMethod(res, request, response, roleId);
167                 } catch (Exception e) {
168                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
169                 }
170                 return role;
171
172         }
173
174         @SuppressWarnings("unchecked")
175         @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
176         @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
177         public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
178                         throws Exception {
179                 Map<String, Object> res = getMethod(request, response);
180                 List<EcompUser> users = null;
181                 try {
182                         users = (List<EcompUser>) invokeMethod(res, request, response);
183                 } catch (Exception e) {
184                         logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
185                 }
186                 return users;
187         }
188
189         @SuppressWarnings("unchecked")
190         @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
191         @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
192         public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
193                         throws Exception {
194                 Map<String, Object> res = getMethod(request, response);
195                 List<CentralV2RoleFunction> roleFunctionsList = null;
196                 try {
197                         roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
198                 } catch (Exception e) {
199                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
200                 }
201                 return roleFunctionsList;
202         }
203
204         @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
205         @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
206         public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
207                         @PathVariable("code") String code) throws Exception {
208                 if (code!=null){
209                         SecureString secureCode = new SecureString(code);
210                         if (!dataValidator.isValid(secureCode))
211                                 return new CentralV2RoleFunction();
212                 }
213
214                 Map<String, Object> res = getMethod(request, response);
215                 CentralV2RoleFunction roleFunction = null;
216                 try {
217                         roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
218                 } catch (Exception e) {
219                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
220                 }
221                 return roleFunction;
222         }
223
224         @SuppressWarnings("unchecked")
225         @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
226         @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
227         public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
228                         @RequestBody String roleFunc) throws Exception {
229                 PortalRestResponse<String> result = null;
230
231                 if (roleFunc!=null){
232                         SecureString secureRoleFunc = new SecureString(roleFunc);
233                         if(!dataValidator.isValid(secureRoleFunc))
234                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
235                 }
236
237                 Map<String, Object> res = getMethod(request, response);
238                 try {
239                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleFunc);
240                         return result;
241                 } catch (Exception e) {
242                         logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
243                         return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
244                 }
245         }
246
247         @SuppressWarnings("unchecked")
248         @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
249         @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
250         public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
251                         @PathVariable("code") String code) throws Exception {
252                 PortalRestResponse<String> result = null;
253
254                 if (code!=null){
255                         SecureString secureCode = new SecureString(code);
256                         if(!dataValidator.isValid(secureCode))
257                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
258                 }
259
260                 Map<String, Object> res = getMethod(request, response);
261                 try {
262                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
263                         return result;
264                 } catch (Exception e) {
265                         logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
266                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
267                 }
268         }
269
270         @SuppressWarnings("unchecked")
271         @ApiOperation(value = "deletes  roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
272         @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
273         public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
274                         @PathVariable("roleId") Long roleId) throws Exception {
275                 PortalRestResponse<String> result = null;
276                 Map<String, Object> res = getMethod(request, response);
277                 try {
278                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
279                         return result;
280                 } catch (Exception e) {
281                         logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
282                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
283                 }
284         }
285
286         @SuppressWarnings("unchecked")
287         @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
288         @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
289         public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
290                         throws Exception {
291                 List<CentralV2Role> cenRole = null;
292                 Map<String, Object> res = getMethod(request, response);
293                 try {
294                         cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
295                 } catch (Exception e) {
296                         logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
297                 }
298                 return cenRole;
299         }
300
301         @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
302         @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
303         public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
304                         @PathVariable("loginId") String loginId) throws Exception {
305                 Map<String, Object> res = getMethod(request, response);
306
307                 if (loginId!=null){
308                         SecureString secureLoginId = new SecureString(loginId);
309
310                         if (!dataValidator.isValid(secureLoginId))
311                                 return null;
312                 }
313
314                 String answer = null;
315                 try {
316                         answer = (String) invokeMethod(res, request, response, loginId);
317                 } catch (Exception e) {
318                         logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
319                 }
320                 return answer;
321         }
322
323         @SuppressWarnings("unchecked")
324         @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
325         @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
326         public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
327                         throws Exception {
328                 Map<String, Object> res = getMethod(request, response);
329                 List<EcompRole> answer = null;
330                 try {
331                         answer = (List<EcompRole>) invokeMethod(res, request, response);
332                 } catch (Exception e) {
333                         logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
334                 }
335                 return answer;
336         }
337
338         @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
339         @RequestMapping(value = {
340                         "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
341         public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
342                         throws Exception {
343                 Map<String, Object> res = getMethod(request, response);
344                 Integer ans = null;
345                 try {
346                         ans = (Integer) invokeMethod(res, request, response);
347                 } catch (Exception e) {
348                         logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
349                 }
350                 return ans;
351         }
352
353         @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
354         @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
355         public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
356                         @RequestParam String sessionMap) throws Exception {
357
358                 if (sessionMap!=null){
359                         SecureString secureSessionMap = new SecureString(sessionMap);
360                         if (!dataValidator.isValid(secureSessionMap)){
361                                 return null;
362                         }
363                 }
364
365                 Map<String, Object> res = getMethod(request, response);
366                 Boolean ans = null;
367                 try {
368                         ans = (Boolean) invokeMethod(res, request, response, sessionMap);
369                 } catch (Exception e) {
370                         logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
371                 }
372                 return ans;
373         }
374
375         @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
376         @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
377         public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
378                 Map<String, Object> res = getMethod(request, response);
379                 String ans = null;
380                 try {
381                         ans = (String) invokeMethod(res, request, response);
382                 } catch (Exception e) {
383                         logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
384                 }
385                 return ans;
386         }
387
388         @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
389         @ResponseBody
390         @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
391         public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
392                         @RequestBody Analytics analyticsMap) throws Exception {
393
394                 if (analyticsMap!=null){
395                         if (!dataValidator.isValid(analyticsMap))
396                                 return new PortalAPIResponse(false, "analyticsScript is not valid");
397                 }
398
399                 Map<String, Object> res = getMethod(request, response);
400                 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
401                 try {
402                         ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
403                 } catch (Exception e) {
404                         logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
405                 }
406                 return ans;
407
408         }
409
410         @SuppressWarnings("unchecked")
411         @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
412         @RequestMapping(value = {
413                         "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
414         public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
415                         throws Exception {
416                 PortalRestResponse<String> result = null;
417                 Map<String, Object> res = getMethod(request, response);
418                 try {
419                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
420                         return result;
421                 } catch (Exception e) {
422                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
423                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
424                 }
425
426         }
427
428         @SuppressWarnings("unchecked")
429         @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
430         @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
431         public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
432                         throws Exception {
433                 PortalRestResponse<String> result = null;
434                 Map<String, Object> res = getMethod(request, response);
435                 try {
436                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
437                         return result;
438                 } catch (Exception e) {
439                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
440                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
441                 }
442         }
443
444         @SuppressWarnings("unchecked")
445         @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
446         @RequestMapping(value = {
447                         "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
448         public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
449                         throws Exception {
450                 PortalRestResponse<String> result = null;
451                 Map<String, Object> res = getMethod(request, response);
452                 try {
453                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
454                         return result;
455                 } catch (Exception e) {
456                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
457                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
458                 }
459         }
460
461         @SuppressWarnings("unchecked")
462         @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
463         @RequestMapping(value = {
464                         "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
465         public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
466                         throws Exception {
467                 PortalRestResponse<String> result = null;
468                 Map<String, Object> res = getMethod(request, response);
469                 try {
470                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
471                         return result;
472                 } catch (Exception e) {
473                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
474                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
475                 }
476
477         }
478
479         @SuppressWarnings("unchecked")
480         @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
481         @RequestMapping(value = {
482                         "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
483         public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
484                         HttpServletResponse response, @PathVariable Long roleId) throws Exception {
485                 PortalRestResponse<String> result = null;
486                 Map<String, Object> res = getMethod(request, response);
487                 try {
488                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
489                         return result;
490                 } catch (Exception e) {
491                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
492                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
493                 }
494         }
495
496         @SuppressWarnings("unchecked")
497         @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
498         @RequestMapping(value = {
499                         "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
500         public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
501                         HttpServletResponse response) throws Exception {
502                 PortalRestResponse<String> result = null;
503                 Map<String, Object> res = getMethod(request, response);
504                 try {
505                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
506                         return result;
507                 } catch (Exception e) {
508                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
509                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
510                 }
511         }
512
513         // not using
514         @SuppressWarnings("unchecked")
515         @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
516         @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
517         public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
518                         @RequestBody List<Role> upload) throws Exception {
519                 PortalRestResponse<String> result = null;
520                 Map<String, Object> res = getMethod(request, response);
521                 try {
522                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, upload);
523                         return result;
524                 } catch (Exception e) {
525                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
526                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
527                 }
528         }
529
530         @SuppressWarnings("unchecked")
531         @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
532         @RequestMapping(value = {
533                         "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
534         public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
535                         HttpServletResponse response) throws Exception {
536                 PortalRestResponse<String> result = null;
537                 Map<String, Object> res = getMethod(request, response);
538                 try {
539                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
540                         return result;
541                 } catch (Exception e) {
542                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
543                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
544                 }
545         }
546
547         @SuppressWarnings("unchecked")
548         @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
549         @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
550         public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
551                 List<String> functionsList = null;
552                 Map<String, Object> res = getMethod(request, response);
553                 try {
554                         functionsList = (List<String>) invokeMethod(res, request, response);
555                 } catch (Exception e) {
556                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
557                 }
558                 return functionsList;
559         }
560
561         private String getPatchNumber() {
562                 String response = "0";
563                 try {
564                         Attributes attributes = manifestService.getWebappManifest();
565                         response = attributes.getValue("Build-Number");
566                 } catch (Exception ex) {
567                         logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
568                 }
569                 return response;
570         }
571
572         @SuppressWarnings("rawtypes")
573         private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
574                 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
575                 @SuppressWarnings("unchecked")
576                 List<Object> beansList = new ArrayList(beans.values());
577                 return beansList;
578
579         }
580
581         private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
582                 Method finalmethod = null;
583                 String url = request.getRequestURI();
584                 String version = "";
585                 String service = "";
586                 Object currentObject = null;
587                 Map<String, Object> res = new HashMap<String, Object>();
588                 String[] uriArray = url.split("/auxapi");
589                 List<Integer> minorversionList = new ArrayList<>();
590                 if (uriArray.length > 1) {
591                         service = uriArray[1];
592                 }
593                 int first = service.indexOf("/");
594                 int second = service.indexOf("/", first + 1);
595                 version = service.substring(first + 1, second);
596                 int min = minorVersion;
597                 if (request.getHeader("MinorVersion") != null) {
598                         min = Integer.parseInt(request.getHeader("MinorVersion"));
599                 }
600                 res.put("min", version+"."+min);
601                 res.put("service", service);
602                 List<Object> objList = getObject(request, response);
603                 String requestedApiMethodType = request.getMethod();
604                 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
605                 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
606                 res.put("majorVersion", majorVersion);
607                 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
608                 outerloop: for (Object obj : objList) {
609                         final List<Method> allMethods = getAllMethodsOfClass(obj);
610                         for (final Method method : allMethods) {
611                                 if (method.isAnnotationPresent(ApiVersion.class)) {
612                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
613                                         Pattern p = Pattern.compile(annotInstance.service(),
614                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
615                                         Matcher matcher = p.matcher(service);
616                                         boolean b = matcher.matches();
617                                         logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
618                                                         + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
619                                         if (annotInstance.max().equals(version) && b && annotInstance.min() == min
620                                                         && annotInstance.method().equals(request.getMethod())) {
621                                                 finalmethod = method;
622                                                 currentObject = obj;
623                                                 res.put("method", method);
624                                                 res.put("Obj", obj);
625                                                 break outerloop;
626                                         }
627                                 }
628                         }
629                 }
630                 return res;
631         }
632
633         private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
634                         String requestedApiMethodType) {
635                 Integer majorVersion = 0;
636                 String serviceEndPoint = service;
637                 int firstindex = serviceEndPoint.indexOf("/");
638                 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
639                 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
640
641                 List<Integer> latestMajorVersionList = new ArrayList<>();
642                 for (Object obj : objList) {
643                         final List<Method> allMethods = getAllMethodsOfClass(obj);
644                         for (final Method method : allMethods) {
645                                 if (method.isAnnotationPresent(ApiVersion.class)) {
646                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
647                                         String endpoint = annotInstance.service();
648                                         int first = endpoint.indexOf("/");
649                                         int second = endpoint.indexOf("/", first + 1);
650                                         endpoint = endpoint.substring(second + 1);
651                                         Pattern p = Pattern.compile(endpoint,
652                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
653                                         Matcher matcher = p.matcher(serviceEndPoint);
654                                         boolean b = matcher.matches();
655                                         if (b && annotInstance.method().equals(requestedApiMethodType)) {
656                                                 int index1 = annotInstance.service().indexOf("/");
657                                                 int index2 = annotInstance.service().indexOf("/", index1 + 1);
658                                                 String majorversion = annotInstance.service().substring(index1 + 2, index2);
659                                                 latestMajorVersionList.add(Integer.parseInt(majorversion));
660                                         }
661                                 }
662                         }
663                 }
664                 majorVersion = Collections.max(latestMajorVersionList);
665                 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
666                 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
667                 return majorVersion+"."+latestMinorVersion;
668         }
669
670         private List<Method> getAllMethodsOfClass(Object obj) {
671                 List<Method> allMethods = new ArrayList<>();
672                 Class<?> objClz = obj.getClass();
673                 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
674                         objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
675                 }
676                 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
677                 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
678                 return allMethods;
679         }
680
681         private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
682                         String requestedApiMethodType) {
683                 Integer minVersion = 0;
684                 String serviceEndPoint = service;
685                 List<Integer> latestMinorVersionList = new ArrayList<>();
686                 for (Object obj : objList) {
687                         final List<Method> allMethods = getAllMethodsOfClass(obj);
688                         for (final Method method : allMethods) {
689                                 if (method.isAnnotationPresent(ApiVersion.class)) {
690                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
691                                         String endpoint = annotInstance.service();
692
693                                         Pattern p = Pattern.compile(endpoint,
694                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
695                                         Matcher matcher = p.matcher(serviceEndPoint);
696                                         boolean b = matcher.matches();
697                                         if (annotInstance.max().equals(reuqestedVersion) && b
698                                                         && annotInstance.method().equals(requestedApiMethodType)) {
699                                                 int minorversion = annotInstance.min();
700                                                 latestMinorVersionList.add(minorversion);
701                                         }
702                                 }
703                         }
704                 }
705                 minVersion = Collections.max(latestMinorVersionList);
706                 return minVersion;
707         }
708
709         private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
710                         String majorVersion, String latestMinorVersion, String service) {
711                 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
712                 response.setHeader("X-PatchVersion", getPatchNumber());
713                 response.setHeader("X-LatestVersion", "V"+majorVersion);
714                 return response;
715         }
716
717         /**
718          * 
719          * @param res
720          * @param args
721          *            method parameters(Maintain HttpServletRequest at 0th position
722          *            and HttpServletResponse at 1th position in args array)
723          * @return
724          * @throws Exception
725          */
726         private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
727                 Method method = (Method) res.get("method");
728                 Object obj = res.get("Obj");
729                 Object responseObj = null;
730                 String min = res.get("min").toString();
731                 String majorVersion = res.get("majorVersion").toString();
732                 String latestMinorVersion = res.get("latestMinorVersion").toString();
733                 String service = res.get("service").toString();
734                 HttpServletRequest request = (HttpServletRequest) args[0];
735                 HttpServletResponse response = (HttpServletResponse) args[1];
736                 setResponse(response, min, majorVersion, latestMinorVersion, service);
737                 final Map<String, String> errorMap = new HashMap<>();
738                 ObjectMapper mapper = new ObjectMapper();
739                 String reason = "";
740                 try {
741                         if (method != null && obj != null) {
742                                 responseObj = method.invoke(obj, args);
743                         } else {
744                                 errorMap.put("error", "Requested api is not available");
745                                 reason = mapper.writeValueAsString(errorMap);
746                                 response.getWriter().write(reason);
747                                 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
748                                                 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
749                                 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
750                         }
751                 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
752                         logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
753                 }
754                 return responseObj;
755         }
756
757         @Override
758         public void setApplicationContext(ApplicationContext context) throws BeansException {
759                 this.context = context;
760         }
761
762         @SuppressWarnings("unchecked")
763         @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
764         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
765         public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
766                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
767
768                 if (extSysUser!=null){
769                         if (!dataValidator.isValid(extSysUser))
770                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
771                 }
772
773                 PortalRestResponse<String> result = null;
774                 Map<String, Object> res = getMethod(request, response);
775                 try {
776                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
777                         return result;
778                 } catch (Exception e) {
779                         logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
780                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
781                 }
782         }
783
784         @SuppressWarnings("unchecked")
785         @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
786         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
787         public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
788                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
789
790                 if (extSysUser!=null){
791                         if (!dataValidator.isValid(extSysUser))
792                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
793                 }
794
795                 PortalRestResponse<String> result = null;
796                 Map<String, Object> res = getMethod(request, response);
797                 try {
798                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
799                         return result;
800                 } catch (Exception e) {
801                         logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
802                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
803                 }
804         }
805
806         @SuppressWarnings("unchecked")
807         @ApiOperation(value = "Processes a request to delete one or more application roles for one      specified user who has roles.", response = PortalRestResponse.class)
808         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
809         public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
810                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
811
812                 if (extSysUser!=null){
813                         if (!dataValidator.isValid(extSysUser))
814                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
815                 }
816
817                 PortalRestResponse<String> result = null;
818                 Map<String, Object> res = getMethod(request, response);
819                 try {
820                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
821                         return result;
822                 } catch (Exception e) {
823                         logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
824                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
825                 }
826         }
827
828         @SuppressWarnings("unchecked")
829         @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
830         @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
831         public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
832                         @RequestBody String ticketEventJson) throws Exception {
833
834                 if (ticketEventJson!=null){
835                         SecureString secureTicketEventJson = new SecureString(ticketEventJson);
836                         if (!dataValidator.isValid(secureTicketEventJson))
837                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
838                 }
839
840                 PortalRestResponse<String> result = null;
841                 Map<String, Object> res = getMethod(request, response);
842                 try {
843                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
844                         return result;
845                 } catch (Exception e) {
846                         logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
847                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
848                 }
849         }
850
851         @SuppressWarnings("unchecked")
852         @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
853         @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
854         @ResponseBody
855         public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
856                         @RequestBody EPUser epUser) {
857
858                 if (epUser!=null){
859                         if (!dataValidator.isValid(epUser))
860                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
861                 }
862
863                 PortalRestResponse<String> result = null;
864                 Map<String, Object> res = getMethod(request, response);
865                 try {
866                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
867                         return result;
868                 } catch (Exception e) {
869                         logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
870                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
871                 }
872         }
873
874         @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
875         @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
876         @ResponseBody
877         public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
878                         @PathVariable("appId") Long appId) {
879                 OnboardingApp result = new OnboardingApp();
880                 Map<String, Object> res = getMethod(request, response);
881                 try {
882                         result = (OnboardingApp) invokeMethod(res, request, response, appId);
883                 } catch (Exception e) {
884                         logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
885                 }
886                 return result;
887         }
888
889         @SuppressWarnings("unchecked")
890         @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
891         @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
892         @ResponseBody
893         public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
894                         @RequestBody OnboardingApp newOnboardApp) {
895
896                 if (newOnboardApp!=null){
897                         if (!dataValidator.isValid(newOnboardApp))
898                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
899                 }
900
901                 PortalRestResponse<String> result = new PortalRestResponse<>();
902                 Map<String, Object> res = getMethod(request, response);
903                 try {
904                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
905                         return result;
906                 } catch (Exception e) {
907                         logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
908                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
909                 }
910
911         }
912
913         @SuppressWarnings("unchecked")
914         @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
915         @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
916         @ResponseBody
917         public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
918                         @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
919
920                 if (oldOnboardApp!=null){
921                         if (!dataValidator.isValid(oldOnboardApp))
922                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
923                 }
924
925                 PortalRestResponse<String> result;
926                 Map<String, Object> res = getMethod(request, response);
927                 try {
928                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
929                         return result;
930                 } catch (Exception e) {
931                         logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
932                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
933                 }
934         }
935
936         @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
937         @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
938         @ResponseBody
939         public PortalAPIResponse publishNotification(HttpServletRequest request,
940                         @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
941
942                 if (notificationItem!=null){
943                         if (!dataValidator.isValid(notificationItem))
944                                 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
945                 }
946
947                 Map<String, Object> res = getMethod(request, response);
948                 try {
949                         return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
950                 } catch (Exception e) {
951                         logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
952                         return new PortalAPIResponse(false, e.getMessage());
953                 }
954         }
955
956         @SuppressWarnings("unchecked")
957         @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
958         @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
959         public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
960                         HttpServletResponse response) throws Exception {
961                 List<FavoritesFunctionalMenuItemJson> favorites = null;
962                 Map<String, Object> res = getMethod(request, response);
963                 try {
964                         favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
965                 } catch (Exception e) {
966                         logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
967                 }
968                 return favorites;
969         }
970
971         @SuppressWarnings("unchecked")
972         @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
973         @RequestMapping(value = {
974                         "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
975         public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
976                         HttpServletResponse response) throws Exception {
977                 List<FunctionalMenuItem> fnMenuItems = null;
978                 Map<String, Object> res = getMethod(request, response);
979                 try {
980                         fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
981                 } catch (Exception e) {
982                         logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
983                 }
984                 return fnMenuItems;
985         }
986
987         
988         @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
989         @RequestMapping(value = { "/v3/systemUser" }, method = RequestMethod.GET, produces = "application/json")
990         public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
991                 List<AAFPermission> permsList = null;
992                 Map<String, Object> res = getMethod(request, response);
993                 try {
994                         permsList = (List<AAFPermission>) invokeMethod(res, request, response);
995                 } catch (Exception e) {
996                         logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
997                 }
998                 return permsList;
999         }
1000         
1001         @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1002         @RequestMapping(value = { "/v3/update/app/roleDescription" }, method = RequestMethod.PUT, produces = "application/json")
1003         public  PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1004                 PortalRestResponse<String> result = null;
1005                 Map<String, Object> res = getMethod(request, response);
1006                 try {
1007                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1008                         return result;
1009                 } catch (Exception e) {
1010                         logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1011                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
1012                 }
1013         }
1014 }