@Test @WithMockUser(authorities = "UPDATE_API_KEY") public void updateApiKey() throws Exception { long keyId = 1; apiKeysController.updateKey(keyId, ROLES); verify(apiKeyService).update(keyId, ROLES); verify(publicApiKeyDataConverter).convert((PersistentApiKeyType) any()); }
@PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") public ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id, @RequestBody List<String> roles) { try { PersistentApiKeyType key = apiKeyService.update(id, roles); return new ResponseEntity<>(publicApiKeyDataConverter.convert(key), HttpStatus.OK); } catch (InvalidRoleNameException e) { throw new BadRequestException(e); } catch (ApiKeyService.ApiKeyNotFoundException e) { throw new ResourceNotFoundException(e); } }
ApiKeysController { @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") public ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id, @RequestBody List<String> roles) { try { PersistentApiKeyType key = apiKeyService.update(id, roles); return new ResponseEntity<>(publicApiKeyDataConverter.convert(key), HttpStatus.OK); } catch (InvalidRoleNameException e) { throw new BadRequestException(e); } catch (ApiKeyService.ApiKeyNotFoundException e) { throw new ResourceNotFoundException(e); } } }
ApiKeysController { @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") public ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id, @RequestBody List<String> roles) { try { PersistentApiKeyType key = apiKeyService.update(id, roles); return new ResponseEntity<>(publicApiKeyDataConverter.convert(key), HttpStatus.OK); } catch (InvalidRoleNameException e) { throw new BadRequestException(e); } catch (ApiKeyService.ApiKeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  ApiKeysController(ApiKeyService apiKeyService, PublicApiKeyDataConverter publicApiKeyDataConverter); }
ApiKeysController { @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") public ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id, @RequestBody List<String> roles) { try { PersistentApiKeyType key = apiKeyService.update(id, roles); return new ResponseEntity<>(publicApiKeyDataConverter.convert(key), HttpStatus.OK); } catch (InvalidRoleNameException e) { throw new BadRequestException(e); } catch (ApiKeyService.ApiKeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  ApiKeysController(ApiKeyService apiKeyService, PublicApiKeyDataConverter publicApiKeyDataConverter); @PostMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_CREATE) @PreAuthorize("hasAuthority('CREATE_API_KEY')") ResponseEntity<PublicApiKeyData> createKey(@RequestBody List<String> roles); @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id,
            @RequestBody List<String> roles); @RequestMapping(method = RequestMethod.GET) @PreAuthorize("hasAuthority('VIEW_API_KEYS')") ResponseEntity<Collection<PublicApiKeyData>> list(); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @AuditEventMethod(event = API_KEY_REMOVE) @PreAuthorize("hasAuthority('REVOKE_API_KEY')") ResponseEntity revoke(@PathVariable("id") long id); }
ApiKeysController { @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") public ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id, @RequestBody List<String> roles) { try { PersistentApiKeyType key = apiKeyService.update(id, roles); return new ResponseEntity<>(publicApiKeyDataConverter.convert(key), HttpStatus.OK); } catch (InvalidRoleNameException e) { throw new BadRequestException(e); } catch (ApiKeyService.ApiKeyNotFoundException e) { throw new ResourceNotFoundException(e); } } @Autowired  ApiKeysController(ApiKeyService apiKeyService, PublicApiKeyDataConverter publicApiKeyDataConverter); @PostMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_CREATE) @PreAuthorize("hasAuthority('CREATE_API_KEY')") ResponseEntity<PublicApiKeyData> createKey(@RequestBody List<String> roles); @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuditEventMethod(event = API_KEY_UPDATE) @PreAuthorize("hasAuthority('UPDATE_API_KEY')") ResponseEntity<PublicApiKeyData> updateKey(@PathVariable("id") long id,
            @RequestBody List<String> roles); @RequestMapping(method = RequestMethod.GET) @PreAuthorize("hasAuthority('VIEW_API_KEYS')") ResponseEntity<Collection<PublicApiKeyData>> list(); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @AuditEventMethod(event = API_KEY_REMOVE) @PreAuthorize("hasAuthority('REVOKE_API_KEY')") ResponseEntity revoke(@PathVariable("id") long id); static final String API_KEYS_V1_PATH; }