跳到主要内容

3.30 Spring Security注解

温馨提醒

增强功能需要通过配置yml配置文件开启增强,自4.0.0开始

knife4j:
enable: true

Knife4j为了满足权限验证将Spring Security的PostAuthorizePostFilterPreAuthorizePreFilter的注解信息追加到接口描述中

代码展示

@RestController
@RequestMapping("/hello")
@PostAuthorize("hasAuthority('class')")
@PostFilter("hasAuthority('class')")
@PreAuthorize("hasAuthority('class')")
@PreFilter("hasAuthority('class')")
public class HelloController {

@GetMapping("/security")
@PostAuthorize("hasAuthority('method')")
@PostFilter("hasAuthority('method')")
@PreAuthorize("hasAuthority('method')")
@PreFilter("hasAuthority('method')")
@ApiOperation(value = "", notes = "Spring Security注解追加到接口描述")
public String security() {
return "hello security";
}
}