@Test public void test_deleteApproleFromSDB_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserDetails userDetails = getMockUser(false); String jsonStr = "{\"role_name\":\"approle1\",\"path\":\"shared/mysafe01\",\"access\":\"write\"}"; ResponseEntity<String> response = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Role association is removed \"]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Role association is removed \"]}"); when(safesService.removeApproleFromSafe(token, jsonStr)).thenReturn(response); mockIsAuthorized(userDetails, true); Map<String,Object> requestMap = new HashMap<>(); requestMap.put("path", "shared/mysafe01"); requestMap.put("role_name", "aprole1"); requestMap.put("access", "write"); when(ControllerUtil.parseJson(jsonStr)).thenReturn(requestMap); when(ControllerUtil.areSafeAppRoleInputsValid(requestMap)).thenReturn(true); SafeAppRoleAccess safeAppRoleAccess = new SafeAppRoleAccess("aprole1", "shared/mysafe01", "write"); when(JSONUtil.getJSON(Mockito.any(SafeAppRoleAccess.class))).thenReturn(jsonStr); ResponseEntity<String> responseEntity = selfSupportService.deleteApproleFromSDB(userDetails, token, safeAppRoleAccess); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess) { if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to delete this approle\"]}"); } String jsonstr = JSONUtil.getJSON(safeAppRoleAccess); String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.removeApproleFromSafe(token, jsonstr); } else { Map<String,Object> requestMap = ControllerUtil.parseJson(jsonstr); if (ObjectUtils.isEmpty(requestMap.get("role_name")) || ObjectUtils.isEmpty(requestMap.get("path"))) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid role name or path\"]}"); } String path = requestMap.get("path").toString(); ResponseEntity<String> isAuthorized = isAuthorized(userDetails, path); if (!isAuthorized.getStatusCode().equals(HttpStatus.OK)) { return isAuthorized.getStatusCode().equals(HttpStatus.BAD_REQUEST)?isAuthorized:ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Error checking user permission\"]}"); } if (isAuthorized.getBody().equals(TVaultConstants.FALSE)) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{\"errors\":[\"Access denied: no permission to remove approle from the safe\"]}"); } token = userDetails.getSelfSupportToken(); return safesService.removeApproleFromSafe(token, jsonstr); } }
SelfSupportService { public ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess) { if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to delete this approle\"]}"); } String jsonstr = JSONUtil.getJSON(safeAppRoleAccess); String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.removeApproleFromSafe(token, jsonstr); } else { Map<String,Object> requestMap = ControllerUtil.parseJson(jsonstr); if (ObjectUtils.isEmpty(requestMap.get("role_name")) || ObjectUtils.isEmpty(requestMap.get("path"))) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid role name or path\"]}"); } String path = requestMap.get("path").toString(); ResponseEntity<String> isAuthorized = isAuthorized(userDetails, path); if (!isAuthorized.getStatusCode().equals(HttpStatus.OK)) { return isAuthorized.getStatusCode().equals(HttpStatus.BAD_REQUEST)?isAuthorized:ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Error checking user permission\"]}"); } if (isAuthorized.getBody().equals(TVaultConstants.FALSE)) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{\"errors\":[\"Access denied: no permission to remove approle from the safe\"]}"); } token = userDetails.getSelfSupportToken(); return safesService.removeApproleFromSafe(token, jsonstr); } } }
SelfSupportService { public ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess) { if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to delete this approle\"]}"); } String jsonstr = JSONUtil.getJSON(safeAppRoleAccess); String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.removeApproleFromSafe(token, jsonstr); } else { Map<String,Object> requestMap = ControllerUtil.parseJson(jsonstr); if (ObjectUtils.isEmpty(requestMap.get("role_name")) || ObjectUtils.isEmpty(requestMap.get("path"))) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid role name or path\"]}"); } String path = requestMap.get("path").toString(); ResponseEntity<String> isAuthorized = isAuthorized(userDetails, path); if (!isAuthorized.getStatusCode().equals(HttpStatus.OK)) { return isAuthorized.getStatusCode().equals(HttpStatus.BAD_REQUEST)?isAuthorized:ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Error checking user permission\"]}"); } if (isAuthorized.getBody().equals(TVaultConstants.FALSE)) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{\"errors\":[\"Access denied: no permission to remove approle from the safe\"]}"); } token = userDetails.getSelfSupportToken(); return safesService.removeApproleFromSafe(token, jsonstr); } }  }
SelfSupportService { public ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess) { if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to delete this approle\"]}"); } String jsonstr = JSONUtil.getJSON(safeAppRoleAccess); String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.removeApproleFromSafe(token, jsonstr); } else { Map<String,Object> requestMap = ControllerUtil.parseJson(jsonstr); if (ObjectUtils.isEmpty(requestMap.get("role_name")) || ObjectUtils.isEmpty(requestMap.get("path"))) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid role name or path\"]}"); } String path = requestMap.get("path").toString(); ResponseEntity<String> isAuthorized = isAuthorized(userDetails, path); if (!isAuthorized.getStatusCode().equals(HttpStatus.OK)) { return isAuthorized.getStatusCode().equals(HttpStatus.BAD_REQUEST)?isAuthorized:ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Error checking user permission\"]}"); } if (isAuthorized.getBody().equals(TVaultConstants.FALSE)) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{\"errors\":[\"Access denied: no permission to remove approle from the safe\"]}"); } token = userDetails.getSelfSupportToken(); return safesService.removeApproleFromSafe(token, jsonstr); } }  ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> addUserToSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getInfo(UserDetails userDetails, String userToken, String path); ResponseEntity<String> getSafe(UserDetails userDetails, String userToken, String path); ResponseEntity<String> removeUserFromSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getFoldersRecursively(UserDetails userDetails, String userToken, String path); ResponseEntity<String> isAuthorized(UserDetails userDetails, String path); ResponseEntity<String> updateSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> deletefolder(UserDetails userDetails, String userToken, String path); ResponseEntity<String> addGroupToSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> removeGroupFromSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> addAwsRoleToSafe(UserDetails userDetails, String userToken, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(UserDetails userDetails, String userToken, AWSRole awsRole, boolean detachOnly); ResponseEntity<String> associateApproletoSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> createRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> updateRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> createIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> updateIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> getAllSafeNames(UserDetails userDetails); ResponseEntity<String> createAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> getSafes(UserDetails userDetails, String userToken); ResponseEntity<String> readAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> listAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> readAppRole(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String userToken, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> updateAppRole(String userToken, AppRole appRole, UserDetails userDetails); }
SelfSupportService { public ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess) { if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(safeAppRoleAccess.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to delete this approle\"]}"); } String jsonstr = JSONUtil.getJSON(safeAppRoleAccess); String token = userDetails.getClientToken(); if (userDetails.isAdmin()) { return safesService.removeApproleFromSafe(token, jsonstr); } else { Map<String,Object> requestMap = ControllerUtil.parseJson(jsonstr); if (ObjectUtils.isEmpty(requestMap.get("role_name")) || ObjectUtils.isEmpty(requestMap.get("path"))) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid role name or path\"]}"); } String path = requestMap.get("path").toString(); ResponseEntity<String> isAuthorized = isAuthorized(userDetails, path); if (!isAuthorized.getStatusCode().equals(HttpStatus.OK)) { return isAuthorized.getStatusCode().equals(HttpStatus.BAD_REQUEST)?isAuthorized:ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Error checking user permission\"]}"); } if (isAuthorized.getBody().equals(TVaultConstants.FALSE)) { return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{\"errors\":[\"Access denied: no permission to remove approle from the safe\"]}"); } token = userDetails.getSelfSupportToken(); return safesService.removeApproleFromSafe(token, jsonstr); } }  ResponseEntity<String> createSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> addUserToSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getInfo(UserDetails userDetails, String userToken, String path); ResponseEntity<String> getSafe(UserDetails userDetails, String userToken, String path); ResponseEntity<String> removeUserFromSafe(UserDetails userDetails, String userToken, SafeUser safeUser); ResponseEntity<String> getFoldersRecursively(UserDetails userDetails, String userToken, String path); ResponseEntity<String> isAuthorized(UserDetails userDetails, String path); ResponseEntity<String> updateSafe(UserDetails userDetails, String userToken, Safe safe); ResponseEntity<String> deletefolder(UserDetails userDetails, String userToken, String path); ResponseEntity<String> addGroupToSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> removeGroupFromSafe(UserDetails userDetails, String userToken, SafeGroup safeGroup); ResponseEntity<String> addAwsRoleToSafe(UserDetails userDetails, String userToken, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(UserDetails userDetails, String userToken, AWSRole awsRole, boolean detachOnly); ResponseEntity<String> associateApproletoSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> deleteApproleFromSDB(UserDetails userDetails, String userToken, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> createRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> updateRole(UserDetails userDetails, String userToken, AWSLoginRole awsLoginRole, String path); ResponseEntity<String> createIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> updateIAMRole(UserDetails userDetails, String userToken, AWSIAMRole awsiamRole, String path); ResponseEntity<String> getAllSafeNames(UserDetails userDetails); ResponseEntity<String> createAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteAppRole(String userToken, AppRole appRole, UserDetails userDetails); ResponseEntity<String> getSafes(UserDetails userDetails, String userToken); ResponseEntity<String> readAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> listAppRoles(String userToken, UserDetails userDetails); ResponseEntity<String> readAppRole(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String userToken, String rolename, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String userToken, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> updateAppRole(String userToken, AppRole appRole, UserDetails userDetails);  }