@Test public void deleteUserTest() throws Exception { this.mockMvc .perform(MockMvcRequestBuilders.delete(ACCOUNT_USER_URL + "/mouaiccool") .header("Content-Type", "application/json").with(user)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FORBIDDEN_403)); this.mockMvc .perform(MockMvcRequestBuilders.delete(ACCOUNT_USER_URL + "/mouaiccool") .header("Content-Type", "application/json").with(admin)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.NOT_FOUND_404)); OadrUserCreateDto dto = new OadrUserCreateDto(); dto.setCommonName("myuser"); dto.setUsername("myuser"); dto.setAuthenticationType("login"); dto.setPassword("pass"); byte[] content = mapper.writeValueAsBytes(dto); MvcResult andReturn = this.mockMvc .perform(MockMvcRequestBuilders.post(ACCOUNT_USER_URL).content(content) .header("Content-Type", "application/json").with(admin)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn(); assertEquals(0, andReturn.getResponse().getContentLength()); OadrUser findByUsername = oadrUserService.findByUsername("myuser"); assertNotNull(findByUsername); this.mockMvc .perform(MockMvcRequestBuilders.delete(ACCOUNT_USER_URL + "/myuser") .header("Content-Type", "application/json").with(admin)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)); findByUsername = oadrUserService.findByUsername("myuser"); assertNull(findByUsername); }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody public void deleteUser(@PathVariable("username") String username, HttpServletResponse response) { OadrUser findByUsername = oadrUserService.findByUsername(username); if (findByUsername == null) { LOGGER.warn("Unknown User: " + username); response.setStatus(HttpStatus.NOT_FOUND_404); return; } oadrUserService.delete(findByUsername); LOGGER.info("Delete Ven: " + findByUsername.getUsername()); }
AccountController { @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody public void deleteUser(@PathVariable("username") String username, HttpServletResponse response) { OadrUser findByUsername = oadrUserService.findByUsername(username); if (findByUsername == null) { LOGGER.warn("Unknown User: " + username); response.setStatus(HttpStatus.NOT_FOUND_404); return; } oadrUserService.delete(findByUsername); LOGGER.info("Delete Ven: " + findByUsername.getUsername()); } }
AccountController { @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody public void deleteUser(@PathVariable("username") String username, HttpServletResponse response) { OadrUser findByUsername = oadrUserService.findByUsername(username); if (findByUsername == null) { LOGGER.warn("Unknown User: " + username); response.setStatus(HttpStatus.NOT_FOUND_404); return; } oadrUserService.delete(findByUsername); LOGGER.info("Delete Ven: " + findByUsername.getUsername()); }  }
AccountController { @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody public void deleteUser(@PathVariable("username") String username, HttpServletResponse response) { OadrUser findByUsername = oadrUserService.findByUsername(username); if (findByUsername == null) { LOGGER.warn("Unknown User: " + username); response.setStatus(HttpStatus.NOT_FOUND_404); return; } oadrUserService.delete(findByUsername); LOGGER.info("Delete Ven: " + findByUsername.getUsername()); }  @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVICE_MANAGER') or hasRole('ROLE_DRPROGRAM')") AbstractUserWithRoleDto registeredUser(Principal principal); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.GET) @ResponseBody List<OadrUserDto> listUser(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createUser(@RequestBody OadrUserCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteUser(@PathVariable("username") String username, HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.GET) @ResponseBody List<OadrAppDto> listApp(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createApp(@RequestBody OadrAppCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteApp(@PathVariable("username") String username, HttpServletResponse response); }
AccountController { @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody public void deleteUser(@PathVariable("username") String username, HttpServletResponse response) { OadrUser findByUsername = oadrUserService.findByUsername(username); if (findByUsername == null) { LOGGER.warn("Unknown User: " + username); response.setStatus(HttpStatus.NOT_FOUND_404); return; } oadrUserService.delete(findByUsername); LOGGER.info("Delete Ven: " + findByUsername.getUsername()); }  @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVICE_MANAGER') or hasRole('ROLE_DRPROGRAM')") AbstractUserWithRoleDto registeredUser(Principal principal); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.GET) @ResponseBody List<OadrUserDto> listUser(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createUser(@RequestBody OadrUserCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteUser(@PathVariable("username") String username, HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.GET) @ResponseBody List<OadrAppDto> listApp(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createApp(@RequestBody OadrAppCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteApp(@PathVariable("username") String username, HttpServletResponse response);  }