summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src
diff options
context:
space:
mode:
authorst398c <st398c@research.att.com>2019-03-28 16:30:03 -0400
committerst398c <st398c@research.att.com>2019-03-28 16:30:03 -0400
commitfa5f20d91c416a855f0d6afe157db8250574617c (patch)
tree3dd5dd3f8bccc8c0f30ca41cb2569aa4b0c5cefb /ecomp-sdk/epsdk-core/src
parent1ded3bb69c5e91cd879d83e13d2b3295710cdb4f (diff)
Fortify, version, Junit
Issue-ID: PORTAL-543, PORTAL-273, PORTAL-544 Change-Id: Ib864ef78bbd534170cab90d9314f2d8943f78872 Signed-off-by: Thota, Saisree <st398c@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java49
-rw-r--r--ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserApiServiceImplTest.java2
2 files changed, 16 insertions, 35 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java
index 074419e6..9c8a8838 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java
@@ -1,5 +1,4 @@
-
/*-
* ============LICENSE_START==========================================
* ONAP Portal SDK
@@ -62,7 +61,6 @@ import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.external.authorization.domain.ExternalAccessPerms;
import org.onap.portalsdk.external.authorization.domain.ExternalAccessRole;
-import org.onap.portalsdk.external.authorization.domain.ExternalAccessRoleDescription;
import org.onap.portalsdk.external.authorization.domain.ExternalAccessUserRoleDetail;
import org.onap.portalsdk.external.authorization.exception.UserNotFoundException;
import org.onap.portalsdk.external.authorization.service.AAFRestServiceImpl;
@@ -85,7 +83,6 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
@Service("userApiService")
public class UserApiServiceImpl implements UserApiService {
-
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserApiServiceImpl.class);
@Autowired
@@ -104,8 +101,7 @@ public class UserApiServiceImpl implements UserApiService {
@Autowired
private AppService appService;
-
-
+
private AAFService aafService = new AAFRestServiceImpl();
@Override
@@ -114,7 +110,7 @@ public class UserApiServiceImpl implements UserApiService {
try {
String namespace = EcompExternalAuthProperties
.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE);
-
+
HttpHeaders headers = getBasicAuthHeaders();
String userRoles = aafService.getUser(orgUserId, request, headers);
ObjectMapper mapper = new ObjectMapper();
@@ -148,12 +144,6 @@ public class UserApiServiceImpl implements UserApiService {
.endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_ADMIN)
&& !role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME)
.endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_OWNER)) {
- ExternalAccessRoleDescription ecDesc = new ExternalAccessRoleDescription();
- if (role.has(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION) && EcompExternalAuthUtils
- .isJSONValid(role.getString(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION))) {
- ecDesc = mapper.readValue(role.getString(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION),
- ExternalAccessRoleDescription.class);
- }
List<ExternalAccessPerms> ecPerms = new ArrayList<>();
if (role.has(EcompExternalAuthUtils.EXT_FIELD_PERMS)) {
JSONArray perms = role.getJSONArray(EcompExternalAuthUtils.EXT_FIELD_PERMS);
@@ -161,7 +151,7 @@ public class UserApiServiceImpl implements UserApiService {
.constructCollectionType(List.class, ExternalAccessPerms.class));
}
ExternalAccessRole ecRole = new ExternalAccessRole(
- role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME), ecPerms, ecDesc);
+ role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME), ecPerms);
userRoleDetail = new ExternalAccessUserRoleDetail(ecRole);
userRoleDetailList.add(userRoleDetail);
}
@@ -201,23 +191,16 @@ public class UserApiServiceImpl implements UserApiService {
private Set setUserApps(List<ExternalAccessUserRoleDetail> userRoleDetailList, String namespace, User user,
App app) {
Set userApps = new TreeSet();
+ //As External Auth System does not provide roleId's we are setting counter value for roleId. These values should not be stored in DB.
+ Long tempRoleId = 0l;
for (ExternalAccessUserRoleDetail userRoleDetail : userRoleDetailList) {
ExternalAccessRole ecRole = userRoleDetail.getRole();
- ExternalAccessRoleDescription roleDesc = ecRole.getDescription();
UserApp userApp = new UserApp();
Role role = new Role();
Set roleFunctions = new TreeSet<>();
- if (roleDesc.getName() == null) {
- role.setActive(true);
- role.setName(ecRole.getName());
- } else {
- role.setActive(Boolean.valueOf(roleDesc.getActive()));
- role.setId(Long.valueOf(roleDesc.getAppRoleId()));
- role.setName(roleDesc.getName());
- if (!roleDesc.getPriority().equals(EcompExternalAuthUtils.EXT_NULL_VALUE)) {
- role.setPriority(Integer.valueOf(roleDesc.getPriority()));
- }
- }
+ role.setId(tempRoleId);
+ role.setActive(true);
+ role.setName(ecRole.getName());
for (ExternalAccessPerms extPerm : ecRole.getPerms()) {
RoleFunction roleFunction = new RoleFunction();
roleFunction.setCode(extPerm.getInstance());
@@ -245,6 +228,7 @@ public class UserApiServiceImpl implements UserApiService {
userApp.setRole(role);
userApp.setUserId(user.getId());
userApps.add(userApp);
+ tempRoleId++;
}
return userApps;
}
@@ -252,10 +236,10 @@ public class UserApiServiceImpl implements UserApiService {
@Override
public List<RoleFunction> getRoleFunctions(String orgUserId) throws Exception {
HttpHeaders headers = getBasicAuthHeaders();
- return aafService.getRoleFunctions(orgUserId,headers);
+ return aafService.getRoleFunctions(orgUserId, headers);
}
-
+ @SuppressWarnings("unused")
private ResponseEntity<String> getPermsFromExternalAuthSystem(HttpEntity<String> entity, String endPoint) {
ResponseEntity<String> getResponse = template.exchange(
EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_URL) + endPoint,
@@ -283,14 +267,13 @@ public class UserApiServiceImpl implements UserApiService {
result = CipherUtil.decryptPKC(encrypted,
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"decryptedPassword failed", e);
+ logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e);
throw e;
}
}
return result;
}
-
-
+
private SearchResult loadSearchResultData(PostSearchBean searchCriteria) throws NamingException {
return ldapService.searchPost(searchCriteria.getUser(), searchCriteria.getSortBy1(),
searchCriteria.getSortBy2(), searchCriteria.getSortBy3(), searchCriteria.getPageNo(),
@@ -302,15 +285,13 @@ public class UserApiServiceImpl implements UserApiService {
String encryptedPass = EcompExternalAuthProperties
.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD);
String appPassword = decryptPass(encryptedPass);
- return aafService.checkUserExists(username,password, appPassword);
+ return aafService.checkUserExists(username, password, appPassword);
}
-
-
@Override
public List<ExternalAccessPerms> getIfUserPermsExists(String username) throws Exception {
HttpHeaders headers = getBasicAuthHeaders();
- return aafService.getIfUserPermsExists(username,headers);
+ return aafService.getIfUserPermsExists(username, headers);
}
} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserApiServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserApiServiceImplTest.java
index 7fa24ad9..0d76b445 100644
--- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserApiServiceImplTest.java
+++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserApiServiceImplTest.java
@@ -230,7 +230,6 @@ public class UserApiServiceImplTest {
userRolesList.add(mockJsonObjectRole4);
userRolesList.add(mockJsonObjectRole5);
mockJsonObjectFinalUserRole.put("role", userRolesList);
- Mockito.when(EcompExternalAuthUtils.isJSONValid(addDesc)).thenReturn(true);
ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(), HttpStatus.OK);
Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response);
@@ -240,6 +239,7 @@ public class UserApiServiceImplTest {
String user = mapper.writeValueAsString(userObj());
Mockito.when(aafService.getUser("test123", mockedRequest, headers)).thenReturn(user);
User actual = UserApiServiceImpl.getUser("test123", mockedRequest);
+ assertNull(actual);
}
@Test