Java Spring Security protected void configure(HttpSecurity http)请解释“安全”的正确用法;和();。这是什么意思?
我在这个平台和其他平台的许多搜索结果中都有很多例子,但我找不到对“and()”的解释。显然是某种分隔符。可能会执行逻辑AND(&&),但可能不会 我想了解正确的用法和它的作用…它的含义 我希望这个问题突出,答案对其他人有用 参考: 然后在该文件内:Java Spring Security protected void configure(HttpSecurity http)请解释“安全”的正确用法;和();。这是什么意思?,java,spring,spring-security,Java,Spring,Spring Security,我在这个平台和其他平台的许多搜索结果中都有很多例子,但我找不到对“and()”的解释。显然是某种分隔符。可能会执行逻辑AND(&&),但可能不会 我想了解正确的用法和它的作用…它的含义 我希望这个问题突出,答案对其他人有用 参考: 然后在该文件内: protected void configure(HttpSecurity http) throws java.lang.Exception 重写此方法以配置HttpSecurity。通常,子类不应该通过调用su
protected void configure(HttpSecurity http)
throws java.lang.Exception
重写此方法以配置HttpSecurity。通常,子类不应该通过调用super来调用此方法,因为它可能会覆盖它们的配置。默认配置为:
http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
- 让我们以下面的例子为例。两者是等价的
- 实际上,我们在这里配置了不同的配置程序,如本例中的
、ExpressionUrlAuthorizationConfigurer
和FormLoginConConfiguration
。尽管在第一个配置中它们是单独配置的,但它们都是一起应用的。因此,LogoutConfigurer
在这里扮演着逻辑和角色和
- 现在请注意,例如,
的返回类型是.anyRequest().authenticated()
,但方法expressionIntercepturRegistry
仅存在于类型为formLogin()
的对象中,因此在生成器模式HttpSecurity
中起到切换返回类型的第二个作用,也就是说,只要调用,和()
,返回类型就是anyRequest().authenticated().and()
,因此现在它允许您启动HttpSecurity
formLogin()
- 参见显示各点返回类型的
Intellij
和()
基本上是一种人性化的方式,表示“结束本节并返回主配置上下文”。您的解释非常清楚-谢谢。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated();
http.formLogin()
.loginPage("/login")
.permitAll();
http.logout()
.permitAll();
}
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}