[英]Spring Security disable security for requests made FROM a certain url
[英]How to allow request from a certain url with spring security
我正在开发一个简单的项目,以学习一些有关Spring的知识。
我已经创建了登录页面和所有身份验证管理,现在我试图构建注册页面,同时完成了后端和前端,但是我遇到了问题。
网络控制台说302 ,“保存”按钮发送带有路径用户/注册的发布请求,但失败,我认为这是一个安全问题,因为如果我进行身份验证然后尝试注册用户,则请求成功。 因此,也许我需要说起安全性,注册请求必须对所有用户都可用,对于未认证的用户也必须可用。 我将路径user / signup放置在spring boot中,但是它不起作用,我也尝试仅使用/ signup
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/script/**", "/css/**", "/getRegisterPage","user/signup");
}
这是项目: https : //github.com/StefanoPisano/expenses (分支0.2)
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/script/**", "/css/**", "/getRegisterPage","/user/signup").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/getLoginPage")
.loginProcessingUrl("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/home", true)
.permitAll();
}
这个
web.ignoring().antMatchers("/script/**", "/css/**", "/getRegisterPage","/user/signup");
将忽略所有使用这些模式的请求。
您需要的是:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**", "/user/signup").permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/getLoginPage")
.loginProcessingUrl("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/home", true)
.permitAll();
http
.csrf().disable();
}
permitAll()-允许任何人(包括未经身份验证的用户)访问URL。 检查此以获取更多信息https://docs.spring.io/spring-security/site/docs/current/reference/html/jc.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.