Spring Security:HttpSecurity vs WebSecurity

huangapple 未分类评论42阅读模式
英文:

Spring Security : HttpSecurity vs WebSecurity

问题

我无法区分以下 HttpSecurity 和 WebSecurity 方法。

@Override
public void configure(WebSecurity webSecurity) throws Exception {
    webSecurity
    .ignoring()
    .antMatchers(HttpMethod.POST, "/api/v1/register");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .authorizeRequests().antMatchers(HttpMethod.POST, "/api/v1/register").permitAll();
}
ignoring() 和 permitAll() 使得URL成为开放URL,从而允许未经身份验证的用户访问。
但是何时使用哪种方法?

HttpSecurity.authenticated() 方法允许所有经过身份验证的用户访问,无论其角色如何。

然而,WebSecurity.ignoring() 和 HttpSecurity.permitAll() 之间有什么区别呢?
英文:

I'm unable to differentiate between the following HttpSecurity and WebSecurity methods.

@Override
public void configure(WebSecurity webSecurity) throws Exception {
	webSecurity
	.ignoring()
	.antMatchers(HttpMethod.POST, "/api/v1/register");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
	http
	.authorizeRequests().antMatchers(HttpMethod.POST, "/api/v1/register").permitAll();
}

ignoring() and permitAll() makes the URLs as open URL, thus giving access to un-authenticated users also.
But when to use which method ?

HttpSecurity.authenticated() method gives access to all authenticated users, irrespective of role.

But, what is the difference between WebSecurity. ignoring() and HttpSecurity.permitAll() ?

huangapple
  • 本文由 发表于 2020年4月5日 17:07:19
  • 转载请务必保留本文链接:https://java.coder-hub.com/61040283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定