0

非常に単純なセキュリティ構成のアプリケーションがあり、アクチュエータ エンドポイントを保護できないようです。私がSOの他の場所で読んだことから、これらのエンドポイントのセキュリティを無効にするのは簡単ではないように思われるので、私は困惑しています.

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig {
    @Autowired
    private DataSource dataSource;

    @Autowired
    private WebSecurityProperties properties;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.
                jdbcAuthentication()
                .dataSource(dataSource);
    }

    @Configuration
    @Order(0)
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
        @Autowired
        private WebSecurityProperties properties;

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http
                    .csrf().disable()
                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                    .and()
                    .authorizeRequests()
                    .antMatchers("/web/**", "/example/**").hasRole(properties.getApiUserGroup())
                    .and()
                    .httpBasic();
        }
    }

    @Configuration
    public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
        @Autowired
        private WebSecurityProperties properties;

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests()
                    .antMatchers("/index.html")
                    .permitAll()
                    .and()
                    .authorizeRequests()
                    .antMatchers("/**").hasRole(properties.getAdminGroup());
        }
    }
}
4

1 に答える 1

0

OK、設定にいくつか問題があったようです。

  • @EnableWebSecurity アノテーションの使用。どうやらこれはSpring Bootのデフォルトを無効にします。dsyerによると、「@EnableWebSecurity を使用すると、Spring Boot の設定が完全​​にオフになります」
  • 構成アプリケーションの順序を指定できませんでした。@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)具体的には、クラス レベルで宣言しませんでした。

これを機能させるための努力の一環として、構成を単純化し、最終的に次のようになりました。

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private DataSource dataSource;

    @Autowired
    private WebSecurityProperties properties;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.
                jdbcAuthentication()
                .dataSource(dataSource);
   }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            .authorizeRequests()
                .antMatchers("/web/**", "/example/**").hasRole(properties.getApiUserGroup())
                .antMatchers("/index.html").permitAll().and()
            .httpBasic().realmName("API example");
    }
}
于 2016-02-22T18:10:57.490 に答える