@Test public void test_readAppRoleBasicDetails_successfully() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String role_name = "testapprole01"; ArrayList<String> policiesList = new ArrayList<String>(); policiesList.add("r_shared_safe01"); String[] policies = policiesList.toArray(new String[policiesList.size()]); AppRole appRoleExpected = new AppRole(role_name, policies, true, 0, 0, 0); String responseJson = new ObjectMapper().writeValueAsString(appRoleExpected); Response response = getMockResponse(HttpStatus.OK, true, responseJson); Map<String, Object> responseMap = new HashMap<>(); Map<String, Object> dataMap = new HashMap<>(); responseMap.put("data", dataMap); dataMap.put("policies",policiesList); dataMap.put("bind_secret_id",new Boolean(true)); dataMap.put("secret_id_num_uses", new Integer(0)); dataMap.put("secret_id_ttl", new Integer(0)); dataMap.put("token_num_uses", new Integer(0)); dataMap.put("token_ttl", new Integer(0)); dataMap.put("token_max_ttl", new Integer(0)); when(ControllerUtil.parseJson(responseJson)).thenReturn(responseMap); when(reqProcessor.process("/auth/approle/role/read", "{\"role_name\":\""+role_name+"\"}",token)).thenReturn(response); AppRole approleActual = appRoleService.readAppRoleBasicDetails(token, role_name); assertNotNull(approleActual); assertNotNull(approleActual.getRole_name()); assertEquals(role_name, approleActual.getRole_name()); }
public AppRole readAppRoleBasicDetails(String token, String rolename) { AppRole appRole = null; if (TVaultConstants.HIDEMASTERAPPROLE && 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, "getAppRole"). put(LogMessage.MESSAGE, "Access denied: Not enough permission to read the AppRole information"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Response readResponse = reqProcessor.process("/auth/approle/role/read","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Map<String,Object> appRoleMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMap != null) { String[] policies = null; if (appRoleMap.get("policies") != null && ((ArrayList<String>)appRoleMap.get("policies")) != null) { ArrayList<String> policiesList = ((ArrayList<String>)appRoleMap.get("policies")); policies = policiesList.toArray(new String[policiesList.size()]); } appRole = new AppRole(rolename, policies, ((Boolean)appRoleMap.get("bind_secret_id")).booleanValue(), ((Integer) appRoleMap.get("secret_id_num_uses")), ((Integer) appRoleMap.get("secret_id_ttl")), (Integer)appRoleMap.get("token_num_uses"), (Integer)appRoleMap.get("token_ttl"), (Integer)appRoleMap.get("token_max_ttl") ); } return appRole; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; }
AppRoleService { public AppRole readAppRoleBasicDetails(String token, String rolename) { AppRole appRole = null; if (TVaultConstants.HIDEMASTERAPPROLE && 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, "getAppRole"). put(LogMessage.MESSAGE, "Access denied: Not enough permission to read the AppRole information"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Response readResponse = reqProcessor.process("/auth/approle/role/read","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Map<String,Object> appRoleMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMap != null) { String[] policies = null; if (appRoleMap.get("policies") != null && ((ArrayList<String>)appRoleMap.get("policies")) != null) { ArrayList<String> policiesList = ((ArrayList<String>)appRoleMap.get("policies")); policies = policiesList.toArray(new String[policiesList.size()]); } appRole = new AppRole(rolename, policies, ((Boolean)appRoleMap.get("bind_secret_id")).booleanValue(), ((Integer) appRoleMap.get("secret_id_num_uses")), ((Integer) appRoleMap.get("secret_id_ttl")), (Integer)appRoleMap.get("token_num_uses"), (Integer)appRoleMap.get("token_ttl"), (Integer)appRoleMap.get("token_max_ttl") ); } return appRole; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } }
AppRoleService { public AppRole readAppRoleBasicDetails(String token, String rolename) { AppRole appRole = null; if (TVaultConstants.HIDEMASTERAPPROLE && 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, "getAppRole"). put(LogMessage.MESSAGE, "Access denied: Not enough permission to read the AppRole information"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Response readResponse = reqProcessor.process("/auth/approle/role/read","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Map<String,Object> appRoleMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMap != null) { String[] policies = null; if (appRoleMap.get("policies") != null && ((ArrayList<String>)appRoleMap.get("policies")) != null) { ArrayList<String> policiesList = ((ArrayList<String>)appRoleMap.get("policies")); policies = policiesList.toArray(new String[policiesList.size()]); } appRole = new AppRole(rolename, policies, ((Boolean)appRoleMap.get("bind_secret_id")).booleanValue(), ((Integer) appRoleMap.get("secret_id_num_uses")), ((Integer) appRoleMap.get("secret_id_ttl")), (Integer)appRoleMap.get("token_num_uses"), (Integer)appRoleMap.get("token_ttl"), (Integer)appRoleMap.get("token_max_ttl") ); } return appRole; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; }  }
AppRoleService { public AppRole readAppRoleBasicDetails(String token, String rolename) { AppRole appRole = null; if (TVaultConstants.HIDEMASTERAPPROLE && 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, "getAppRole"). put(LogMessage.MESSAGE, "Access denied: Not enough permission to read the AppRole information"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Response readResponse = reqProcessor.process("/auth/approle/role/read","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Map<String,Object> appRoleMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMap != null) { String[] policies = null; if (appRoleMap.get("policies") != null && ((ArrayList<String>)appRoleMap.get("policies")) != null) { ArrayList<String> policiesList = ((ArrayList<String>)appRoleMap.get("policies")); policies = policiesList.toArray(new String[policiesList.size()]); } appRole = new AppRole(rolename, policies, ((Boolean)appRoleMap.get("bind_secret_id")).booleanValue(), ((Integer) appRoleMap.get("secret_id_num_uses")), ((Integer) appRoleMap.get("secret_id_ttl")), (Integer)appRoleMap.get("token_num_uses"), (Integer)appRoleMap.get("token_ttl"), (Integer)appRoleMap.get("token_max_ttl") ); } return appRole; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; }  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 AppRole readAppRoleBasicDetails(String token, String rolename) { AppRole appRole = null; if (TVaultConstants.HIDEMASTERAPPROLE && 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, "getAppRole"). put(LogMessage.MESSAGE, "Access denied: Not enough permission to read the AppRole information"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Response readResponse = reqProcessor.process("/auth/approle/role/read","{\"role_name\":\""+rolename+"\"}",token); Map<String, Object> responseMap = null; if(HttpStatus.OK.equals(readResponse.getHttpstatus())) { responseMap = ControllerUtil.parseJson(readResponse.getResponse()); if(responseMap.isEmpty()) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; } Map<String,Object> appRoleMap = (Map<String,Object>) responseMap.get("data"); if (appRoleMap != null) { String[] policies = null; if (appRoleMap.get("policies") != null && ((ArrayList<String>)appRoleMap.get("policies")) != null) { ArrayList<String> policiesList = ((ArrayList<String>)appRoleMap.get("policies")); policies = policiesList.toArray(new String[policiesList.size()]); } appRole = new AppRole(rolename, policies, ((Boolean)appRoleMap.get("bind_secret_id")).booleanValue(), ((Integer) appRoleMap.get("secret_id_num_uses")), ((Integer) appRoleMap.get("secret_id_ttl")), (Integer)appRoleMap.get("token_num_uses"), (Integer)appRoleMap.get("token_ttl"), (Integer)appRoleMap.get("token_max_ttl") ); } return appRole; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getAppRole"). put(LogMessage.MESSAGE, "Reading AppRole failed"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return appRole; }  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 );  }