AppRoleService { public ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId){ String jsonStr = JSONUtil.getJSON(appRoleIdSecretId); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "AppRole Login"). put(LogMessage.MESSAGE, "Trying to authenticate with AppRole"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/approle/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "AppRole Login"). put(LogMessage.MESSAGE, "AppRole Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "AppRole Login"). put(LogMessage.MESSAGE, "AppRole Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Approle Login Failed.\"]}" + "HTTP STATUSCODE :" + response.getHttpstatus()); } }  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 );  }
@Test public void test_loginWithApprole_successfully() { String expectedLoginResponse = "{ \"auth\": { \"renewable\": true, \"lease_duration\": 2764800, \"metadata\": {}, \"policies\": [ \"default\" ], \"accessor\": \"5d7fb475-07cb-4060-c2de-1ca3fcbf0c56\", \"client_token\": \"98a4c7ab-b1fe-361b-ba0b-e307aacfd587\" }}"; Response response =getMockResponse(HttpStatus.OK, true, expectedLoginResponse); AppRoleIdSecretId appRoleIdSecretId = new AppRoleIdSecretId("approle1", "5973a6de-38c1-0402-46a3-6d76e38b773c"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(expectedLoginResponse); String jsonStr = "{\"role_id\":\"approle1\",\"secret_id\":\"5973a6de-38c1-0402-46a3-6d76e38b773c\"}"; when(JSONUtil.getJSON(appRoleIdSecretId)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/login",jsonStr,"")).thenReturn(response); ResponseEntity<String> responseEntityActual = appRoleService.login(appRoleIdSecretId); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }