我的资源有此代码:
@DeleteMapping("/devices/{id}")
@Timed
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
public ResponseEntity<Void> deleteDevice(@PathVariable Long id) {
log.debug("REST request to delete Device : {}", id);
deviceService.delete(id);
return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString())).build();
}
应该仅由具有'ROLE_ADMIN'的用户执行。但是,任何登录的用户都可以运行它,即使他们不具有ROLE_ADMIN权限。
我也尝试通过添加
.antMatchers(HttpMethod.DELETE,"/api/**").hasAuthority(AuthoritiesConstants.ADMIN)
在SecurityConfiguration上,但是从不阻止请求。我想念什么?我正在使用JHipster 6.9.1
正如我的评论中提到的那样-在Configuration
中也启用prePostEnabled以激活方法安全性: