Olá, mesmo seguindo os passos executados pelo professor na parte 5 do curso para integrar o Swagger no projeto, não consigo acessar a url com a interface da biblioteca.
build.gradle:
dependencies { // Kotlin implementation 'org.jetbrains.kotlin:kotlin-reflect' implementation 'org.jetbrains.kotlin:kotlin-stdlib'
// Spring
implementation 'org.springframework.boot:spring-boot-starter-web'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Data
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.data:spring-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33'
implementation 'org.liquibase:liquibase-core'
implementation 'io.github.serpro69:kotlin-faker:1.13.0'
// Request/Response serialization
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'com.google.code.gson:gson:2.8.9'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'io.jsonwebtoken:jjwt:0.2'
// Documentation
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
// Helper
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// Test
implementation platform('org.testcontainers:testcontainers-bom:1.19.3')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test:6.2.1'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:mysql'
// Test Helpers
implementation "io.github.serpro69:kotlin-faker:1.13.0"
testImplementation "org.amshove.kluent:kluent-android:1.72"
testImplementation "io.mockk:mockk:1.13.8"
}
SecurityConfiguration.kt:
@Configuration @EnableWebSecurity class SecurityConfiguration( private val authConfig: AuthenticationConfiguration, private val jwtUtil: JwtUtil, ) { @Bean fun filterChain(http: HttpSecurity): SecurityFilterChain { http { authorizeHttpRequests { // Set authorities (user roles) for each endpoint authorize(HttpMethod.POST, "/login", permitAll) authorize(HttpMethod.GET, "/swagger-ui/", permitAll) authorize(HttpMethod.GET, "/v3/api-docs/", permitAll)
// Domain endpoints
authorize("/topics", hasAuthority("READ_WRITE"))
// Only accept requests sent by authenticated users
authorize(anyRequest, authenticated)
}
// Disable CSRF to make JWT work properly
csrf { disable() }
// Disable state saves between requests when logged in a user session
sessionManagement {
sessionCreationPolicy = SessionCreationPolicy.STATELESS
}
// Intercept all incoming requests
setUpFilterChain()
}
return http.build()
}
private fun HttpSecurityDsl.setUpFilterChain() {
// Token generation filter
addFilterBefore<UsernamePasswordAuthenticationFilter>(JwtLoginFilter(authConfig.authenticationManager, jwtUtil))
// Endpoint authentication/authorization filter
addFilterBefore<UsernamePasswordAuthenticationFilter>(JwtAuthFilter(jwtUtil))
}
@Bean
fun getPasswordEncoder() = BCryptPasswordEncoder()
}
Ao executar na url "http://localhost:8080/swagger-ui/index.html":
Como pode ser que existam vários fatores que podem estar levando ao problema, vou deixar o projeto no GitHub linkado.