@Test public void test_readAccessorIds_failure() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String role_name = "testapprole01"; String responseJson = "{\r\n" + " \"error\": [\r\n" + " \"\"\r\n" + " ]\r\n" + "}"; Response response = getMockResponse(HttpStatus.NOT_FOUND, true, responseJson); Map<String, Object> responseMap = new HashMap<>(); ArrayList<String> accessorIds = new ArrayList<String>(); accessorIds.add("generated-accessor-id1"); responseMap.put("keys", accessorIds); when(ControllerUtil.parseJson(responseJson)).thenReturn(responseMap); when(reqProcessor.process("/auth/approle/role/accessors/list", "{\"role_name\":\""+role_name+"\"}",token)).thenReturn(response); List<String> actualAccessorIds = appRoleService.readAccessorIds(token, role_name); assertEquals(null, actualAccessorIds); }
public List<String> readAccessorIds(String token, String rolename) { ArrayList<String> accessorIds = null; if (rolename.equals(TVaultConstants.SELF_SERVICE_APPROLE_NAME)) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Access denied: no permission to read roleID of this AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, String.format("Trying to read accessor_id for [%s]", rolename)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/role/accessors/list","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(response.getHttpstatus())) { responseMap = ControllerUtil.parseJson(response.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Reading accessor_ids for AppRole failed. No accessor_id information available."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } accessorIds = (ArrayList<String>) responseMap.get("keys"); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsOfSecretIds"). put(LogMessage.MESSAGE, "Reading accessors of all the SecretIDs for AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; }
AppRoleService { public List<String> readAccessorIds(String token, String rolename) { ArrayList<String> accessorIds = null; if (rolename.equals(TVaultConstants.SELF_SERVICE_APPROLE_NAME)) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Access denied: no permission to read roleID of this AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, String.format("Trying to read accessor_id for [%s]", rolename)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/role/accessors/list","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(response.getHttpstatus())) { responseMap = ControllerUtil.parseJson(response.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Reading accessor_ids for AppRole failed. No accessor_id information available."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } accessorIds = (ArrayList<String>) responseMap.get("keys"); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsOfSecretIds"). put(LogMessage.MESSAGE, "Reading accessors of all the SecretIDs for AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } }
AppRoleService { public List<String> readAccessorIds(String token, String rolename) { ArrayList<String> accessorIds = null; if (rolename.equals(TVaultConstants.SELF_SERVICE_APPROLE_NAME)) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Access denied: no permission to read roleID of this AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, String.format("Trying to read accessor_id for [%s]", rolename)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/role/accessors/list","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(response.getHttpstatus())) { responseMap = ControllerUtil.parseJson(response.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Reading accessor_ids for AppRole failed. No accessor_id information available."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } accessorIds = (ArrayList<String>) responseMap.get("keys"); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsOfSecretIds"). put(LogMessage.MESSAGE, "Reading accessors of all the SecretIDs for AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; }  }
AppRoleService { public List<String> readAccessorIds(String token, String rolename) { ArrayList<String> accessorIds = null; if (rolename.equals(TVaultConstants.SELF_SERVICE_APPROLE_NAME)) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Access denied: no permission to read roleID of this AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, String.format("Trying to read accessor_id for [%s]", rolename)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/role/accessors/list","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(response.getHttpstatus())) { responseMap = ControllerUtil.parseJson(response.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Reading accessor_ids for AppRole failed. No accessor_id information available."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } accessorIds = (ArrayList<String>) responseMap.get("keys"); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsOfSecretIds"). put(LogMessage.MESSAGE, "Reading accessors of all the SecretIDs for AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; }  ResponseEntity<String> createAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> readAppRole(String token, String rolename); ResponseEntity<String> readAppRoles(String token); ResponseEntity<String> listAppRoles(String token,  UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String token, String rolename); String readRoleId(String token, String rolename); List<String> readAccessorIds(String token, String rolename); AppRoleMetadata readAppRoleMetadata(String token, String rolename); AppRole readAppRoleBasicDetails(String token, String rolename); ResponseEntity<String> readAppRoleRoleId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String token, String rolename, UserDetails userDetails); ResponseEntity<String> createsecretId(String token, AppRoleSecretData appRoleSecretData); ResponseEntity<String> readAppRoleSecretId(String token, String rolename); ResponseEntity<String> deleteSecretId(String token, AppRoleNameSecretId appRoleNameSecretId); ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String token, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId); ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> updateAppRole(String token, AppRole appRole, UserDetails userDetails); Response configureApprole(String rolename,String policies,String token ); }
AppRoleService { public List<String> readAccessorIds(String token, String rolename) { ArrayList<String> accessorIds = null; if (rolename.equals(TVaultConstants.SELF_SERVICE_APPROLE_NAME)) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Access denied: no permission to read roleID of this AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, String.format("Trying to read accessor_id for [%s]", rolename)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/role/accessors/list","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(response.getHttpstatus())) { responseMap = ControllerUtil.parseJson(response.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsIds"). put(LogMessage.MESSAGE, "Reading accessor_ids for AppRole failed. No accessor_id information available."). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; } accessorIds = (ArrayList<String>) responseMap.get("keys"); return accessorIds; } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "readAccessorsOfSecretIds"). put(LogMessage.MESSAGE, "Reading accessors of all the SecretIDs for AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return accessorIds; }  ResponseEntity<String> createAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> readAppRole(String token, String rolename); ResponseEntity<String> readAppRoles(String token); ResponseEntity<String> listAppRoles(String token,  UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String token, String rolename); String readRoleId(String token, String rolename); List<String> readAccessorIds(String token, String rolename); AppRoleMetadata readAppRoleMetadata(String token, String rolename); AppRole readAppRoleBasicDetails(String token, String rolename); ResponseEntity<String> readAppRoleRoleId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String token, String rolename, UserDetails userDetails); ResponseEntity<String> createsecretId(String token, AppRoleSecretData appRoleSecretData); ResponseEntity<String> readAppRoleSecretId(String token, String rolename); ResponseEntity<String> deleteSecretId(String token, AppRoleNameSecretId appRoleNameSecretId); ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String token, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId); ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> updateAppRole(String token, AppRole appRole, UserDetails userDetails); Response configureApprole(String rolename,String policies,String token );  }