具有@PreAuthorize的JHipster始终允许访问

问题描述 投票:0回答:1

我的资源有此代码:

    @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

spring-boot jhipster
1个回答
1
投票

正如我的评论中提到的那样-在Configuration中也启用prePostEnabled以激活方法安全性:

© www.soinside.com 2019 - 2024. All rights reserved.