2

我认为这在 xml 配置中很容易,但是当我现在使用 java 代码配置时,我迷路了,所以谁能告诉我如何配置 spring security 以允许对静态资源目录进行非安全检查?

@Override
protected void configure(HttpSecurity http) throws Exception {

    http
    .csrf().disable()

    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
    .and()
    .authorizeRequests().antMatchers(actuatorEndpoints()).hasRole(backendAdminRole)
    .and()
    .authorizeRequests().antMatchers(apiEndpoints()).hasRole(frontendUserRole)
    ***//what code can I add here to make static directory/recourse not checked by spring security?***
    .anyRequest().authenticated()
    .and().anonymous().disable()
    .exceptionHandling().authenticationEntryPoint(unauthorizedEntryPoint());
    ;
}

非常感谢你的好意首先

4

1 回答 1

0

我猜你的意思是这样的我如何在 JavaConfig 中定义 http "security = 'none'?

太好了,但只是不知道为什么这仅适用于 WebSecurity,而不适用于 HttpSecurity,所以如果我想忽略任何内容,我必须覆盖 WebSecurity 签名并放在那里,这也意味着我们必须有两个配置函数来忽略并验证目的?

并不真地。configure(AuthenticationManagerBuilder auth)上还有一个WebSecurityConfigurerAdapter,所以,我认为在不同的域对象之间分配这些职责没有任何问题。另一方面ignore是更常见的安全功能,但http仅限于HTTP。

从另一面看,当您不注意配置中的代码时,您的代码应该更ignored清晰http

于 2015-02-23T20:51:41.843 回答