【发布时间】:2021-06-18 10:42:49
【问题描述】:
我正在尝试通过以下方式应用 URl 和基于角色的身份验证
http
.authorizeRequests()
.antMatchers("/rest/**").hasRole("ADMIN")
.and()
.authorizeRequests()
.antMatchers("/admin/**").hasRole("MANAGER")
.and()
.authorizeRequests()
.antMatchers("/restApi/**").hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin()
.permitAll();
但是在输入用户名和密码后,我又回到了 Spring Boot 提供的默认登录屏幕。
如果我使用permitAll() 而不是hasRole(),那么它可以正常工作。
我哪里错了?
【问题讨论】:
-
最后
permitAll()有什么意义? -
你叫什么网址?
-
您在哪里将角色应用到您的用户?
标签: spring spring-boot spring-mvc spring-security