我有一个典型的安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
//http.authorizeRequests().antMatchers("/resources/**").permitAll().anyRequest().permitAll();
}
现在 spring 要求登录除登录页面之外的所有内容...但是我怎样才能以其他方式登录,因此它仅要求 View /索引登录页面?是否仅适用于一组端点? 谢谢!
最佳答案
试试这个:
http
.authorizeRequests()
.antMatchers("/", "/index").authenticated()//Makes / and /index to be authenthicated
.anyRequest().permitAll()//Makes any other allow without authentication. Or if you want a group use antMatchers here too.
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
关于java - 仅将 Spring Security 应用于一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61273204/