import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Hex;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.onap.portalapp.portal.logging.aop.EPAuditLog;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
import org.onap.portalapp.portal.logging.logic.EPLogUtil;
-import org.onap.portalapp.portal.transport.BulkUploadRoleFunction;
-import org.onap.portalapp.portal.transport.BulkUploadUserRoles;
-import org.onap.portalapp.portal.transport.CentralApp;
-import org.onap.portalapp.portal.transport.CentralRole;
-import org.onap.portalapp.portal.transport.CentralRoleFunction;
-import org.onap.portalapp.portal.transport.CentralUser;
-import org.onap.portalapp.portal.transport.CentralUserApp;
-import org.onap.portalapp.portal.transport.CentralV2Role;
-import org.onap.portalapp.portal.transport.CentralV2User;
-import org.onap.portalapp.portal.transport.CentralV2UserApp;
-import org.onap.portalapp.portal.transport.CentralizedAppRoles;
-import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles;
-import org.onap.portalapp.portal.transport.EcompUserRoles;
-import org.onap.portalapp.portal.transport.ExternalAccessPerms;
-import org.onap.portalapp.portal.transport.ExternalAccessPermsDetail;
-import org.onap.portalapp.portal.transport.ExternalAccessRole;
-import org.onap.portalapp.portal.transport.ExternalAccessRolePerms;
-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.GlobalRoleWithApplicationRoleFunction;
-import org.onap.portalapp.portal.transport.LocalRole;
+import org.onap.portalapp.portal.transport.*;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
import org.onap.portalapp.portal.utils.EcompPortalUtils;
import org.onap.portalapp.portal.utils.PortalConstants;
logger.debug(EELFLoggerDelegate.debugLogger, "getSingleAppRole: Connecting to External Auth system");
response = template.exchange(
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "roles/"
- + app.getNameSpace()
- + "." + addRole
+ + app.getNameSpace() + "." + addRole
.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"),
HttpMethod.GET, entity, String.class);
logger.debug(EELFLoggerDelegate.debugLogger,
* @param updateExtRole
* @param app
* @return true if success else false
- * @throws Exception
- * If updateRoleInExternalSystem fails we catch it in logger for
- * detail message
+ * @throws Exception If updateRoleInExternalSystem fails we catch it in logger
+ * for detail message
*/
private boolean updateRoleInExternalSystem(Role updateExtRole, EPApp app, boolean isGlobalRole) throws Exception {
boolean response = false;
}
/*
- * Adds function to the role in the external auth system while editing a
- * role or updating new functions to a role
+ * Adds function to the role in the external auth system while editing a role or
+ * updating new functions to a role
*
*/
private boolean addFunctionsToRoleInExternalAuthSystem(Role updateExtRole, EPApp app, ObjectMapper mapper,
/**
*
- * It converts list of functions in updateExtRole parameter to the
- * RoleFunction object
+ * It converts list of functions in updateExtRole parameter to the RoleFunction
+ * object
*
* @param updateExtRole
* @return list of functions
* @param newRole
* @param app
* @return true if successfully added in the system else false
- * @throws Exception
- * If fails to add role in the system
+ * @throws Exception If fails to add role in the system
*/
private void addNewRoleInExternalSystem(List<EPRole> newRole, EPApp app)
throws Exception, HttpClientErrorException {
*
* It updates existing role in the External Auth System
*
- * @param addRole
- * It Contains role information
+ * @param addRole It Contains role information
* @param app
* @return string which is formatted to match with the external auth system
* @throws JsonProcessingException
*
* @param checkRole
* @param app
- * @throws Exception
- * If role exits
+ * @throws Exception If role exits
*/
private void checkIfRoleExitsInExternalSystem(Role checkRole, EPApp app) throws Exception {
getNameSpaceIfExists(app);
/**
*
- * It filters the app functions which starts with similar name in the result
- * set
+ * It filters the app functions which starts with similar name in the result set
*
* @param roleFunc
* @param roleFunction
}
/**
- * It returns user detail information which is deep copy of EPUser.class
- * object
+ * It returns user detail information which is deep copy of EPUser.class object
*
* @param userInfo
* @param userAppSet
/**
*
- * It returns list of app roles along with role functions and which went
- * through deep copy
+ * It returns list of app roles along with role functions and which went through
+ * deep copy
*
* @param app
* @param roleInfo
@Override
public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception {
String code = EcompPortalUtils.getFunctionCode(functionCode);
- String encodedCode = encodeFunctionCode(code);
+ String encodedCode = EcompPortalUtils.encodeFunctionCode(code);
CentralV2RoleFunction roleFunc = null;
EPApp app = getApp(uebkey).get(0);
List<CentralV2RoleFunction> getRoleFuncList = null;
throws Exception {
boolean saveOrUpdateFunction = false;
try {
- domainCentralRoleFunction.setCode(encodeFunctionCode(domainCentralRoleFunction.getCode()));
+ if(EcompPortalUtils.checkFunctionCodeHasEncodePattern(domainCentralRoleFunction.getCode()))
+ domainCentralRoleFunction.setCode(EcompPortalUtils.encodeFunctionCode(domainCentralRoleFunction.getCode()));
final Map<String, String> functionParams = new HashMap<>();
functionParams.put("appId", String.valueOf(app.getId()));
if (EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) {
if (extPerms.getJSONObject(i).has("description")) {
description = extPerms.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION);
} else {
- description = extPerms.getJSONObject(i).getString("type") + "|"
+ description = extPerms.getJSONObject(i).getString("type").substring(app.getNameSpace().length() + 1) + "|"
+ extPerms.getJSONObject(i).getString("instance") + "|"
+ extPerms.getJSONObject(i).getString("action");
}
/**
*
- * While sync functions form external auth system if new role found we
- * should add in local and return Role.class object
+ * While sync functions form external auth system if new role found we should
+ * add in local and return Role.class object
*
* @param app
* @param role
}
}
- /**
- *
- * 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
+ * system
*
* @param app
- * @param finalRoleList
- * contains list of current roles present in External Auth System
- * @param applicationRolesList
- * contains list of current roles present in DB
+ * @param finalRoleList contains list of current roles present in
+ * External Auth System
+ * @param applicationRolesList contains list of current roles present in DB
*/
@SuppressWarnings("unchecked")
private void inactiveRolesNotInExternalAuthSystem(EPApp app, List<EPRole> finalRoleList,
final Map<String, String> extRoleParams = new HashMap<>();
List<EPRole> roleList = null;
extRoleParams.put(APP_ROLE_NAME_PARAM, role.getName());
- if (!checkRolesInactive.containsKey(role.getName()
- .replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"))) {
+ if (!checkRolesInactive.containsKey(role.getName())) {
if (app.getId() == 1) {
roleList = dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, extRoleParams, null);
} else {
return userRolesAdded;
}
- @Override
- public String encodeFunctionCode(String funCode) {
- String encodedString = funCode;
- List<Pattern> encodingList = new ArrayList<>();
- encodingList.add(Pattern.compile("/"));
- encodingList.add(Pattern.compile("-"));
- for (Pattern xssInputPattern : encodingList) {
- encodedString = xssInputPattern.matcher(encodedString)
- .replaceAll("%" + Hex.encodeHexString(xssInputPattern.toString().getBytes()));
- }
- encodedString = encodedString.replaceAll("\\*", "%" + Hex.encodeHexString("*".getBytes()));
- return encodedString;
- }
-
@Override
public void bulkUploadRoleFunc(UploadRoleFunctionExtSystem data, EPApp app) throws Exception {
ObjectMapper mapper = new ObjectMapper();
ExternalAccessRolePerms extRolePerms;
ExternalAccessPerms extPerms;
extPerms = new ExternalAccessPerms(app.getNameSpace() + "." + data.getType(),
- encodeFunctionCode(data.getInstance()), data.getAction());
+ EcompPortalUtils.encodeFunctionCode(data.getInstance()), data.getAction());
String appNameSpace = "";
if (data.getIsGlobalRolePartnerFunc()) {
appNameSpace = epAppService.getApp(1l).getNameSpace();
}
return roleDescUpdated;
}
+
}