summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common/src')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java4
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java237
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java76
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRoleDescription.java68
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java2
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/BEPropertyTest.java60
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java118
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestTest.java200
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java213
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java13
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java35
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepositoryTest.java71
12 files changed, 596 insertions, 501 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
index 5a354f3a..54b915fe 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
@@ -207,8 +207,8 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
client.header(SystemProperties.USERAGENT_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE);
logger.debug(EELFLoggerDelegate.debugLogger,
- String.format("App %d found, baseUri=[%s], Headers: [%s=%s, %s=%s, %s=%s]", appSystemId, appBaseUri,
- APP_USERNAME_HEADER, username, PASSWORD_HEADER, encriptedPwd, BASIC_AUTHENTICATION_HEADER, encodingStr));
+ String.format("App %d found, baseUri=[%s], Headers: [%s=%s]", appSystemId, appBaseUri,
+ APP_USERNAME_HEADER, username));
return client;
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
index a77b9589..f83a8e34 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
@@ -2,7 +2,7 @@
* ============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
@@ -42,7 +42,6 @@ import java.util.ArrayList;
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;
@@ -53,7 +52,6 @@ import java.util.stream.Collectors;
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;
@@ -99,7 +97,6 @@ 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.ExternalRoleDescription;
import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
import org.onap.portalapp.portal.transport.LocalRole;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
@@ -157,8 +154,6 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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";
@@ -167,18 +162,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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);
@@ -315,12 +302,10 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
* @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))) {
@@ -328,7 +313,6 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
} 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);
@@ -360,86 +344,29 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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);
}
@@ -447,17 +374,41 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
} 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;
@@ -701,54 +652,23 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
}
}
- /**
- *
- * 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;
}
@@ -823,17 +743,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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);
@@ -1258,13 +1169,11 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
*/
@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());
@@ -1781,7 +1690,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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 {} ",
@@ -2190,7 +2099,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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();
@@ -2341,7 +2251,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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()));
@@ -2710,6 +2620,7 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
JSONArray extRole = getAppRolesJSONFromExtAuthSystem(app);
logger.debug(EELFLoggerDelegate.debugLogger, "Entering into getExternalRoleDetailsList");
+ //refactoring done
List<ExternalRoleDetails> externalRoleDetailsList = getExternalRoleDetailsList(app,
mapper, extRole);
@@ -2899,20 +2810,17 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
ObjectMapper mapper, JSONArray extRole)
throws IOException {
List<ExternalRoleDetails> externalRoleDetailsList = new ArrayList<>();
- ExternalRoleDescription ApplicationRole = new ExternalRoleDescription();
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);
- String roleName = extRole.getJSONObject(i).getString(ROLE_NAME);
- ApplicationRole.setName(roleName.substring(app.getNameSpace().length() + 1));
+ String name = extRole.getJSONObject(i).getString(ROLE_NAME);
+ String actualRoleName = name.substring(app.getNameSpace().length() + 1);
if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_ROLE_DESCRIPTION)) {
- String desc = extRole.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION);
- ApplicationRole.setName(desc);
+ actualRoleName = extRole.getJSONObject(i).getString(EXTERNAL_AUTH_ROLE_DESCRIPTION);
}
SortedSet<ExternalAccessPerms> externalAccessPermsOfRole = new TreeSet<>();
if (extRole.getJSONObject(i).has(EXTERNAL_AUTH_PERMS)) {
@@ -2932,14 +2840,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
}
}
externalRoleDetail.setActive(true);
- externalRoleDetail.setName(ApplicationRole.getName());
+ externalRoleDetail.setName(actualRoleName);
if (app.getId() == 1) {
externalRoleDetail.setAppId(null);
} else {
externalRoleDetail.setAppId(app.getId());
}
// get role functions from DB
- EPRole currRole = curRolesMap.get(ApplicationRole.getName()
+ EPRole currRole = curRolesMap.get(actualRoleName
.replaceAll(EcompPortalUtils.EXTERNAL_CENTRAL_AUTH_ROLE_HANDLE_SPECIAL_CHARACTERS, "_"));
Long roleId = null;
if (currRole != null)
@@ -3045,6 +2953,9 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
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");
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
index 2eb7c948..b0dd4a21 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
@@ -823,6 +823,72 @@ public class UserRolesCommonServiceImpl {
return addRemoteUser;
}
+
+ private EPUser pushRemoteUser(List<RoleInAppForUser> roleInAppForUserList, String userId, EPApp app,
+ ObjectMapper mapper, SearchService searchService,
+ ApplicationsRestClientService applicationsRestClientService) throws Exception {
+ EPUser addRemoteUser = null;
+ if (remoteUserShouldBeCreated(roleInAppForUserList)) {
+ pushUserOnRemoteApp(userId, app, applicationsRestClientService, searchService, mapper,
+ isAppUpgradeVersion(app), roleInAppForUserList);
+ }
+ return addRemoteUser;
+ }
+
+ protected void pushUserOnRemoteApp(String userId, EPApp app,
+ ApplicationsRestClientService applicationsRestClientService, SearchService searchService,
+ ObjectMapper mapper, boolean postOpenSource, List<RoleInAppForUser> roleInAppForUserList) throws Exception {
+
+ EPUser client = searchService.searchUserByUserId(userId);
+
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ if (client == null) {
+ String msg = "cannot create user " + userId + ", because he/she cannot be found in phonebook.";
+ logger.error(EELFLoggerDelegate.errorLogger, msg);
+ throw new Exception(msg);
+ }
+
+ client.setLoginId(userId);
+ client.setActive(true);
+ roleInAppForUserList.removeIf(role -> role.isApplied.equals(false));
+ Set<EcompRole> userRolesInRemoteApp = constructUsersRemoteAppRoles(roleInAppForUserList);
+ SortedSet<Role> roles = new TreeSet<>();
+ List<EPRole> getAppRoles = getAppRoles(app.getId());
+ for (EcompRole epRole : userRolesInRemoteApp) {
+ Role role = new Role();
+ EPRole appRole = getAppRoles.stream()
+ .filter(applicationRole -> epRole.getId().equals(applicationRole.getId()))
+ .findAny()
+ .orElse(null);
+ if(appRole != null)
+ role.setId(appRole.getAppRoleId());
+ role.setName(epRole.getName());
+ roles.add(role);
+ }
+ client.setRoles(roles);
+ String userInString = null;
+ userInString = mapper.writerFor(EPUser.class).writeValueAsString(client);
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "about to post a client to remote application, users json = " + userInString);
+ applicationsRestClientService.post(EPUser.class, app.getId(), userInString, String.format("/user/%s", userId));
+
+ }
+
+
+ public List<EPRole> getAppRoles(Long appId) throws Exception {
+ List<EPRole> applicationRoles = null;
+ final Map<String, Long> appParams = new HashMap<>();
+ try {
+ appParams.put("appId", appId);
+ applicationRoles = dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppRoles: failed", e);
+ throw e;
+ }
+ return applicationRoles;
+ }
+
/**
* It checks whether the remote user exists or not
* if exits returns user object else null
@@ -883,16 +949,12 @@ public class UserRolesCommonServiceImpl {
// if centralized app
if (app.getCentralAuth()) {
if (!app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
- try {
- addRemoteUser(roleInAppForUserList, userId, app, mapper, searchService,
+ pushRemoteUser(roleInAppForUserList, userId, app, mapper, searchService,
applicationsRestClientService);
- } catch (Exception e) {
- String message=e.getMessage();
- logger.error(EELFLoggerDelegate.errorLogger, message, e);
- }
}
- Set<EcompRole> userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList, mapper,
+
+ Set<EcompRole> userRolesInLocalApp = postUsersRolesToLocalApp(roleInAppForUserList, mapper,
applicationsRestClientService, appId, userId);
RolesInAppForUser rolesInAppForUser = constructRolesInAppForUserUpdate(userId, appId,
userRolesInLocalApp);
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRoleDescription.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRoleDescription.java
index dd013c78..b9781071 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRoleDescription.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRoleDescription.java
@@ -39,59 +39,20 @@ package org.onap.portalapp.portal.transport;
public class ExternalRoleDescription {
- private String id;
private String name;
- private String active;
- private String priority;
- private String appId;
- private String appRoleId;
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
- public String getActive() {
- return active;
- }
- public void setActive(String active) {
- this.active = active;
- }
- public String getPriority() {
- return priority;
- }
- public void setPriority(String priority) {
- this.priority = priority;
- }
- public String getAppId() {
- return appId;
- }
- public void setAppId(String appId) {
- this.appId = appId;
- }
- public String getAppRoleId() {
- return appRoleId;
- }
- public void setAppRoleId(String appRoleId) {
- this.appRoleId = appRoleId;
- }
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((active == null) ? 0 : active.hashCode());
- result = prime * result + ((appId == null) ? 0 : appId.hashCode());
- result = prime * result + ((appRoleId == null) ? 0 : appRoleId.hashCode());
- result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((priority == null) ? 0 : priority.hashCode());
return result;
}
@Override
@@ -103,38 +64,15 @@ public class ExternalRoleDescription {
if (getClass() != obj.getClass())
return false;
ExternalRoleDescription other = (ExternalRoleDescription) obj;
- if (active == null) {
- if (other.active != null)
- return false;
- } else if (!active.equals(other.active))
- return false;
- if (appId == null) {
- if (other.appId != null)
- return false;
- } else if (!appId.equals(other.appId))
- return false;
- if (appRoleId == null) {
- if (other.appRoleId != null)
- return false;
- } else if (!appRoleId.equals(other.appRoleId))
- return false;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
- if (priority == null) {
- if (other.priority != null)
- return false;
- } else if (!priority.equals(other.priority))
- return false;
return true;
}
+
+
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java
index 809e42f9..f8d1116b 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java
@@ -86,7 +86,7 @@ public class EcompPortalUtils {
* otherwise
*/
public static boolean legitimateUserId(String orgUserId) {
- return orgUserId.matches("^[a-zA-Z0-9]+$");
+ return orgUserId.matches("^[a-zA-Z0-9/_/-/@]+$");
}
/**
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/BEPropertyTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/BEPropertyTest.java
index 102e6aeb..516393a3 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/BEPropertyTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/BEPropertyTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -45,25 +47,41 @@ import org.junit.Test;
public class BEPropertyTest {
-
- private static final String TEST="test";
-
- @Test
- public void test() {
- BEProperty property=new BEProperty(TEST, TEST);
- BEProperty beProperty=new BEProperty(TEST, TEST);
- BEProperty be=property;
-
- beProperty.setKey(property.getKey());
- beProperty.setValue(property.getValue());
-
- assertEquals(property.hashCode(), beProperty.hashCode());
- assertTrue(beProperty.equals(property));
- assertTrue(be.equals(property));
- assertFalse(be.equals(null));
- be.setValue(null);
- assertTrue(be.equals(property));
- be.setKey(null);
- assertTrue(be.equals(property));
- }
+
+ private static final String TEST="test";
+
+ @Test
+ public void test() {
+ BEProperty property=new BEProperty(TEST, TEST);
+ BEProperty beProperty=new BEProperty(TEST, TEST);
+ BEProperty be=property;
+
+ beProperty.setKey(property.getKey());
+ beProperty.setValue(property.getValue());
+
+ assertEquals(property.hashCode(), beProperty.hashCode());
+ assertTrue(beProperty.equals(property));
+ assertTrue(be.equals(property));
+ assertFalse(be.equals(null));
+ be.setValue(null);
+ assertTrue(be.equals(property));
+ be.setKey(null);
+ assertTrue(be.equals(property));
+
+ assertFalse(property.equals(this));
+
+ property.setKey(null);
+ beProperty.setKey("notnull");
+ assertFalse(property.equals(beProperty));
+ assertFalse(beProperty.equals(property));
+
+ property.setKey("notnull");
+ beProperty.setKey("notnull");
+ property.setValue(null);
+ beProperty.setValue("notnull");
+ assertFalse(property.equals(beProperty));
+ assertFalse(beProperty.equals(property));
+
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
index d081b801..f99c80bc 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -51,58 +53,68 @@ import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
public class EPRoleTest {
-
- @Test
- public void testEpRole() {
- EPRole role=new EPRole();
- role.setActive(true);
- role.setAppId(1l);
- role.setAppRoleId(2l);
- role.setId(3l);
- role.setName("TEST_ADMIN");
- SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
- EPRole child=new EPRole();
- child.setActive(true);
- child.setAppId(1l);
- child.setAppRoleId(3l);
- child.setId(6l);
- child.setName("TEST_USER");
- childRoles.add(child);
- role.setChildRoles(childRoles);
- SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
- EPRole parent=new EPRole();
- parent.setActive(true);
- parent.setAppId(1l);
- parent.setAppRoleId(3l);
- parent.setId(6l);
- parent.setName("TEST_USER");
- parentRoles.add(parent);
- role.setParentRoles(parentRoles);
-
- SortedSet<RoleFunction> rolefunction = new TreeSet<RoleFunction>();
- RoleFunction function=new RoleFunction();
- function.setAction("Test");;
- function.setCode("code");
- rolefunction.add(function);
- role.setRoleFunctions(rolefunction);
- role.setPriority(5);
- role.setAppRoleId(3l);
- assertEquals(3l, role.getAppRoleId().longValue());
- assertNotNull(role.getChildRoles());
- assertNotNull(role.getParentRoles());
- assertNotNull(role.getRoleFunctions());
- role.compareTo(role);
- assertEquals(1l, role.getAppId().longValue());
- assertEquals("TEST_ADMIN",role.getName());
- role.removeChildRole(6l);
- role.removeParentRole(6l);
- assertEquals(role.toString(), "[Id = 3, name = TEST_ADMIN]");
- role.removeRoleFunction("code");
- role.addChildRole(child);
- role.addParentRole(parent);
- role.addRoleFunction(function);
-
- }
-
+
+ @Test
+ public void testEpRole() {
+ EPRole role=new EPRole();
+ role.setActive(true);
+ role.setAppId(1l);
+ role.setAppRoleId(2l);
+ role.setId(3l);
+ role.setName("TEST_ADMIN");
+ SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
+ EPRole child=new EPRole();
+ child.setActive(true);
+ child.setAppId(1l);
+ child.setAppRoleId(3l);
+ child.setId(6l);
+ child.setName("TEST_USER");
+ childRoles.add(child);
+ role.setChildRoles(childRoles);
+ SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
+ EPRole parent=new EPRole();
+ parent.setActive(true);
+ parent.setAppId(1l);
+ parent.setAppRoleId(3l);
+ parent.setId(6l);
+ parent.setName("TEST_USER");
+ parentRoles.add(parent);
+ role.setParentRoles(parentRoles);
+
+ SortedSet<RoleFunction> rolefunction = new TreeSet<RoleFunction>();
+ RoleFunction function=new RoleFunction();
+ function.setAction("Test");;
+ function.setCode("code");
+ rolefunction.add(function);
+ role.setRoleFunctions(rolefunction);
+ role.setPriority(5);
+ role.setAppRoleId(3l);
+ assertEquals(3l, role.getAppRoleId().longValue());
+ assertNotNull(role.getChildRoles());
+ assertNotNull(role.getParentRoles());
+ assertNotNull(role.getRoleFunctions());
+ role.compareTo(role);
+ assertEquals(1l, role.getAppId().longValue());
+ assertEquals("TEST_ADMIN",role.getName());
+ role.removeChildRole(6l);
+ role.removeParentRole(6l);
+ assertEquals(role.toString(), "[Id = 3, name = TEST_ADMIN]");
+ role.removeRoleFunction("code");
+ role.addChildRole(child);
+ role.addParentRole(parent);
+ role.addRoleFunction(function);
+
+ parent.setAppId(null);
+ child.setAppId((long) 1234);
+ assertEquals(parent.compareTo(child), -1);
+
+ child.setAppId(null);
+ parent.setAppId((long) 1234);
+ assertEquals(parent.compareTo(child), 1);
+
+
+
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestTest.java
index 96089cd7..d40bd420 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -50,45 +52,163 @@ import java.util.Set;
import org.junit.Test;
public class EPUserAppRolesRequestTest {
-
- private static final String TEST="test";
- Date date=new Date();
-
-
- @Test
- public void testEpUserAppRoles() {
- EPUserAppRolesRequest request=new EPUserAppRolesRequest();
- request=buildEPUserAppRolesRequest(request);
- EPUserAppRolesRequest request1=new EPUserAppRolesRequest();
- request1=buildEPUserAppRolesRequest(request1);
-
- assertEquals(request.getRequestStatus(), "test");
- request.getAppId();
- request.getUserId();
- assertEquals(request.getCreated(),date);
- assertEquals(request.getCreatedDate(),date);
- assertEquals(request.getUpdatedDate(),date);
- assertNotNull(request.getEpRequestIdDetail());
- assertEquals(request.hashCode(), request1.hashCode());
- assertTrue(request.equals(request1));
- assertNotNull(request.toString());
-
-
- }
- private EPUserAppRolesRequest buildEPUserAppRolesRequest(EPUserAppRolesRequest request) {
- request.setUserId(1l);
- request.setAppId(1l);
- request.setCreated(date);
- request.setCreatedDate(date);
- request.setUpdatedDate(date);
- request.setRequestStatus(TEST);
- Set<EPUserAppRolesRequestDetail> epRequestIdDetail=new HashSet<>();
- EPUserAppRolesRequestDetail detail=new EPUserAppRolesRequestDetail();
- detail.setId(1l);
- epRequestIdDetail.add(detail);
- request.setEpRequestIdDetail(epRequestIdDetail);
-
- return request;
- }
+
+ private static final String TEST="test";
+ Date date=new Date();
+
+
+ @Test
+ public void testEpUserAppRoles() {
+ EPUserAppRolesRequest request=new EPUserAppRolesRequest();
+ request=buildEPUserAppRolesRequest(request);
+ EPUserAppRolesRequest request1=new EPUserAppRolesRequest();
+ request1=buildEPUserAppRolesRequest(request1);
+
+ assertEquals(request.getRequestStatus(), "test");
+ request.getAppId();
+ request.getUserId();
+ assertEquals(request.getCreated(),date);
+ assertEquals(request.getCreatedDate(),date);
+ assertEquals(request.getUpdatedDate(),date);
+ assertNotNull(request.getEpRequestIdDetail());
+ assertEquals(request.hashCode(), request1.hashCode());
+ assertTrue(request.equals(request1));
+ assertNotNull(request.toString());
+
+ request.setAppId(null);
+ request1.setAppId((long) 12345);
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 54321);
+ request1.setAppId((long) 12345);
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(null);
+ request1.setCreatedDate(new Date());
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ Date requstDate = new Date();
+ requstDate.setYear(2000);
+ request.setCreatedDate(requstDate);
+ request1.setCreatedDate(new Date());
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(null);
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ HashSet<EPUserAppRolesRequestDetail> details = new HashSet<EPUserAppRolesRequestDetail>();
+ details.add(new EPUserAppRolesRequestDetail());
+ request.setEpRequestIdDetail(details);
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ assertFalse(request.equals(request1));
+
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus(null);
+ request1.setRequestStatus("notnull");
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus("status");
+ request1.setRequestStatus("notnull");
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus("notnull");
+ request1.setRequestStatus("notnull");
+ request.setUpdatedDate(null);
+ request1.setUpdatedDate(new Date());
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus("notnull");
+ request1.setRequestStatus("notnull");
+ Date date = new Date();
+ date.setYear(2000);
+ request.setUpdatedDate(date);
+ request1.setUpdatedDate(new Date());
+ assertFalse(request.equals(request1));
+
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus("notnull");
+ request1.setRequestStatus("notnull");
+ request.setUpdatedDate(new Date());
+ request1.setUpdatedDate(new Date());
+ request.setUserId(null);
+ request1.setUserId((long) 12345);
+ assertFalse(request.equals(request1));
+
+ request.setAppId((long) 12345);
+ request1.setAppId((long) 12345);
+ request.setCreatedDate(new Date());
+ request1.setCreatedDate(new Date());
+ request.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request1.setEpRequestIdDetail(new HashSet<EPUserAppRolesRequestDetail>());
+ request.setRequestStatus("notnull");
+ request1.setRequestStatus("notnull");
+ request.setUpdatedDate(new Date());
+ request1.setUpdatedDate(new Date());
+ request.setUserId((long) 54321);
+ request1.setUserId((long) 12345);
+ assertFalse(request.equals(request1));
+
+ assertFalse(request.equals(this));
+ assertFalse(request.equals(null));
+
+ }
+ private EPUserAppRolesRequest buildEPUserAppRolesRequest(EPUserAppRolesRequest request) {
+ request.setUserId(1l);
+ request.setAppId(1l);
+ request.setCreated(date);
+ request.setCreatedDate(date);
+ request.setUpdatedDate(date);
+ request.setRequestStatus(TEST);
+ Set<EPUserAppRolesRequestDetail> epRequestIdDetail=new HashSet<>();
+ EPUserAppRolesRequestDetail detail=new EPUserAppRolesRequestDetail();
+ detail.setId(1l);
+ epRequestIdDetail.add(detail);
+ request.setEpRequestIdDetail(epRequestIdDetail);
+
+ return request;
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java
index bc4c6f38..c856b5a3 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -37,7 +39,7 @@
*/
package org.onap.portalapp.portal.domain;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.util.Date;
@@ -46,106 +48,111 @@ import org.onap.portalapp.portal.domain.EPUser;
public class EPUserTest {
- public EPUser mockEPUser(){
-
- EPUser epUser = new EPUser();
-
- epUser.setId((long)1);
- epUser.setManagerId((long) 1234);
- epUser.setFirstName("test");
- epUser.setLastName("test");
- epUser.setMiddleInitial("test");
- epUser.setPhone("test");
- epUser.setFax("test");
- epUser.setCellular("test");
- epUser.setEmail("test");
- epUser.setAddressId((long) 123);
- epUser.setAlertMethodCd("test");
- epUser.setHrid("test");
- epUser.setOrgUserId("test");
- epUser.setOrgCode("test");
- epUser.setAddress1("test");
- epUser.setAddress2("test");
- epUser.setCity("test");
- epUser.setState("test");
- epUser.setZipCode("test");
- epUser.setCountry("test");
- epUser.setOrgManagerUserId("test");
- epUser.setLocationClli("test");
- epUser.setBusinessCountryCode("test");
- epUser.setBusinessCountryName("test");
- epUser.setBusinessUnit("test");
- epUser.setBusinessUnitName("test");
- epUser.setDepartment("test");
- epUser.setDepartmentName("test");
- epUser.setCompanyCode("test");
- epUser.setCompany("test");
- epUser.setZipCodeSuffix("test");
- epUser.setJobTitle("test");
- epUser.setCommandChain("test");
- epUser.setSiloStatus("test");
- epUser.setCostCenter("test");
- epUser.setFinancialLocCode("test");
- epUser.setLoginId("test");
- epUser.setLoginPwd("test");
- epUser.setLastLoginDate(new Date());
- epUser.setActive(false);
- epUser.setInternal(false);
- epUser.setSelectedProfileId((long) 12345);
- epUser.setTimeZoneId((long) 12345);
- epUser.setOnline(false);
- epUser.setChatId("test");
- return epUser;
-
- }
-
- @Test
- public void userTest(){
- EPUser user = mockEPUser();
-
- assertEquals(user.getId(), new Long(1));
- assertEquals(user.getManagerId(), new Long(1234));
- assertEquals(user.getFirstName(), "test");
- assertEquals(user.getLastName(), "test");
- assertEquals(user.getMiddleInitial(), "test");
- assertEquals(user.getPhone(), "test");
- assertEquals(user.getFax(), "test");
- assertEquals(user.getCellular(), "test");
- assertEquals(user.getEmail(), "test");
- assertEquals(user.getAddressId(), new Long(123) );
- assertEquals(user.getAlertMethodCd(), "test");
- assertEquals(user.getHrid(), "test");
- assertEquals(user.getOrgUserId(), "test");
- assertEquals(user.getOrgCode(), "test");
- assertEquals(user.getAddress1(), "test");
- assertEquals(user.getAddress2(), "test");
- assertEquals(user.getState(), "test");
- assertEquals(user.getZipCode(), "test");
- assertEquals(user.getCountry(), "test");
- assertEquals(user.getOrgManagerUserId(), "test");
- assertEquals(user.getLocationClli(), "test");
- assertEquals(user.getBusinessCountryCode(), "test");
- assertEquals(user.getBusinessCountryName(), "test");
- assertEquals(user.getBusinessUnit(), "test");
- assertEquals(user.getBusinessUnitName(), "test");
- assertEquals(user.getDepartment(), "test");
- assertEquals(user.getDepartmentName(), "test");
- assertEquals(user.getCompanyCode(), "test");
- assertEquals(user.getCompany(), "test");
- assertEquals(user.getZipCodeSuffix(), "test");
- assertEquals(user.getJobTitle(), "test");
- assertEquals(user.getCommandChain(), "test");
- assertEquals(user.getSiloStatus(), "test");
- assertEquals(user.getFinancialLocCode(), "test");
- assertEquals(user.getLoginId(), "test");
- assertEquals(user.getLoginPwd(), "test");
- assertEquals(user.getActive(), false);
- assertEquals(user.getInternal(), false);
- assertEquals(user.getSelectedProfileId(), new Long (12345));
- assertEquals(user.getTimeZoneId(), new Long (12345));
- assertEquals(user.getChatId(), "test");
-
- //assertEquals(user.toString(), "EPUser [orgId=null, managerId=1234, firstName=test, middleInitial=test, lastName=test, phone=test, fax=test, cellular=test, email=test, addressId=123, alertMethodCd=test, hrid=test, orgUserId=test, orgCode=test, address1=test, address2=test, city=test, state=test, zipCode=test, country=test, orgManagerUserId=test, locationClli=test, businessCountryCode=test, businessCountryName=test, businessUnit=test, businessUnitName=test, department=test, departmentName=test, companyCode=test, company=test, zipCodeSuffix=test, jobTitle=test, commandChain=test, siloStatus=test, costCenter=test, financialLocCode=test, loginId=test, loginPwd=test, lastLoginDate=Tue Sep 05 11:04:49 EDT 2017, active=false, internal=false, selectedProfileId=12345, timeZoneId=12345, online=false, chatId=test, isGuest=false, userApps=[], pseudoRoles=[]]");
- }
-
+ public EPUser mockEPUser(){
+
+ EPUser epUser = new EPUser();
+
+ epUser.setId((long)1);
+ epUser.setManagerId((long) 1234);
+ epUser.setFirstName("test");
+ epUser.setLastName("test");
+ epUser.setMiddleInitial("test");
+ epUser.setPhone("test");
+ epUser.setFax("test");
+ epUser.setCellular("test");
+ epUser.setEmail("test");
+ epUser.setAddressId((long) 123);
+ epUser.setAlertMethodCd("test");
+ epUser.setHrid("test");
+ epUser.setOrgUserId("test");
+ epUser.setOrgCode("test");
+ epUser.setAddress1("test");
+ epUser.setAddress2("test");
+ epUser.setCity("test");
+ epUser.setState("test");
+ epUser.setZipCode("test");
+ epUser.setCountry("test");
+ epUser.setOrgManagerUserId("test");
+ epUser.setLocationClli("test");
+ epUser.setBusinessCountryCode("test");
+ epUser.setBusinessCountryName("test");
+ epUser.setBusinessUnit("test");
+ epUser.setBusinessUnitName("test");
+ epUser.setDepartment("test");
+ epUser.setDepartmentName("test");
+ epUser.setCompanyCode("test");
+ epUser.setCompany("test");
+ epUser.setZipCodeSuffix("test");
+ epUser.setJobTitle("test");
+ epUser.setCommandChain("test");
+ epUser.setSiloStatus("test");
+ epUser.setCostCenter("test");
+ epUser.setFinancialLocCode("test");
+ epUser.setLoginId("test");
+ epUser.setLoginPwd("test");
+ epUser.setLastLoginDate(new Date());
+ epUser.setActive(false);
+ epUser.setInternal(false);
+ epUser.setSelectedProfileId((long) 12345);
+ epUser.setTimeZoneId((long) 12345);
+ epUser.setOnline(false);
+ epUser.setChatId("test");
+ return epUser;
+
+ }
+
+ @Test
+ public void userTest(){
+ EPUser user = mockEPUser();
+
+ assertEquals(user.getId(), new Long(1));
+ assertEquals(user.getManagerId(), new Long(1234));
+ assertEquals(user.getFirstName(), "test");
+ assertEquals(user.getLastName(), "test");
+ assertEquals(user.getMiddleInitial(), "test");
+ assertEquals(user.getPhone(), "test");
+ assertEquals(user.getFax(), "test");
+ assertEquals(user.getCellular(), "test");
+ assertEquals(user.getEmail(), "test");
+ assertEquals(user.getAddressId(), new Long(123) );
+ assertEquals(user.getAlertMethodCd(), "test");
+ assertEquals(user.getHrid(), "test");
+ assertEquals(user.getOrgUserId(), "test");
+ assertEquals(user.getOrgCode(), "test");
+ assertEquals(user.getAddress1(), "test");
+ assertEquals(user.getAddress2(), "test");
+ assertEquals(user.getState(), "test");
+ assertEquals(user.getZipCode(), "test");
+ assertEquals(user.getCountry(), "test");
+ assertEquals(user.getOrgManagerUserId(), "test");
+ assertEquals(user.getLocationClli(), "test");
+ assertEquals(user.getBusinessCountryCode(), "test");
+ assertEquals(user.getBusinessCountryName(), "test");
+ assertEquals(user.getBusinessUnit(), "test");
+ assertEquals(user.getBusinessUnitName(), "test");
+ assertEquals(user.getDepartment(), "test");
+ assertEquals(user.getDepartmentName(), "test");
+ assertEquals(user.getCompanyCode(), "test");
+ assertEquals(user.getCompany(), "test");
+ assertEquals(user.getZipCodeSuffix(), "test");
+ assertEquals(user.getJobTitle(), "test");
+ assertEquals(user.getCommandChain(), "test");
+ assertEquals(user.getSiloStatus(), "test");
+ assertEquals(user.getFinancialLocCode(), "test");
+ assertEquals(user.getLoginId(), "test");
+ assertEquals(user.getLoginPwd(), "test");
+ assertEquals(user.getActive(), false);
+ assertEquals(user.getInternal(), false);
+ assertEquals(user.getSelectedProfileId(), new Long (12345));
+ assertEquals(user.getTimeZoneId(), new Long (12345));
+ assertEquals(user.getChatId(), "test");
+
+ EPUser another = mockEPUser();
+ assertTrue(user.compareTo(another) == 0);
+ another.setLastName("otherlastname");
+ assertTrue(user.compareTo(another) == 5);
+
+ //assertEquals(user.toString(), "EPUser [orgId=null, managerId=1234, firstName=test, middleInitial=test, lastName=test, phone=test, fax=test, cellular=test, email=test, addressId=123, alertMethodCd=test, hrid=test, orgUserId=test, orgCode=test, address1=test, address2=test, city=test, state=test, zipCode=test, country=test, orgManagerUserId=test, locationClli=test, businessCountryCode=test, businessCountryName=test, businessUnit=test, businessUnitName=test, department=test, departmentName=test, companyCode=test, company=test, zipCodeSuffix=test, jobTitle=test, commandChain=test, siloStatus=test, costCenter=test, financialLocCode=test, loginId=test, loginPwd=test, lastLoginDate=Tue Sep 05 11:04:49 EDT 2017, active=false, internal=false, selectedProfileId=12345, timeZoneId=12345, online=false, chatId=test, isGuest=false, userApps=[], pseudoRoles=[]]");
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java
index e6d97ec4..1ddadd89 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java
@@ -2,7 +2,7 @@
* ============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
@@ -48,13 +48,7 @@ public class ExternalAccessUserRoleDetailTest {
public ExternalAccessUserRoleDetail mockExternalAccessUserRoleDetail(){
ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription();
- externalRoleDescription.setId("test");
externalRoleDescription.setName("test");
- externalRoleDescription.setActive("test");
- externalRoleDescription.setPriority("test");
- externalRoleDescription.setAppId("test");
- externalRoleDescription.setAppRoleId("test");
-
ExternalAccessUserRoleDetail externalAccessUserRoleDetail = new ExternalAccessUserRoleDetail("test", externalRoleDescription);
externalAccessUserRoleDetail.setName("test");
@@ -67,12 +61,7 @@ public class ExternalAccessUserRoleDetailTest {
ExternalAccessUserRoleDetail externalAccessUserRoleDetail = mockExternalAccessUserRoleDetail();
ExternalRoleDescription externalRoleDescription1 = new ExternalRoleDescription();
- externalRoleDescription1.setId("test");
externalRoleDescription1.setName("test");
- externalRoleDescription1.setActive("test");
- externalRoleDescription1.setPriority("test");
- externalRoleDescription1.setAppId("test");
- externalRoleDescription1.setAppRoleId("test");
ExternalAccessUserRoleDetail externalAccessUserRoleDetail1 = new ExternalAccessUserRoleDetail("test", externalRoleDescription1);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java
index 6a4b6cab..41ee7fde 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java
@@ -2,7 +2,7 @@
* ============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
@@ -42,7 +42,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.portalapp.portal.transport.ExternalRoleDescription;
public class ExternalRoleDescriptionTest {
@@ -51,49 +50,17 @@ public class ExternalRoleDescriptionTest {
@Test
public void externalRoleDescriptionTest(){
ExternalRoleDescription extRole=mockExternalRoleDescription();
-
ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription();
- externalRoleDescription.setId(extRole.getId());
externalRoleDescription.setName(extRole.getName());
- externalRoleDescription.setActive(extRole.getActive());
- externalRoleDescription.setPriority(extRole.getPriority());
- externalRoleDescription.setAppId(extRole.getAppId());
- externalRoleDescription.setAppRoleId(extRole.getAppRoleId());
-
- assertEquals(externalRoleDescription.getId(), TEST);
assertEquals(externalRoleDescription.getName(), TEST);
- assertEquals(externalRoleDescription.getActive(), TEST);
- assertEquals(externalRoleDescription.getPriority(), TEST);
- assertEquals(externalRoleDescription.getAppId(), TEST);
- assertEquals(externalRoleDescription.getAppRoleId(), TEST);
assertEquals(externalRoleDescription.hashCode(), extRole.hashCode());
assertTrue(externalRoleDescription.equals(extRole));
-
- assertFalse(externalRoleDescription.equals(null));
- externalRoleDescription.setPriority(null);
- assertFalse(externalRoleDescription.equals(extRole));
externalRoleDescription.setName(null);
assertFalse(externalRoleDescription.equals(extRole));
- externalRoleDescription.setId(null);
- assertFalse(externalRoleDescription.equals(extRole));
- externalRoleDescription.setAppRoleId(null);
- assertFalse(externalRoleDescription.equals(extRole));
- externalRoleDescription.setAppId(null);
- assertFalse(externalRoleDescription.equals(extRole));
- externalRoleDescription.setActive(null);
- assertFalse(externalRoleDescription.equals(extRole));
}
private ExternalRoleDescription mockExternalRoleDescription(){
-
ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription();
-
- externalRoleDescription.setId(TEST);
externalRoleDescription.setName(TEST);
- externalRoleDescription.setActive(TEST);
- externalRoleDescription.setPriority(TEST);
- externalRoleDescription.setAppId(TEST);
- externalRoleDescription.setAppRoleId(TEST);
-
return externalRoleDescription;
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepositoryTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepositoryTest.java
new file mode 100644
index 00000000..896c10a3
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/MusicCookieCsrfTokenRepositoryTest.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2018 IBM Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.utils;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
+import org.springframework.security.web.csrf.CsrfToken;
+
+public class MusicCookieCsrfTokenRepositoryTest {
+
+ MusicCookieCsrfTokenRepository repo;
+
+ CookieCsrfTokenRepository cookieRepo;
+
+ @Before
+ public void setup() {
+ cookieRepo = new CookieCsrfTokenRepository();
+ repo = new MusicCookieCsrfTokenRepository(cookieRepo);
+ }
+
+ @Test
+ public void generateTokenTest(){
+ HttpServletRequest requestMock = Mockito.mock(HttpServletRequest.class);
+ CsrfToken expected = cookieRepo.generateToken(requestMock);
+
+ CsrfToken actual = repo.generateToken(requestMock);
+
+ Assert.assertEquals(expected.getHeaderName(), actual.getHeaderName());
+ Assert.assertEquals(expected.getParameterName(), actual.getParameterName());
+ }
+}