は、これは私の春ブーツ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);
}
感謝を解決するために、たとえば
management.security.roles=ROLE_SOMENAME
のためにあなたのmanagement.security.roles
のための接頭辞ROLE_
を使用する必要がありますが、私は、 '.antMatchers(" /アクチュエータ/でこれを管理することができますよ* ")。hasAuthority(" R_0 ")'。問題は、デフォルトのSpring Boot Actuatorのセキュリティ統合を動作させることができず、このようなカスタム設定を提供する必要がないことです。 – alexanoid私は同じ問題を抱えています。 'AuthenticationManagerBuilder'に' UserDetailsService'を設定することで、 'HttpSecurity'クラスのように明示的なURIアクセス設定の必要性を意味するデフォルトのセキュリティ設定をいくらか上書きすることに気付きました。あなたは当初期待どおりに動作させることができましたか? – RZet
はい、 'management.security.roles'の接頭辞' ROLE_'を 'management.security.roles = ROLE_SOMENAME'のように使用する必要があります – alexanoid