@Test public void test_createAppRole() throws Exception { String [] policies = {"default"}; AppRole appRole = new AppRole("approle1", policies, true, 1, 100, 0); String inputJson =new ObjectMapper().writeValueAsString(appRole); String responseMessage = "{\"messages\":[\"AppRole created succssfully\"]}"; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseMessage); UserDetails userDetails = getMockUser(true); when(appRoleService.createAppRole(eq("5PDrOhsy4ig8L3EpsJZSLAMg"), Mockito.any(), eq(userDetails))).thenReturn(responseEntityExpected); mockMvc.perform(MockMvcRequestBuilders.post("/v2/auth/approle/role").requestAttr("UserDetails", userDetails) .header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg") .header("Content-Type", "application/json;charset=UTF-8") .content(inputJson)) .andExpect(status().isOk()) .andExpect(content().string(containsString(responseMessage))); }
@ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") public ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return appRoleService.createAppRole(token, appRole, userDetails); }
AppRoleControllerV2 { @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") public ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return appRoleService.createAppRole(token, appRole, userDetails); } }
AppRoleControllerV2 { @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") public ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return appRoleService.createAppRole(token, appRole, userDetails); }  }
AppRoleControllerV2 { @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") public ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return appRoleService.createAppRole(token, appRole, userDetails); }  @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole); @ApiOperation(value = "${AppRoleControllerV2.associateApprole.value}", notes = "${AppRoleControllerV2.associateApprole.notes}") @PostMapping(value="/v2/auth/approle/associateApprole",produces="application/json") ResponseEntity<String> associateApprole(@RequestHeader(value="vault-token") String token, @RequestBody SafeAppRoleAccess safeAppRoleAccess); @ApiOperation(value = "${AppRoleControllerV2.readAppRole.value}", notes = "${AppRoleControllerV2.readAppRole.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}",produces="application/json") ResponseEntity<String> readAppRole(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.listAppRoles.value}", notes = "${AppRoleControllerV2.listAppRoles.notes}") @GetMapping (value="/v2/auth/approle/role",produces="application/json") ResponseEntity<String> getAppRoles(@RequestHeader(value="vault-token") String token); @ApiOperation(value = "${AppRoleControllerV2.readAppRoleRoleId.value}", notes = "${AppRoleControllerV2.readAppRoleRoleId.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}/role_id",produces="application/json") ResponseEntity<String> readAppRoleRoleId(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.deleteAppRole.value}", notes = "${AppRoleControllerV2.deleteAppRole.notes}") @DeleteMapping(value="/v2/auth/approle/role/{role_name}",produces="application/json") ResponseEntity<String> deleteAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.createsecretId.value}", notes = "${AppRoleControllerV2.createsecretId.notes}") @PostMapping(value="/v2/auth/approle/role/secret_id", consumes="application/json", produces="application/json") ResponseEntity<String> createsecretId(@RequestHeader(value="vault-token") String token, @RequestBody AppRoleSecretData appRoleSecretData); @ApiOperation(value = "${AppRoleControllerV2.deleteSecretId.value}", notes = "${AppRoleControllerV2.deleteSecretId.notes}") @DeleteMapping(value="/v2/auth/approle/role/secret_id",produces="application/json") ResponseEntity<String> deleteSecretId(@RequestHeader(value="vault-token") String token,  @RequestBody AppRoleNameSecretId appRoleNameSecretId); @ApiOperation(value = "${AppRoleControllerV2.readSecretId.value}", notes = "${AppRoleControllerV2.readSecretId.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}/secret_id",produces="application/json") ResponseEntity<String> readSecretId(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.login.value}", notes = "${AppRoleControllerV2.login.notes}") @PostMapping(value="/v2/auth/approle/login",produces="application/json") ResponseEntity<String> login(@RequestBody AppRoleIdSecretId appRoleIdSecretId); }
AppRoleControllerV2 { @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") public ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return appRoleService.createAppRole(token, appRole, userDetails); }  @ApiOperation(value = "${AppRoleControllerV2.createAppRole.value}", notes = "${AppRoleControllerV2.createAppRole.notes}") @PostMapping(value="/v2/auth/approle/role", consumes="application/json", produces="application/json") ResponseEntity<String> createAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody AppRole appRole); @ApiOperation(value = "${AppRoleControllerV2.associateApprole.value}", notes = "${AppRoleControllerV2.associateApprole.notes}") @PostMapping(value="/v2/auth/approle/associateApprole",produces="application/json") ResponseEntity<String> associateApprole(@RequestHeader(value="vault-token") String token, @RequestBody SafeAppRoleAccess safeAppRoleAccess); @ApiOperation(value = "${AppRoleControllerV2.readAppRole.value}", notes = "${AppRoleControllerV2.readAppRole.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}",produces="application/json") ResponseEntity<String> readAppRole(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.listAppRoles.value}", notes = "${AppRoleControllerV2.listAppRoles.notes}") @GetMapping (value="/v2/auth/approle/role",produces="application/json") ResponseEntity<String> getAppRoles(@RequestHeader(value="vault-token") String token); @ApiOperation(value = "${AppRoleControllerV2.readAppRoleRoleId.value}", notes = "${AppRoleControllerV2.readAppRoleRoleId.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}/role_id",produces="application/json") ResponseEntity<String> readAppRoleRoleId(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.deleteAppRole.value}", notes = "${AppRoleControllerV2.deleteAppRole.notes}") @DeleteMapping(value="/v2/auth/approle/role/{role_name}",produces="application/json") ResponseEntity<String> deleteAppRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.createsecretId.value}", notes = "${AppRoleControllerV2.createsecretId.notes}") @PostMapping(value="/v2/auth/approle/role/secret_id", consumes="application/json", produces="application/json") ResponseEntity<String> createsecretId(@RequestHeader(value="vault-token") String token, @RequestBody AppRoleSecretData appRoleSecretData); @ApiOperation(value = "${AppRoleControllerV2.deleteSecretId.value}", notes = "${AppRoleControllerV2.deleteSecretId.notes}") @DeleteMapping(value="/v2/auth/approle/role/secret_id",produces="application/json") ResponseEntity<String> deleteSecretId(@RequestHeader(value="vault-token") String token,  @RequestBody AppRoleNameSecretId appRoleNameSecretId); @ApiOperation(value = "${AppRoleControllerV2.readSecretId.value}", notes = "${AppRoleControllerV2.readSecretId.notes}") @GetMapping(value="/v2/auth/approle/role/{role_name}/secret_id",produces="application/json") ResponseEntity<String> readSecretId(@RequestHeader(value="vault-token") String token, @PathVariable("role_name" ) String rolename); @ApiOperation(value = "${AppRoleControllerV2.login.value}", notes = "${AppRoleControllerV2.login.notes}") @PostMapping(value="/v2/auth/approle/login",produces="application/json") ResponseEntity<String> login(@RequestBody AppRoleIdSecretId appRoleIdSecretId);  }