@Test public void testController() throws Exception{ MultiValueMap<String, String> mm = new LinkedMultiValueMap<>(); MultiValueMap<String, String> mm1 = new LinkedMultiValueMap<>(); MultiValueMap<String, String> mm2 = new LinkedMultiValueMap<>(); MvcResult mvcResult = mvc.perform(post("/verify") .contentType(MediaType.APPLICATION_JSON) .content("{\"username\":\"john\", \"password\":\"123\", \"mail\":\"isalb@qq.com\", \"img_url\":null}")) .andExpect(status().isOk()) .andReturn(); int result = Integer.valueOf(mvcResult.getResponse().getContentAsString()); mvc.perform(get("/signup?hashCode="+result)) .andExpect(status().isMovedTemporarily()); mvc.perform(get("/signup?hashCode=0")) .andExpect(status().isUnauthorized()); authController.revokeToken("00"); mm.add("username", "john"); mm.add("operation", "-"); mm1.add("username", "johnnull"); mm1.add("operation", "-"); mm2.add("username", "john"); mm2.add("operation", "#"); mvc.perform(post("/grant/role/ROLE_ADMIN") .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mvc.perform(post("/grant/role/ROLE_ADMIN") .params(mm1) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().is(666)); mvc.perform(post("/grant/role/ROLE_ADMIN") .params(mm2) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().is(666)); mm.remove("operation"); mm.add("operation", "+"); mvc.perform(post("/grant/role/ROLE_ADMIN") .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mm.remove("operation"); mm.add("operation", "#"); mvc.perform(post("/grant/role/ROLE_ADMIN") .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().is(666)); mm.remove("operation"); mm.add("operation", "+"); mvc.perform(post("/grant/role/ROLE_ADMIN").with(user("admin").roles("USER","ADMIN")) .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mvc.perform(post("/revoke/authority/comment").with(user("admin").roles("USER","ADMIN")) .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mvc.perform(post("/revoke/authority/comment").with(user("admin").roles("USER","ADMIN")) .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mm.remove("operation"); mm.add("operation", "-"); mvc.perform(post("/revoke/authority/comment") .with(user("admin").roles("USER","ADMIN")) .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mm.remove("operation"); mm.add("operation", "+"); mvc.perform(post("/revoke/authority/comment").with(user("admin").roles("USER","ADMIN")) .params(mm) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()); mvc.perform(post("/revoke/authority/comment").with(user("admin").roles("USER","ADMIN")) .params(mm1) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().is(777)); mvc.perform(post("/revoke/authority/comment").with(user("admin").roles("USER","ADMIN")) .params(mm2) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) .andExpect(status().is(777)); }
@PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") public ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken) { defaultTokenServices.revokeToken(accessToken); return ResponseEntity.ok().body("Logout Succeeded!"); }
AuthController { @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") public ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken) { defaultTokenServices.revokeToken(accessToken); return ResponseEntity.ok().body("Logout Succeeded!"); } }
AuthController { @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") public ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken) { defaultTokenServices.revokeToken(accessToken); return ResponseEntity.ok().body("Logout Succeeded!"); } @Autowired  AuthController(DefaultTokenServices defaultTokenServices); }
AuthController { @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") public ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken) { defaultTokenServices.revokeToken(accessToken); return ResponseEntity.ok().body("Logout Succeeded!"); } @Autowired  AuthController(DefaultTokenServices defaultTokenServices); @GetMapping(value = "/uuid") String uuid(); @GetMapping(value = "/qrcode") byte[] qrcode(@RequestParam("uuid") String uuid); @PutMapping(value = "/settoken") void setToken(@RequestParam("uuid") String uuid, @RequestParam("token") String token); @PostMapping(value = "/verify", produces = "application/json") int verify(@RequestBody User user); @GetMapping(value = "/signup", produces = "application/json") RedirectView create(@RequestParam int hashCode); @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken); @PreAuthorize("hasRole('ADMIN')") @PostMapping(value = "/grant/role/{role}", produces = "application/json") ResponseEntity<?> grantRole(@PathVariable("role") String roleName,
                                       @RequestParam("username") String username,
                                       @RequestParam("operation") String c); @PreAuthorize("hasRole('ADMIN')") @PostMapping(value = "/revoke/authority/{authority}", produces = "application/json") ResponseEntity<?> revokeAuthority(@PathVariable("authority") String authorityName,
                                       @RequestParam("username") String username,
                                       @RequestParam("operation") String c); }
AuthController { @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") public ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken) { defaultTokenServices.revokeToken(accessToken); return ResponseEntity.ok().body("Logout Succeeded!"); } @Autowired  AuthController(DefaultTokenServices defaultTokenServices); @GetMapping(value = "/uuid") String uuid(); @GetMapping(value = "/qrcode") byte[] qrcode(@RequestParam("uuid") String uuid); @PutMapping(value = "/settoken") void setToken(@RequestParam("uuid") String uuid, @RequestParam("token") String token); @PostMapping(value = "/verify", produces = "application/json") int verify(@RequestBody User user); @GetMapping(value = "/signup", produces = "application/json") RedirectView create(@RequestParam int hashCode); @PreAuthorize("hasRole('USER')") @Transactional @DeleteMapping(value = "/exit", produces = "application/json") ResponseEntity<?> revokeToken(@RequestParam("access_token") String accessToken); @PreAuthorize("hasRole('ADMIN')") @PostMapping(value = "/grant/role/{role}", produces = "application/json") ResponseEntity<?> grantRole(@PathVariable("role") String roleName,
                                       @RequestParam("username") String username,
                                       @RequestParam("operation") String c); @PreAuthorize("hasRole('ADMIN')") @PostMapping(value = "/revoke/authority/{authority}", produces = "application/json") ResponseEntity<?> revokeAuthority(@PathVariable("authority") String authorityName,
                                       @RequestParam("username") String username,
                                       @RequestParam("operation") String c);  }