微服务 教程
1085个小节阅读:195.4k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
我们要对接口进行鉴权配置,即用户拥有权限才能访问接口。
开启鉴权配置注解
xxxxxxxxxx
// Security配置类
@Configuration
// 开启鉴权配置注解
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter{
}
在需要鉴权的接口上方添加鉴权注解
xxxxxxxxxx
@Controller
@RequestMapping("/backstage/admin")
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping("/all")
@PreAuthorize("hasAnyAuthority('/admin/all')")
public ModelAndView all(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
}
}
@Controller
@RequestMapping("/backstage/role")
public class RoleController {
@Autowired
private RoleService roleService;
@RequestMapping("/all")
@PreAuthorize("hasAnyAuthority('/role/all')")
public ModelAndView all(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
}
}
@Controller
@RequestMapping("/backstage/permission")
public class PermissionController {
@Autowired
private PermissionService permissionService;
@RequestMapping("/all")
@PreAuthorize("hasAnyAuthority('/permission/all')")
public ModelAndView all(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
}
}
使用不同权限的用户登录,查看他们是否能访问这些接口