* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.onap.portalapp.portal.transport.ExternalAccessUser;
import org.onap.portalapp.portal.transport.ExternalAccessUserRoleDetail;
import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
-import org.onap.portalapp.portal.transport.ExternalRoleDescription;
import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
import org.onap.portalapp.portal.transport.LocalRole;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
private static final String FUNCTION_PIPE = "|";
- private static final String IS_NULL_STRING = "null";
-
private static final String EXTERNAL_AUTH_PERMS = "perms";
private static final String EXTERNAL_AUTH_ROLE_DESCRIPTION = "description";
private static final String CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE = "Connecting to External Auth system";
- private static final String APP_ROLE_ID = "appRoleId";
-
private static final String APP_ID = "appId";
- private static final String PRIORITY = "priority";
-
- private static final String ACTIVE = "active";
-
private static final String ROLE_NAME = "name";
- private static final String ID = "id";
-
private static final String APP_ID_EQUALS = " app_id = ";
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAccessRolesServiceImpl.class);
* @throws Exception
* If updateRoleInExternalSystem fails we catch it in logger for detail message
*/
- @SuppressWarnings("unchecked")
private boolean updateRoleInExternalSystem(Role updateExtRole, EPApp app, boolean isGlobalRole) throws Exception {
boolean response = false;
ObjectMapper mapper = new ObjectMapper();
ResponseEntity<String> deleteResponse = null;
- HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
List<EPRole> epRoleList = null;
if (app.getId().equals(PortalConstants.PORTAL_APP_ID)
|| (isGlobalRole && !app.getId().equals(PortalConstants.PORTAL_APP_ID))) {
} else {
epRoleList = getPartnerAppRoleInfo(updateExtRole.getId(), app);
}
-
// Assigning functions to global role
if ((isGlobalRole && !app.getId().equals(PortalConstants.PORTAL_APP_ID))) {
List<RoleFunction> globalRoleFunctionListNew = convertSetToListOfRoleFunctions(updateExtRole);
list = mapper.readValue(perms.toString(), TypeFactory.defaultInstance()
.constructCollectionType(List.class, ExternalAccessPerms.class));
}
- ExternalRoleDescription sysRoleList = mapper.readValue(desc, ExternalRoleDescription.class);
// If role name or role functions are updated then delete
// record in External System and add new record to avoid
// conflicts
- Boolean existingRoleActive;
- boolean isActiveValueChanged;
- // check role active status
- existingRoleActive = new Boolean(sysRoleList.getActive());
- isActiveValueChanged = existingRoleActive.equals(updateExtRole.getActive());
boolean isRoleNameChanged = false;
- if (!sysRoleList.getName().equals(updateExtRole.getName())) {
+ if (!desc.equals(updateExtRole.getName())) {
isRoleNameChanged = true;
- Map<String, String> delRoleKeyMapper = new HashMap<>();
- delRoleKeyMapper.put(ROLE_NAME, name);
- String delRoleKeyValue = mapper.writeValueAsString(delRoleKeyMapper);
- deleteResponse = deleteRoleInExternalSystem(delRoleKeyValue);
- if (deleteResponse.getStatusCode().value() != 200) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "updateRoleInExternalSystem: Failed to delete role in external system due to {} ",
- deleteResponse.getBody());
- throw new ExternalAuthSystemException(deleteResponse.getBody());
- }
+ deleteRoleInExtSystem(mapper, name);
addRole(updateExtRole, app.getUebKey());
// add partner functions to the global role in External Auth System
- if(!list.isEmpty() && isGlobalRole){
- addPartnerHasRoleFunctionsToGlobalRole(list, mapper, app, updateExtRole);
+ if (!list.isEmpty() && isGlobalRole) {
+ addPartnerHasRoleFunctionsToGlobalRole(list, mapper, app, updateExtRole);
}
- list.removeIf(perm -> EcompPortalUtils.checkNameSpaceMatching(perm.getType(), app.getNameSpace()));
- // if role name is changes please ignore the previous functions in External Auth and update with user requested functions
- addRemoveFunctionsToRole(updateExtRole, app, mapper, roleFunctionListNew, name,
- list);
+ list.removeIf(
+ perm -> EcompPortalUtils.checkNameSpaceMatching(perm.getType(), app.getNameSpace()));
+ // if role name is changes please ignore the previous functions in External Auth
+ // and update with user requested functions
+ addRemoveFunctionsToRole(updateExtRole, app, mapper, roleFunctionListNew, name, list);
}
- boolean checkPriorityStatus = StringUtils.equals(String.valueOf(sysRoleList.getPriority()),
- String.valueOf(updateExtRole.getPriority()));
- ExternalAccessRole updateRole = new ExternalAccessRole();
- if (!isActiveValueChanged || !checkPriorityStatus || sysRoleList.getId().equals(IS_NULL_STRING)
- || !sysRoleList.getId().equals(String.valueOf(epRoleList.get(0).getId()))) {
- String updateDesc = "";
- List<EPRole> getRole;
- final Map<String, String> getAppRoleByName = new HashMap<>();
- getAppRoleByName.put(APP_ROLE_NAME_PARAM, updateExtRole.getName());
- if (app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
- getRole = dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, getAppRoleByName,
- null);
- } else {
- getAppRoleByName.put("appId", String.valueOf(app.getId()));
- getRole = dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
- getAppRoleByName, null);
- }
- Map<String, String> extSystemUpdateRoleJsonMapper = new LinkedHashMap<>();
- extSystemUpdateRoleJsonMapper.put(ID, String.valueOf(getRole.get(0).getId()));
- extSystemUpdateRoleJsonMapper.put(ROLE_NAME, String.valueOf(updateExtRole.getName()));
- extSystemUpdateRoleJsonMapper.put(ACTIVE, String.valueOf(updateExtRole.getActive()));
- extSystemUpdateRoleJsonMapper.put(PRIORITY, String.valueOf(updateExtRole.getPriority()));
- if (app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
- extSystemUpdateRoleJsonMapper.put(APP_ID, "null");
- extSystemUpdateRoleJsonMapper.put(APP_ROLE_ID, "null");
- } else {
- extSystemUpdateRoleJsonMapper.put(APP_ID, String.valueOf(app.getId()));
- extSystemUpdateRoleJsonMapper.put(APP_ROLE_ID,
- String.valueOf(getRole.get(0).getAppRoleId()));
-
- }
- updateDesc = mapper.writeValueAsString(extSystemUpdateRoleJsonMapper);
- updateRole.setName(app.getNameSpace() + "." + updateExtRole.getName().replaceAll(
- EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
- updateRole.setDescription(updateDesc);
- String updateRoleDesc = mapper.writeValueAsString(updateRole);
- HttpEntity<String> entity = new HttpEntity<>(updateRoleDesc, headers);
- logger.debug(EELFLoggerDelegate.debugLogger, "updateRoleInExternalSystem: {} for PUT: {}",
- CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE, updateRoleDesc);
- ResponseEntity<String> updatePermsResponse = template.exchange(
- SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)
- + "role",
- HttpMethod.PUT, entity, String.class);
- logger.debug(EELFLoggerDelegate.debugLogger,
- "updateRoleInExternalSystem: Finished updating in External Auth system {} and status code: {} ",
- updateRoleDesc, updatePermsResponse.getStatusCode().value());
+ // Delete role in External System if role is inactive
+ if (!updateExtRole.getActive()) {
+ deleteRoleInExtSystem(mapper, name);
}
- if(!isRoleNameChanged) {
+ if (!isRoleNameChanged) {
response = addRemoveFunctionsToRole(updateExtRole, app, mapper, roleFunctionListNew, name,
list);
}
} else {
// It seems like role exists in local DB but not in External
// Access system
- addRole(updateExtRole, app.getUebKey());
- List<RoleFunction> roleFunctionListUpdate = convertSetToListOfRoleFunctions(updateExtRole);
- response = true;
- if (!roleFunctionListUpdate.isEmpty()) {
- addRoleFunctionsInExternalSystem(updateExtRole, mapper, app);
+ if (updateExtRole.getActive()) {
+ addRole(updateExtRole, app.getUebKey());
+ ExternalAccessRolePerms extAddRolePerms = null;
+ ExternalAccessPerms extAddPerms = null;
+ List<RoleFunction> roleFunctionListAdd = convertSetToListOfRoleFunctions(updateExtRole);
+ HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
+ for (RoleFunction roleFunc : roleFunctionListAdd) {
+ extAddPerms = new ExternalAccessPerms(app.getNameSpace() + "." + roleFunc.getType(),
+ roleFunc.getCode(), roleFunc.getAction());
+ extAddRolePerms = new ExternalAccessRolePerms(extAddPerms,
+ app.getNameSpace() + "." + updateExtRole.getName().replaceAll(
+ EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
+ response = addRoleFuncExtSysRestAPI(mapper, extAddRolePerms, headers);
+ }
}
}
}
return response;
}
+ private void deleteRoleInExtSystem(ObjectMapper mapper, String name)
+ throws JsonProcessingException, Exception, ExternalAuthSystemException {
+ ResponseEntity<String> deleteResponse;
+ Map<String, String> delRoleKeyMapper = new HashMap<>();
+ delRoleKeyMapper.put(ROLE_NAME, name);
+ String delRoleKeyValue = mapper.writeValueAsString(delRoleKeyMapper);
+ deleteResponse = deleteRoleInExternalSystem(delRoleKeyValue);
+ if (deleteResponse.getStatusCode().value() != 200) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "updateRoleInExternalSystem: Failed to delete role in external system due to {} ",
+ deleteResponse.getBody());
+ throw new ExternalAuthSystemException(deleteResponse.getBody());
+ }
+ }
+
private boolean addRemoveFunctionsToRole(Role updateExtRole, EPApp app, ObjectMapper mapper,
List<RoleFunction> roleFunctionListNew, String name, List<ExternalAccessPerms> list) throws Exception {
boolean response;
}
}
- /**
- *
- * It adds functions to the role in external auth system
- *
- * @param updateExtRole
- * @param addPermsMapper
- * @param app
- * @return true if success else false
- * @throws Exception
- */
- private boolean addRoleFunctionsInExternalSystem(Role updateExtRole, ObjectMapper addPermsMapper, EPApp app)
- throws Exception {
- boolean response = false;
- ExternalAccessRolePerms extAddRolePerms = null;
- ExternalAccessPerms extAddPerms = null;
- List<RoleFunction> roleFunctionListAdd = convertSetToListOfRoleFunctions(updateExtRole);
- HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
- for (RoleFunction roleFunc : roleFunctionListAdd) {
- String code = "";
- String type= "";
- String action = "";
- if (roleFunc.getCode().contains(FUNCTION_PIPE)) {
- code = EcompPortalUtils.getFunctionCode(roleFunc.getCode());
- type = getFunctionCodeType(roleFunc.getCode());
- action = getFunctionCodeAction(roleFunc.getCode());
- } else {
- code = roleFunc.getCode();
- type = roleFunc.getCode().contains("menu") ? "menu" : "url";
- action = "*";
- }
- extAddPerms = new ExternalAccessPerms(app.getNameSpace() + "." + type, code, action);
- extAddRolePerms = new ExternalAccessRolePerms(extAddPerms,
- app.getNameSpace() + "." + updateExtRole.getName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
- String updateRolePerms = addPermsMapper.writeValueAsString(extAddRolePerms);
- HttpEntity<String> entity = new HttpEntity<>(updateRolePerms, headers);
- logger.debug(EELFLoggerDelegate.debugLogger, "addRoleFunctionsInExternalSystem: {} for POST: {} " , CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE, updateRolePerms);
- ResponseEntity<String> addResponse = template.exchange(
- SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "role/perm",
- HttpMethod.POST, entity, String.class);
- if (addResponse.getStatusCode().value() != 201) {
- response = false;
- logger.debug(EELFLoggerDelegate.debugLogger,
- "addRoleFunctionsInExternalSystem: While adding permission to the role in External Auth system something went wrong! due to {} and statuscode: {}",
- addResponse.getStatusCode().getReasonPhrase(), addResponse.getStatusCode().value());
- } else {
- response = true;
- logger.debug(EELFLoggerDelegate.debugLogger, "addRoleFunctionsInExternalSystem: Finished adding permissions to roles in External Auth system {} and status code: {} ", updateRolePerms, addResponse.getStatusCode().value());
- }
+ private boolean addRoleFuncExtSysRestAPI(ObjectMapper addPermsMapper, ExternalAccessRolePerms extAddRolePerms,
+ HttpHeaders headers) throws JsonProcessingException {
+ boolean response;
+ String updateRolePerms = addPermsMapper.writeValueAsString(extAddRolePerms);
+ HttpEntity<String> entity = new HttpEntity<>(updateRolePerms, headers);
+ logger.debug(EELFLoggerDelegate.debugLogger, "addRoleFunctionsInExternalSystem: {} for POST: {} " , CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE, updateRolePerms);
+ ResponseEntity<String> addResponse = template.exchange(
+ SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "role/perm",
+ HttpMethod.POST, entity, String.class);
+ if (addResponse.getStatusCode().value() != 201 && addResponse.getStatusCode().value() != 409) {
+ response = false;
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "addRoleFunctionsInExternalSystem: While adding permission to the role in External Auth system something went wrong! due to {} and statuscode: {}",
+ addResponse.getStatusCode().getReasonPhrase(), addResponse.getStatusCode().value());
+ } else {
+ response = true;
+ logger.debug(EELFLoggerDelegate.debugLogger, "addRoleFunctionsInExternalSystem: Finished adding permissions to roles in External Auth system {} and status code: {} ", updateRolePerms, addResponse.getStatusCode().value());
}
return response;
}
ObjectMapper mapper = new ObjectMapper();
String addNewRole = "";
ExternalAccessRole extRole = new ExternalAccessRole();
- String addDesc = null;
- Map<String, String> extSystemJsonMapper = new LinkedHashMap<>();
- extSystemJsonMapper.put(ID, String.valueOf(newRole.get(0).getId()));
- extSystemJsonMapper.put(ROLE_NAME, String.valueOf(newRole.get(0).getName()));
- extSystemJsonMapper.put(ACTIVE, String.valueOf(newRole.get(0).getActive()));
- extSystemJsonMapper.put(PRIORITY, String.valueOf(newRole.get(0).getPriority()));
- extSystemJsonMapper.put(APP_ID, String.valueOf(newRole.get(0).getAppId()));
- extSystemJsonMapper.put(APP_ROLE_ID, String.valueOf(newRole.get(0).getAppRoleId()));
- addDesc = mapper.writeValueAsString(extSystemJsonMapper);
extRole.setName(app.getNameSpace() + "." + newRole.get(0).getName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
- extRole.setDescription(addDesc);
+ extRole.setDescription(String.valueOf(newRole.get(0).getName()));
addNewRole = mapper.writeValueAsString(extRole);
HttpEntity<String> postEntity = new HttpEntity<>(addNewRole, headers);
logger.debug(EELFLoggerDelegate.debugLogger, "addNewRoleInExternalSystem: {} for POST: {} " , CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE, addNewRole);
ObjectMapper mapper = new ObjectMapper();
String addNewRole = "";
ExternalAccessRole extRole = new ExternalAccessRole();
- List<EPRole> role = null;
- String addDesc = null;
- Map<String, String> extSystemUpdateRole = new LinkedHashMap<>();
- if (app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
- role = getPortalAppRoleInfo(addRole.getId());
- } else {
- role = getPartnerAppRoleInfo(addRole.getId(), app);
- }
- extSystemUpdateRole.put(ID, String.valueOf(role.get(0).getId()));
- extSystemUpdateRole.put(ROLE_NAME, String.valueOf(addRole.getName()));
- extSystemUpdateRole.put(ACTIVE, String.valueOf(role.get(0).getActive()));
- extSystemUpdateRole.put(PRIORITY, String.valueOf(role.get(0).getPriority()));
- extSystemUpdateRole.put(APP_ID, String.valueOf(role.get(0).getAppId()));
- extSystemUpdateRole.put(APP_ROLE_ID, String.valueOf(role.get(0).getAppRoleId()));
- addDesc = mapper.writeValueAsString(extSystemUpdateRole);
extRole.setName(app.getNameSpace() + "." + addRole.getName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
- extRole.setDescription(addDesc);
+ extRole.setDescription(String.valueOf(addRole.getName()));
addNewRole = mapper.writeValueAsString(extRole);
return addNewRole;
}
*/
@SuppressWarnings("unchecked")
@Transactional(rollbackFor = Exception.class)
- private boolean addRoleInEcompDB(Role addRoleInDB, EPApp app) throws Exception {
+ public boolean addRoleInEcompDB(Role addRoleInDB, EPApp app) throws Exception {
boolean result = false;
EPRole epRole = null;
Set<RoleFunction> roleFunctionList = addRoleInDB.getRoleFunctions();
if (EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) {
addNewRoleInExternalSystem(getRoleCreated, app);
}
+ result = true;
} else { // if role already exists then update it
EPRole globalRole = null;
List<EPRole> applicationRoles;
*/
@SuppressWarnings("unchecked")
private CentralV2User createEPUser(EPUser userInfo, Set<EPUserApp> userAppSet, EPApp app) throws Exception {
-
final Map<String, Long> params = new HashMap<>();
CentralV2User userAppList = new CentralV2User();
CentralV2User user1 = null;
final Map<String, Long> params1 = new HashMap<>();
List<EPRole> globalRoleList = new ArrayList<>();
-
try {
if (app.getId() != PortalConstants.PORTAL_APP_ID) {
params1.put("userId", userInfo.getId());
String deleteRoleKey = "{\"name\":\"" + app.getNameSpace() + "." + epRoleList.get(0).getName()
.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_") + "\"}";
deleteResponse = deleteRoleInExternalSystem(deleteRoleKey);
- if (deleteResponse.getStatusCode().value() != 200 || deleteResponse.getStatusCode().value() != 404) {
+ if (deleteResponse.getStatusCode().value() != 200 && deleteResponse.getStatusCode().value() != 404) {
EPLogUtil.logExternalAuthAccessAlarm(logger, deleteResponse.getStatusCode());
logger.error(EELFLoggerDelegate.errorLogger,
"deleteRoleForApplication: Failed to delete role in external auth system! due to {} ",
if (extPerms.getJSONObject(i).has("description")) {
description = extPerms.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION);
} else {
- description = extPerms.getJSONObject(i).getString("instance");
+ description = extPerms.getJSONObject(i).getString("type")+"|"+extPerms.getJSONObject(i).getString("instance")
+ +"|"+extPerms.getJSONObject(i).getString("action");
}
if (extPerms.getJSONObject(i).has("roles")) {
ObjectMapper rolesListMapper = new ObjectMapper();
roleParams.put(APP_ROLE_NAME_PARAM, role);
List<EPRole> roleCreated = null;
if (app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
- roleCreated = dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams,
+ roleCreated = dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, roleParams,
null);
} else {
roleParams.put("appId", String.valueOf(app.getId()));
applicationRolesList = getAppRoles(app.getId());
List<String> applicationRoleIdList = new ArrayList<>();
for (EPRole applicationRole : applicationRolesList) {
- applicationRoleIdList.add(applicationRole.getName());
+ applicationRoleIdList.add(applicationRole.getName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
}
List<EPRole> roleListToBeAddInEcompDB = new ArrayList<>();
logger.debug(EELFLoggerDelegate.debugLogger, "Entering into inactiveRolesNotInExternalAuthSystem");
// Check if roles exits in external Access system and if not make inactive in DB
inactiveRolesNotInExternalAuthSystem(app, finalRoleList, applicationRolesList);
-
- logger.debug(EELFLoggerDelegate.debugLogger, "Entering into checkAndUpdateRoleInDB");
- // It checks properties in the external auth system app role description and updates role in local
- checkAndUpdateRoleInDB(app, finalRoleList);
-
logger.debug(EELFLoggerDelegate.debugLogger, "Entering into addNewRoleInEcompDBUpdateDescInExtAuthSystem");
// Add new roles in DB and updates role description in External Auth System
addNewRoleInEcompDBUpdateDescInExtAuthSystem(app, roleListToBeAddInEcompDB);
}
}
- /**
- *
- * It checks description in External Auth System if found any changes updates in DB
- *
- * @param app
- * @param finalRoleList contains list of External Auth System roles list which is converted to EPRole
- */
- @SuppressWarnings("unchecked")
- private void checkAndUpdateRoleInDB(EPApp app, List<EPRole> finalRoleList) {
- for (EPRole roleItem : finalRoleList) {
- final Map<String, String> roleParams = new HashMap<>();
- List<EPRole> currentList = null;
- roleParams.put(APP_ROLE_NAME_PARAM, roleItem.getName());
- if (app.getId() == 1) {
- currentList = dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, roleParams, null);
- } else {
- roleParams.put(APP_ID, app.getId().toString());
- currentList = dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null);
- }
-
- if (!currentList.isEmpty()) {
- try {
- Boolean aafRoleActive;
- Boolean localRoleActive;
- boolean result;
- aafRoleActive = Boolean.valueOf(roleItem.getActive());
- localRoleActive = Boolean.valueOf(currentList.get(0).getActive());
- result = aafRoleActive.equals(localRoleActive);
- EPRole updateRole = currentList.get(0);
-
- if (!result) {
- updateRole.setActive(roleItem.getActive());
- dataAccessService.saveDomainObject(updateRole, null);
- }
- if (roleItem.getPriority() != null
- && !currentList.get(0).getPriority().equals(roleItem.getPriority())) {
- updateRole.setPriority(roleItem.getPriority());
- dataAccessService.saveDomainObject(updateRole, null);
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "syncApplicationRolesWithEcompDB: Failed to update role ", e);
- }
- }
- }
- }
/**
*
* It de-activates application roles in DB if not present in External Auth system
final Map<String, String> extRoleParams = new HashMap<>();
List<EPRole> roleList = null;
extRoleParams.put(APP_ROLE_NAME_PARAM, role.getName());
- if (!checkRolesInactive.containsKey(role.getName())) {
+ if (!checkRolesInactive.containsKey(role.getName().replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"))) {
if (app.getId() == 1) {
roleList = dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, extRoleParams, null);
} else {
ObjectMapper mapper, JSONArray extRole)
throws IOException {
List<ExternalRoleDetails> externalRoleDetailsList = new ArrayList<>();
- ExternalRoleDescription ApplicationRole = new ExternalRoleDescription();
- ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms();
+ ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms();
List<String> functionCodelist = new ArrayList<>();
+ Map<String, EPRole> curRolesMap = getCurrentRolesInDB(app);
for (int i = 0; i < extRole.length(); i++) {
ExternalRoleDetails externalRoleDetail = new ExternalRoleDetails();
EPAppRoleFunction ePAppRoleFunction = new EPAppRoleFunction();
JSONObject Role = (JSONObject) extRole.get(i);
- if (!extRole.getJSONObject(i).has(EXTERNAL_AUTH_ROLE_DESCRIPTION)) {
- ApplicationRole.setActive("true");
- ApplicationRole.setAppId(IS_NULL_STRING);
- ApplicationRole.setPriority(IS_NULL_STRING);
- ApplicationRole.setAppRoleId(IS_NULL_STRING);
- String roleName = extRole.getJSONObject(i).getString(ROLE_NAME);
- ApplicationRole.setName(roleName.substring(app.getNameSpace().length() + 1));
- } else {
- String desc = extRole.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION);
- ApplicationRole = mapper.readValue(desc, ExternalRoleDescription.class);
- }
-
+ String name = extRole.getJSONObject(i).getString(ROLE_NAME);
+ String actualRoleName = name.substring(app.getNameSpace().length() + 1);
SortedSet<ExternalAccessPerms> externalAccessPermsOfRole = new TreeSet<>();
if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_PERMS)) {
JSONArray extPerm = (JSONArray) Role.get(EXTERNAL_AUTH_PERMS);
for (int j = 0; j < extPerm.length(); j++) {
JSONObject perms = extPerm.getJSONObject(j);
- boolean isNamespaceMatching = EcompPortalUtils.checkNameSpaceMatching(perms.getString("type"), app.getNameSpace());
+ boolean isNamespaceMatching = EcompPortalUtils.checkNameSpaceMatching(perms.getString("type"),
+ app.getNameSpace());
if (isNamespaceMatching) {
externalAccessPerms = new ExternalAccessPerms(perms.getString("type"),
perms.getString("instance"), perms.getString("action"));
}
}
-
- if (ApplicationRole.getActive().equals(IS_NULL_STRING)) {
- externalRoleDetail.setActive(false);
- } else {
- externalRoleDetail.setActive(Boolean.parseBoolean(ApplicationRole.getActive()));
- }
- externalRoleDetail.setName(ApplicationRole.getName());
-
- if (ApplicationRole.getAppId().equals(IS_NULL_STRING) && app.getId() == 1) {
+ externalRoleDetail.setActive(true);
+ externalRoleDetail.setName(actualRoleName);
+ if (app.getId() == 1) {
externalRoleDetail.setAppId(null);
- } else if (ApplicationRole.getAppId().equals(IS_NULL_STRING)) {
- externalRoleDetail.setAppId(app.getId());
- } else {
- externalRoleDetail.setAppId(Long.parseLong(ApplicationRole.getAppId()));
- }
-
- if (ApplicationRole.getPriority().equals(IS_NULL_STRING)) {
- externalRoleDetail.setPriority(null);
} else {
- externalRoleDetail.setPriority(Integer.parseInt(ApplicationRole.getPriority()));
- }
-
- if (ApplicationRole.getAppRoleId().equals(IS_NULL_STRING) && app.getId() == 1) {
- externalRoleDetail.setAppRoleId(null);
+ externalRoleDetail.setAppId(app.getId());
}
-
+ // get role functions from DB
+ EPRole currRole = curRolesMap.get(actualRoleName
+ .replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
+ Long roleId = null;
+ if (currRole != null)
+ roleId = currRole.getId();
// get role functions from DB
final Map<String, EPAppRoleFunction> roleFunctionsMap = new HashMap<>();
- if (!ApplicationRole.getId().equals(IS_NULL_STRING)) {
- final Map<String, Long> appRoleFuncsParams = new HashMap<>();
+ final Map<String, Long> appRoleFuncsParams = new HashMap<>();
+ if (roleId != null) {
appRoleFuncsParams.put("appId", app.getId());
- appRoleFuncsParams.put("roleId", Long.valueOf(ApplicationRole.getId()));
- List<EPAppRoleFunction> appRoleFunctions = dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null);
+ appRoleFuncsParams.put("roleId", roleId);
+ List<EPAppRoleFunction> appRoleFunctions = dataAccessService
+ .executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null);
if (!appRoleFunctions.isEmpty()) {
for (EPAppRoleFunction roleFunc : appRoleFunctions) {
roleFunctionsMap.put(roleFunc.getCode(), roleFunc);
}
}
}
-
if (!externalAccessPermsOfRole.isEmpty()) {
// Adding functions to role
for (ExternalAccessPerms externalpermission : externalAccessPermsOfRole) {
EPAppRoleFunction checkRoleFunctionPipeExits = roleFunctionsMap.get(funcCode);
if (checkRoleFunctionPipeExits == null) {
try {
- final Map<String, String> appFuncsParams = new HashMap<>();
+ final Map<String, String> appFuncsParams = new HashMap<>();
appFuncsParams.put("appId", String.valueOf(app.getId()));
appFuncsParams.put("functionCd", externalpermission.getInstance());
logger.debug(EELFLoggerDelegate.debugLogger,
"SyncApplicationRolesWithEcompDB: Adding function to the role: {}",
externalpermission.getInstance());
List<CentralV2RoleFunction> roleFunction = null;
- roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null);
+ roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId",
+ appFuncsParams, null);
if (roleFunction.isEmpty()) {
appFuncsParams.put("functionCd", funcCode);
- roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null);
+ roleFunction = dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId",
+ appFuncsParams, null);
}
if (!roleFunction.isEmpty()) {
EPAppRoleFunction apRoleFunction = new EPAppRoleFunction();
apRoleFunction.setAppId(app.getId());
- apRoleFunction.setRoleId(Long.parseLong(ApplicationRole.getId()));
+ apRoleFunction.setRoleId(roleId);
apRoleFunction.setCode(roleFunction.get(0).getCode());
dataAccessService.saveDomainObject(apRoleFunction, null);
}
logger.debug(EELFLoggerDelegate.debugLogger,
"syncApplicationRolesWithEcompDB: Finished GET roles from External Auth system and the result is :",
res);
+ if(res == null || res.trim().isEmpty())
+ return null;
+
JSONObject jsonObj = new JSONObject(res);
JSONArray extRole = jsonObj.getJSONArray("userRole");
*/
private EPRole convertExternalRoleDetailstoEpRole(ExternalRoleDetails externalRoleDetails) {
EPRole role = new EPRole();
- role.setActive(externalRoleDetails.isActive());
+ role.setActive(true);
role.setAppId(externalRoleDetails.getAppId());
role.setAppRoleId(externalRoleDetails.getAppRoleId());
role.setName(externalRoleDetails.getName());