SpringSecurity + h2-console
in developCo-De with 0 comment

SpringSecurity + h2-console

in developCo-De with 0 comment

LOCAL-ONLY

Add dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

Setup H2 in Springboot

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=test
spring.h2.console.enabled=true

Modify Security Config

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http)
            throws Exception {
        http.httpBasic();
        http.authorizeHttpRequests()
            .requestMatchers("/h2-console/**").permitAll()
            .anyRequest().permitAll();
        http.headers().frameOptions().disable(); 
        http.csrf().disable();
        return http.build();
    }
Comments are closed.