如何允许来自某个url的请求与弹簧安全
问题描述:
我正在开发一个简单的项目,以了解有关spring的一些信息。如何允许来自某个url的请求与弹簧安全
我已经创建了登录页面和所有身份验证管理,现在我正在尝试构建注册页面,我已经完成了后端和前端,但是我遇到了问题。
“保存”送与路径用户/注册 POST请求的按钮,但失败了,网络控制台说:,我认为这是一个安全问题,因为如果我身份验证,然后我尝试注册用户的请求是成功的。 所以,也许我需要说,春季安全,注册请求必须可供所有用户,也为未经认证的。 我把路径用户/注册春季启动,但它不工作,我也只用/注册
@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
使用那一个它说403 – untruste
403是什么请求? –
http:// localhost:8080/user/signup – untruste