-
/index 公共资源
-
/hello .... 受保护资源 权限管理
在项目中添加如下配置就可以实现对资源权限规则设定:
@Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.mvcMatchers("/index").permitAll()
.anyRequest().authenticated()
.and().formLogin();
}
}
# 说明 - permitAll() 代表放行该资源,该资源为公共资源 无需认证和授权可以直接访问 - anyRequest().authenticated() 代表所有请求,必须认证之后才能访问 - formLogin() 代表开启表单认证 ## 注意: 放行资源必须放在所有认证请求之前!



