How to re-enable anonymous access to Spring Boot Health endpoint?

Probably I'm doing something wrong here, I just can't figure out what...

I have an Oauth2 authentication server and a resource server within the same application.

Resource server configuration:

@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
    public static final String RESOURCE_ID = "resources";

    public void configure(final ResourceServerSecurityConfigurer resources) {

    public void configure(final HttpSecurity http) throws Exception {
                .antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')")
                .antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
                .antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
                .antMatchers(HttpMethod.PATCH, "/**").access("#oauth2.hasScope('write')")
                .antMatchers(HttpMethod.DELETE, "/**").access("#oauth2.hasScope('write')")
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .antMatchers(HttpMethod.GET, "/health").permitAll();


Authentication server configuration:

public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private UserDetailsService userDetailsService;

    public void configure(final AuthenticationManagerBuilder auth) throws Exception {
                .passwordEncoder(new BCryptPasswordEncoder());

    protected void configure(final HttpSecurity http) throws Exception {
                .and().httpBasic().realmName("OAuth Server");

When I try to access /health, I got a HTTP/1.1 401 Unauthorized.

How can I persuade Spring Boot to make /health anonymously accessible?


You also need to disable it by setting to false.

As M. Deinum said:

The order in which you specify your mappings is also the order in which they are consulted. The first match wins... As /** matches everything your /health mapping is useless. Move that above the /** mappings to have it functional. – M. Deinum Aug 20 at 17:56

Need Your Help

ASP.NET MVC 3 - Dealing with Session variables

c# forms-authentication

I have an app which uses Form's Authentication and when the user log's in, I retrieve the user's actual name and assign that to a session variable, like so:

filling a dataframe or matrix with for loop

r for-loop matrix dataframes

Is there a quick way to fill this matrix df with the values of n1 then n2 and finally n3 in order from left to right?