2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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.onap.portalapp.portal.controller;
40 import java.util.List;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
45 import org.onap.portalapp.controller.EPRestrictedBaseController;
46 import org.onap.portalapp.portal.controller.PortalAdminController;
47 import org.onap.portalapp.portal.domain.EPRole;
48 import org.onap.portalapp.portal.domain.EPUser;
49 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
50 import org.onap.portalapp.portal.service.AdminRolesService;
51 import org.onap.portalapp.portal.service.PortalAdminService;
52 import org.onap.portalapp.portal.transport.FieldsValidator;
53 import org.onap.portalapp.portal.transport.PortalAdmin;
54 import org.onap.portalapp.portal.utils.EcompPortalUtils;
55 import org.onap.portalapp.util.EPUserUtils;
56 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
57 import org.springframework.beans.factory.annotation.Autowired;
58 import org.springframework.context.annotation.EnableAspectJAutoProxy;
59 import org.springframework.web.bind.annotation.PathVariable;
60 import org.springframework.web.bind.annotation.RequestBody;
61 import org.springframework.web.bind.annotation.RequestMapping;
62 import org.springframework.web.bind.annotation.RequestMethod;
63 import org.springframework.web.bind.annotation.RestController;
66 @org.springframework.context.annotation.Configuration
67 @EnableAspectJAutoProxy
69 public class PortalAdminController extends EPRestrictedBaseController {
71 PortalAdminService portalAdminService;
73 AdminRolesService adminRolesService;
75 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PortalAdminController.class);
77 @RequestMapping(value = { "/portalApi/portalAdmins" }, method = RequestMethod.GET, produces = "application/json")
78 public List<PortalAdmin> getPortalAdmins(HttpServletRequest request, HttpServletResponse response) {
79 EPUser user = EPUserUtils.getUserSession(request);
80 List<PortalAdmin> portalAdmins = null;
82 logger.debug(EELFLoggerDelegate.debugLogger, "PortalAdminController.getPortalAdmins, null user");
83 EcompPortalUtils.setBadPermissions(user, response, "getPortalAdmins");
84 } else if (!adminRolesService.isSuperAdmin(user)) {
85 logger.debug(EELFLoggerDelegate.debugLogger, "PortalAdminController.getPortalAdmins, bad permissions");
86 EcompPortalUtils.setBadPermissions(user, response, "createPortalAdmin");
88 // return the list of portal admins
89 portalAdmins = portalAdminService.getPortalAdmins();
90 logger.debug(EELFLoggerDelegate.debugLogger, "portalAdmins: called getPortalAdmins()");
91 EcompPortalUtils.logAndSerializeObject("/portalApi/getPortalAdmins", "result =", portalAdmins);
98 * RESTful service method to create a new portal admin. Requirement: you
99 * must be the Ecomp portal super admin user.
102 @RequestMapping(value = { "/portalApi/portalAdmin" }, method = RequestMethod.POST)
103 public FieldsValidator createPortalAdmin(HttpServletRequest request, @RequestBody String userid,
104 HttpServletResponse response) {
105 EPUser user = EPUserUtils.getUserSession(request);
106 FieldsValidator fieldsValidator = null;
108 logger.debug(EELFLoggerDelegate.debugLogger, "PortalAdminController.createPortalAdmin, null user");
109 EcompPortalUtils.setBadPermissions(user, response, "createPortalAdmin");
110 } else if (!adminRolesService.isSuperAdmin(user)) {
111 logger.debug(EELFLoggerDelegate.debugLogger, "PortalAdminController.createPortalAdmin bad permissions");
112 EcompPortalUtils.setBadPermissions(user, response, "createPortalAdmin");
114 fieldsValidator = portalAdminService.createPortalAdmin(userid);
115 response.setStatus(fieldsValidator.httpStatusCode.intValue());
117 EcompPortalUtils.logAndSerializeObject("/portalAdmin", "POST result =", response.getStatus());
119 return fieldsValidator;
122 @RequestMapping(value = { "/portalApi/portalAdmin/{orgUserId}" }, method = RequestMethod.DELETE)
123 public FieldsValidator deletePortalAdmin(HttpServletRequest request, @PathVariable("orgUserId") Long orgUserId,
124 HttpServletResponse response) {
125 EPUser user = EPUserUtils.getUserSession(request);
126 FieldsValidator fieldsValidator = null;
127 if (!adminRolesService.isSuperAdmin(user)) {
128 EcompPortalUtils.setBadPermissions(user, response, "deletePortalAdmin");
130 fieldsValidator = portalAdminService.deletePortalAdmin(orgUserId);
131 response.setStatus(fieldsValidator.httpStatusCode.intValue());
133 EcompPortalUtils.logAndSerializeObject("/portalAdmin", "DELETE result =", response.getStatus());
135 return fieldsValidator;
138 @RequestMapping(value = { "/portalApi/adminAppsRoles/{appId}" }, method = RequestMethod.GET, produces = "application/json")
139 public List<EPRole> getRolesByApp(HttpServletRequest request, @PathVariable("appId") Long appId,
140 HttpServletResponse response) {
141 EPUser user = EPUserUtils.getUserSession(request);
142 List<EPRole> rolesByApp = null;
146 EcompPortalUtils.setBadPermissions(user, response, "getUserApps");
148 rolesByApp = adminRolesService.getRolesByApp(user, appId);
150 } catch (Exception e) {
151 logger.error(EELFLoggerDelegate.errorLogger, "getRolesByApp failed", e);