6

は、これは私の春ブーツ1.5.1アクチュエータapplication.propertiesです:春ブーツアクチュエータのエンドポイントセキュリティはカスタム春のセキュリティ設定では動作しません

#Spring Boot Actuator 
management.contextPath: /actuator 
management.security.roles=R_0 

これは私のWebSecurityConfigです:

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private UserDetailsService userDetailsService; 

    @Value("${logout.success.url}") 
    private String logoutSuccessUrl; 

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

     // @formatter:off 
     http.addFilterBefore(new CorsFilter(), ChannelProcessingFilter.class); 

     http 
      .csrf().ignoringAntMatchers("/v1.0/**", "/logout") 
     .and() 
      .authorizeRequests() 

      .antMatchers("/oauth/authorize").authenticated() 
      //Anyone can access the urls 
      .antMatchers("/signin/**").permitAll() 
      .antMatchers("/v1.0/**").permitAll() 
      .antMatchers("/auth/**").permitAll() 
      .antMatchers("/actuator/health").permitAll() 
      .antMatchers("/actuator/**").hasAuthority("R_0") 
      .antMatchers("/login").permitAll() 
      .anyRequest().authenticated() 
     .and() 
      .formLogin() 
       .loginPage("/login") 
       .loginProcessingUrl("/login") 
       .failureUrl("/login?error=true") 
       .usernameParameter("username") 
       .passwordParameter("password") 
       .permitAll() 
      .and() 
       .logout() 
        .logoutUrl("/logout") 
        .logoutSuccessUrl(logoutSuccessUrl) 
        .permitAll(); 
     // @formatter:on 
    } 

    /** 
    * Configures the authentication manager bean which processes authentication requests. 
    */ 
    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder()); 
    } 

    @Override 
    @Bean 
    public AuthenticationManager authenticationManagerBean() throws Exception { 
     return super.authenticationManagerBean(); 
    } 

} 

今私R_0権限を持っているが、私がアクセスしようとしているときに私のアプリケーションにログインできました。

http://localhost:8080/api/actuator/beans 

私は、次のエラーが表示されます

There was an unexpected error (type=Forbidden, status=403). 
Access is denied. User must have one of the these roles: R_0 

正しく正しいAuthenticationについて知っておくために、春ブーツアクチュエータを構成するにはどのように?それは私が次のトリックを行う必要が働い得るために今

management.security.enabled=false 

.antMatchers("/actuator/health").permitAll() 
.antMatchers("/actuator/**").hasAuthority("R_0") 

は正しい方法でアクチュエータを構成するためのチャンスですか?

http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html

By default all sensitive HTTP endpoints are secured such that only users that have an ACTUATOR role may access them. Security is enforced using the standard HttpServletRequest.isUserInRole method.

Use the management.security.roles property if you want something different to ACTUATOR.

だから私はあなたがしなければならないすべてが設定されていると思う:私はこのリンクによるとUserDetailsService.UserDetails.Authorities

public Collection<? extends GrantedAuthority> getAuthorities() { 
     String[] authorities = permissions.stream().map(p -> { 
      return p.getName(); 
     }).toArray(String[]::new); 
     return AuthorityUtils.createAuthorityList(authorities); 
    } 
+1

感謝を解決するために、たとえばmanagement.security.roles=ROLE_SOMENAMEのためにあなたのmanagement.security.rolesのための接頭辞ROLE_を使用する必要がありますが、私は、 '.antMatchers(" /アクチュエータ/でこれを管理することができますよ* ")。hasAuthority(" R_0 ")'。問題は、デフォルトのSpring Boot Actuatorのセキュリティ統合を動作させることができず、このようなカスタム設定を提供する必要がないことです。 – alexanoid

+0

私は同じ問題を抱えています。 'AuthenticationManagerBuilder'に' UserDetailsS​​ervice'を設定することで、 'HttpSecurity'クラスのように明示的なURIアクセス設定の必要性を意味するデフォルトのセキュリティ設定をいくらか上書きすることに気付きました。あなたは当初期待どおりに動作させることができましたか? – RZet

+0

はい、 'management.security.roles'の接頭辞' ROLE_'を 'management.security.roles = ROLE_SOMENAME'のように使用する必要があります – alexanoid

答えて

3

この例を参照してください*あなたはこの問題に

+0

私はSpringブート1.5.1で 'management.security.roles'プロパティの値に' ROLE_'という接頭辞を付けるべきではないと考えました。私はこの主題に関して多くの混乱を見出しました。私はあなたの問題が、以下の 'HttpSecurity'設定' .antMatchers( "/ actuator/**")。hasAuthority( "ROLE_R_0") 'を代わりに修正することで解決できると考えています。 – RZet

+0

antMatcherは問題を解決しません。アクチュエータ/ヘルスエンドポイントでは、許可されたユーザではないユーザに対して異なるデータが返されます。提供されているantMatcher設定に基づいて実装することは不可能です – alexanoid

+0

あなたが話している動作はhttp://docs.spring.io/spring-boot/docs/current/reference/html/production-readyのセクション48.7に記載されています-monitoring.html。あなたの最初の質問は '/アクチュエータ/豆'呼び出しの約403ステータスコードでした。 'antMatchers("/actuator ... ")'設定を削除し、 'UserDetailsS​​ervice'があなたのケースで' GrantedAuthority'を 'ROLE_R_0'に設定した' UserDetails'オブジェクトを返すようにすることで修正できると思います。あるいは、主題に関するコメントで述べたように、それを 'InMemoryUserDetailsManagerConfigurer'と組み合わせることもできます。 – RZet

-1

を使用してい

を更新し

フォールドapplication.propertiesのlowingプロパティ。

management.security.roles 

例:

management.security.roles=R_0 
+0

ありがとうございますが、私の質問を見てください。私はすでに 'management.security.roles = R_0'を提供しています。問題は、Spring Boot Actuatorが何らかの理由で現在のSpring Securityで作業する方法を理解していないことです。 – alexanoid

関連する問題