*
* ============LICENSE_END============================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.portalapp.portal.controller;
import org.onap.portalapp.portal.domain.EcompAuditLog;
import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.onap.portalapp.portal.ecomp.model.UploadRoleFunctionExtSystem;
import org.onap.portalapp.portal.exceptions.DuplicateRecordException;
import org.onap.portalapp.portal.exceptions.InvalidApplicationException;
import org.onap.portalapp.portal.exceptions.InvalidRoleException;
@EnableAspectJAutoProxy
@EPAuditLog
public class RoleManageController extends EPRestrictedBaseController {
+ private static final String PIPE = "|";
+
private static final String ROLE_INVALID_CHARS = "%=():,\"\"";
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleManageController.class);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
CentralV2Role domainRole = externalAccessRolesService.getRoleInfo(roleId, requestedApp.getUebKey());
// role. toggle active ind
- boolean active = domainRole.isActive();
+ boolean active = domainRole.getActive();
domainRole.setActive(!active);
String result = mapper.writeValueAsString(domainRole);
List<CentralV2Role> roles = externalAccessRolesService.getRolesForApp(requestedApp.getUebKey());
for (CentralV2Role existRole : roles)
if (existRole.getName().equalsIgnoreCase(role.getName()))
- throw new DuplicateRecordException("role already exists: " + existRole.getName());
+ throw new DuplicateRecordException("Role already exists: " + existRole.getName());
domainRole = new CentralV2Role();
domainRole.setName(role.getName());
domainRole.setPriority(role.getPriority());
+ domainRole.setActive(role.getActive());
if (role.getChildRoles() != null && role.getChildRoles().size() > 0) {
for (Object childRole : childRoles) {
domainRole.addChildRole((CentralV2Role) childRole);
+ " and action: " + roleFunction.getAction() + " found while saving!");
}
roleFunction.setCode(externalAccessRolesService.encodeFunctionCode(roleFunction.getCode()));
- roleFunction.setCode(roleFunction.getType() + "|" + roleFunction.getCode() + "|"
+ roleFunction.setCode(roleFunction.getType() + PIPE + roleFunction.getCode() + PIPE
+ roleFunction.getAction());
domainRole.addRoleFunction((CentralV2RoleFunction) roleFunction);
}
if (isAuthorizedUser(user, requestedApp)) {
fieldsValidation(requestedApp);
if (requestedApp.getCentralAuth()) {
- CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(roleFunc.getCode(),
+ String code = roleFunc.getType()+PIPE+roleFunc.getCode()+PIPE+roleFunc.getAction();
+ CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(code,
requestedApp.getUebKey());
+ if(domainRoleFunction != null && (domainRoleFunction.getType() == null || domainRoleFunction.getAction() == null)) {
+ addIfTypeActionDoesNotExits(domainRoleFunction);
+ }
+ boolean isSave = true;
if (domainRoleFunction != null && domainRoleFunction.getCode().equals(roleFunc.getCode())
&& domainRoleFunction.getType().equals(roleFunc.getType())
&& domainRoleFunction.getAction().equals(roleFunc.getAction())) {
domainRoleFunction.setName(roleFunc.getName());
saveOrUpdateResponse = externalAccessRolesService.saveCentralRoleFunction(domainRoleFunction,
requestedApp);
+ isSave = false;
} else {
roleFunc.setAppId(requestedApp.getId());
saveOrUpdateResponse = externalAccessRolesService.saveCentralRoleFunction(roleFunc,
if (saveOrUpdateResponse) {
EPUser requestedUser = externalAccessRolesService.getUser(user.getOrgUserId()).get(0);
EPApp app = externalAccessRolesService.getApp(requestedApp.getUebKey()).get(0);
- CentralV2RoleFunction function = externalAccessRolesService.getRoleFunction(roleFunc.getCode(),
- requestedApp.getUebKey());
- String activityCode = (function.getCode() == null)
+ String activityCode = (isSave)
? EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_ADD_FUNCTION
: EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_UPDATE_FUNCTION;
- logger.info(EELFLoggerDelegate.applicationLogger,
- "saveRoleFunction: succeeded for app {}, function {}", app.getId(), roleFunc.getCode());
- AuditLog auditLog = getAuditInfo(requestedUser, activityCode);
- auditLog.setComments(EcompPortalUtils.truncateString("saveRoleFunction role for app:"
- + app.getId() + " and function:'" + roleFunc.getCode() + "'",
- PortalConstants.AUDIT_LOG_COMMENT_SIZE));
- auditService.logActivity(auditLog, null);
- MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
- EPEELFLoggerAdvice.getCurrentDateTimeUTC());
- EcompPortalUtils.calculateDateTimeDifferenceForLog(
- MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
- MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
- logger.info(EELFLoggerDelegate.auditLogger,
- EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode,
- String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(),
- roleFunc.getCode()));
- MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
- MDC.remove(SystemProperties.MDC_TIMER);
+ logExterlaAuthRoleFunctionActivity(code, requestedUser, app, activityCode);
}
} else
throw new NonCentralizedAppException(requestedApp.getName() + " is not Centralized Application");
}
return new PortalRestResponse<>(PortalRestStatusEnum.OK, "Saved Successfully!", "Success");
}
+
+ private void logExterlaAuthRoleFunctionActivity(String code, EPUser requestedUser, EPApp app, String activityCode) {
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "saveRoleFunction: succeeded for app {}, function {}", app.getId(), code);
+ AuditLog auditLog = getAuditInfo(requestedUser, activityCode);
+ auditLog.setComments(EcompPortalUtils.truncateString("saveRoleFunction role for app:"
+ + app.getId() + " and function:'" + code + "'",
+ PortalConstants.AUDIT_LOG_COMMENT_SIZE));
+ auditService.logActivity(auditLog, null);
+ MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
+ EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+ EcompPortalUtils.calculateDateTimeDifferenceForLog(
+ MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
+ MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
+ logger.info(EELFLoggerDelegate.auditLogger,
+ EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode,
+ String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(),
+ code));
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
+ MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
+ MDC.remove(SystemProperties.MDC_TIMER);
+ }
+
+
+
+ private void addIfTypeActionDoesNotExits(CentralV2RoleFunction domainRoleFunction) {
+ if(domainRoleFunction.getCode().contains(PIPE)) {
+ String newfunctionCodeFormat = EcompPortalUtils.getFunctionCode(domainRoleFunction.getCode());
+ String newfunctionTypeFormat = EcompPortalUtils.getFunctionType(domainRoleFunction.getCode());
+ String newfunctionActionFormat = EcompPortalUtils.getFunctionAction(domainRoleFunction.getCode());
+ domainRoleFunction.setType(newfunctionTypeFormat);
+ domainRoleFunction.setAction(newfunctionActionFormat);
+ domainRoleFunction.setCode(newfunctionCodeFormat);
+ } else {
+ String type = externalAccessRolesService.getFunctionCodeType(domainRoleFunction.getCode());
+ String action = externalAccessRolesService.getFunctionCodeAction(domainRoleFunction.getCode());
+ domainRoleFunction.setType(type);
+ domainRoleFunction.setAction(action);
+ }
+ }
@RequestMapping(value = { "/portalApi/role_function_list/removeRoleFunction/{appId}" }, method = RequestMethod.POST)
public PortalRestResponse<String> removeRoleFunction(HttpServletRequest request, HttpServletResponse response,
String data = roleFunc;
boolean getDelFuncResponse = false;
CentralV2RoleFunction availableRoleFunction = mapper.readValue(data, CentralV2RoleFunction.class);
- String code = availableRoleFunction.getType() + "|" + availableRoleFunction.getCode() + "|"
+ String code = availableRoleFunction.getType() + PIPE + availableRoleFunction.getCode() + PIPE
+ availableRoleFunction.getAction();
CentralV2RoleFunction domainRoleFunction = externalAccessRolesService.getRoleFunction(code,
requestedApp.getUebKey());
- if (domainRoleFunction.getCode().contains("|")) {
- getDelFuncResponse = externalAccessRolesService
- .deleteCentralRoleFunction(code, requestedApp);
- } else {
- getDelFuncResponse = externalAccessRolesService
- .deleteCentralRoleFunction(domainRoleFunction.getCode(), requestedApp);
- }
+ getDelFuncResponse = externalAccessRolesService
+ .deleteCentralRoleFunction(domainRoleFunction.getCode(), requestedApp);
if (getDelFuncResponse) {
logger.info(EELFLoggerDelegate.applicationLogger,
"deleteRoleFunction: succeeded for app {}, role {}", requestedApp.getId(),
Iterator<CentralV2Role> availableChildRolesIterator = availableChildRoles.iterator();
while (availableChildRolesIterator.hasNext()) {
CentralV2Role role = availableChildRolesIterator.next();
- if (!role.isActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) {
+ if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) {
availableChildRolesIterator.remove();
}
}
EcompPortalUtils.setBadPermissions(user, response, "createAdmin");
response.getWriter().write("Unauthorized User");
}
+
+ @RequestMapping(value = { "/portalApi/uploadRoleFunction/{appId}" }, method = RequestMethod.POST, produces = "application/json")
+ public PortalRestResponse<String> bulkUploadRoleFunc(HttpServletRequest request, HttpServletResponse response,
+ @RequestBody UploadRoleFunctionExtSystem data, @PathVariable("appId") Long appId) {
+ EPUser user = EPUserUtils.getUserSession(request);
+ try {
+ EPApp app = appService.getApp(appId);
+ if (isAuthorizedUser(user, app)) {
+ fieldsValidation(app);
+ externalAccessRolesService.bulkUploadRoleFunc(data, app);
+ String activityCode = EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_UPDATE_ROLE_AND_FUNCTION;
+ String code = data.getName()+","+data.getType()+ PIPE + data.getInstance() + PIPE + data.getAction();
+ logExterlaAuthRoleFunctionActivity(code , user, app, activityCode);
+ } else {
+ logger.info(EELFLoggerDelegate.auditLogger,
+ "RoleManageController.syncRoles, Unauthorized user:" + user.getOrgUserId());
+ EcompPortalUtils.setBadPermissions(user, response, "createAdmin");
+ return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Unauthorized User", "Failure");
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Failed bulkUploadRoleFunc!", e);
+ return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
+ }
+ return new PortalRestResponse<>(PortalRestStatusEnum.OK, "Uploaded Role Function successfully!", "Success");
+ }
}