Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Security protected void configure(HttpSecurity http)请解释“安全”的正确用法;和();。这是什么意思?_Java_Spring_Spring Security - Fatal编程技术网

Java Spring Security protected void configure(HttpSecurity http)请解释“安全”的正确用法;和();。这是什么意思?

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

我在这个平台和其他平台的许多搜索结果中都有很多例子,但我找不到对“and()”的解释。显然是某种分隔符。可能会执行逻辑AND(&&),但可能不会

我想了解正确的用法和它的作用…它的含义

我希望这个问题突出,答案对其他人有用

参考:

然后在该文件内:

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


和()只返回方法链接的de securityBuilder
和()
基本上是一种人性化的方式,表示“结束本节并返回主配置上下文”。您的解释非常清楚-谢谢。
    @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();
    }