Maifee Ul Asad
Maifee Ul Asad

Reputation: 4607

spring boot security doesn't let me access h2-console

I'm trying to implement JWT in Spring Boot. For some debugging purposes, I need an H2 console.

So in my WebSecurityConfiguration, I wrote :

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        //httpSecurity.headers().frameOptions().disable();
        httpSecurity.authorizeRequests().antMatchers("/h2").permitAll();
        httpSecurity
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/auth/check/username").permitAll()
                .antMatchers("/auth/signup").permitAll()
                .antMatchers("/auth/login").permitAll()
                .anyRequest().authenticated().and()
                .exceptionHandling().and().sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

    }

In my application properties, I have this configuration :

spring.h2.console.enabled=true
spring.h2.console.path=/h2

When I hit ":8080/h2", it gives me 403.

So the question remains, how can I properly configure Spring Boot Web Security.

After including /h2/**, I get this UI :

spring boot blocking h2 console

Upvotes: 0

Views: 2203

Answers (1)

shabbeer ahammad
shabbeer ahammad

Reputation: 184

Please try "h2" pattern as:

httpSecurity.authorizeRequests().antMatchers("/h2/**").permitAll();

And this too :

httpSecurity.headers().frameOptions().disable();

more can found here : How to disable 'X-Frame-Options' response header in Spring Security?

Upvotes: 5

Related Questions