Spring security Spring安全性和()方法

Spring security Spring安全性和()方法,spring-security,Spring Security,在spring framework security中,有一个示例: http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") 1 .permitAll(); 有人知道什么时候使用和()吗?它是在ExpressionUrlAuthorizationConfigurer.Expr

在spring framework security中,有一个示例:

http
    .authorizeRequests()
        .anyRequest().authenticated()
        .and()
    .formLogin()
        .loginPage("/login") 1
        .permitAll();  
有人知道什么时候使用和()吗?它是在ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry中定义的,不容易阅读springs文档,似乎是为了混淆。

和()。在特定配置器上配置完选项后,通常会使用
和()
方法。那么比如说,

http
    .someConfigurer
        .<some feature of configurer>()
        .<some feature of configurer>()
        .and()
    .someOtherConfigurer
        .<some feature of someOtherConfigurer>()
        ...
        .and()
     ...
配置器之后的下一级是要调整的特定配置器的属性。例如

formLogin()
    .loginPage("/login")
    .permitAll()
    .and()
最后的
和()。因此,我们可以使用
和()

方法本身来自类。
ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
中的
and()
方法依次调用上述方法。

基本上and()方法用于连接Spring Security的多个配置器
您可以参考所附图片以更清楚地理解

我将问题解释为为什么需要为某些方法而不是其他方法添加“and()”

对于这一点,我的答案是它取决于前面方法的返回类型

当返回类型为HttpSecurity时,无需添加“and()”
例如 crsf().disable():返回类型HttpSecurity
(我不明白为什么返回类型是HttpSecurity,可能它调用了disable函数,因此没有返回任何内容?)

为其他退货类型添加“和()
例如 cors():返回类型CorsConfigurer
formLogin():返回类型FormLoginConfiguler

以文本而不是图像的形式发布代码。您能否发布一些最低限度的代码示例来演示这一点?
formLogin()
    .loginPage("/login")
    .permitAll()
    .and()