Como permitir o banco de dados h2-console com spring-security kotlin

Estou usando a linguagem kotlin. Estou usando a configuração abaixo, mas mesmo assim ao entrar no meu h2-console não consigo acessar.

  • gradle
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	id 'org.springframework.boot' version '3.1.5'
	id 'io.spring.dependency-management' version '1.1.3'
	id 'org.asciidoctor.jvm.convert' version '3.3.2'
	id 'org.jetbrains.kotlin.jvm' version '1.8.22'
	id 'org.jetbrains.kotlin.plugin.spring' version '1.8.22'
	id 'org.jetbrains.kotlin.plugin.jpa' version '1.8.22'
	id 'jacoco'
	id "io.freefair.lombok" version "5.3.0"
}

java {
	sourceCompatibility = '17'
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

ext {
	set('snippetsDir', file("build/generated-snippets"))
	set('springCloudVersion', "2022.0.4")
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-jdbc'
	implementation 'org.springframework.boot:spring-boot-starter-data-rest'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
	implementation 'org.flywaydb:flyway-core'
	implementation 'org.jetbrains.kotlin:kotlin-reflect'
	implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
	runtimeOnly 'com.h2database:h2'
	implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	implementation group: 'com.auth0', name: 'java-jwt', version: '4.4.0'


	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'org.postgresql:postgresql'


	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.boot:spring-boot-testcontainers'
	testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
	testImplementation 'org.testcontainers:junit-jupiter'
	testImplementation 'org.testcontainers:postgresql'
	testImplementation 'org.springframework.security:spring-security-test'


	implementation("com.github.ben-manes.caffeine:caffeine:2.9.1")
	implementation("org.springframework.boot:spring-boot-starter-cache")
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

tasks.withType(KotlinCompile) {
	kotlinOptions {
		freeCompilerArgs += '-Xjsr305=strict'
		jvmTarget = '17'
	}
}

tasks.named('bootBuildImage') {
	builder = 'paketobuildpacks/builder-jammy-base:latest'
}

tasks.named('test') {
	maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
	outputs.dir snippetsDir
	useJUnitPlatform()
	finalizedBy(tasks.jacocoTestReport)
}

tasks.named('asciidoctor') {
	inputs.dir snippetsDir
	dependsOn test
}

tasks.named("jacocoTestReport") {
	executionData(file("${project.buildDir}/jacoco/test.exec"))

	reports {
		html.required.set(true)
		xml.required.set(true)
	}

	classDirectories.setFrom(
			files(
					classDirectories.files.collect {
						fileTree(it) {
							exclude("**/obama/ObamaApplication**")
							exclude("**/model/**")
							exclude("**/entity/**")
							exclude("**/handler/**")
							exclude("**/exception/**")
							exclude("**/configuration/")
							exclude("**/exchange/**")
						}
					}
			)
	)
}

  • SecurityConfig
package br.ufrn.imd.obama.security.infrastructure.security

import org.springframework.boot.autoconfigure.security.servlet.PathRequest
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.authentication.AuthenticationManager
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.web.SecurityFilterChain

@Configuration
@EnableWebSecurity
class SecutiryConfig {
    @Bean
    fun securityFilterChain(httpsecurity: HttpSecurity): SecurityFilterChain {
        return httpsecurity
            .csrf{it.disable()}
            .sessionManagement{it.sessionCreationPolicy(SessionCreationPolicy.STATELESS)}
            .authorizeHttpRequests{
                it.requestMatchers(PathRequest.toH2Console()).permitAll()
                it.anyRequest().permitAll()
            }
            .build()
    }

    @Bean
    fun authenticationManager(authenticationConfiguration: AuthenticationConfiguration): AuthenticationManager {
        return authenticationConfiguration.authenticationManager
    }

    @Bean
    fun passwordEncoder(): PasswordEncoder {
        return BCryptPasswordEncoder()
    }
}