Ola, fiz a troca para o AuthenticationManager novo porem ao compilar retorna um erro com a seguinte causa:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterChain' defined in class path resource [com/example/demo/config/SecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'filterChain' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.springframework.security.config.annotation.web.builders.FilterOrderRegistration.getOrder(java.lang.Class)" is null
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.22.jar:5.3.22]
-----------------------------
`Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'filterChain' threw exception;`
-------------------------
`Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.springframework.security.config.annotation.web.builders.FilterOrderRegistration.getOrder(java.lang.Class)" is null`
A minha SecurityConfiguration está assim:
@Configuration
@EnableWebSecurity
class SecurityConfiguration(
private val configuration: AuthenticationConfiguration,
private val jwtUtil: JWTUtil
){
@Bean
fun filterChain(http: HttpSecurity): SecurityFilterChain {
// se http NAO for nulo, prossegue por conta do ?
http.csrf().disable().authorizeHttpRequests()?. // desabilitia csrf e autoriza requisicao
antMatchers("/topicos")?.hasAuthority("SOMENTE_LEITURA")?.
antMatchers(HttpMethod.POST, "/login")?.permitAll()?.anyRequest()?.authenticated()?. // qualquer requisicao precisa ser autenticada
and()
http.addFilterBefore(
JWTLoginFilter(authManager = configuration.authenticationManager, jwtUtil = jwtUtil),
UsernamePasswordAuthenticationFilter().javaClass
)
http?.addFilterBefore(JWTAuthenticationFilter(jwtUtil = jwtUtil), OncePerRequestFilter::class.java)
http?.sessionManagement()
?.sessionCreationPolicy(SessionCreationPolicy.STATELESS) // api nao guarda estado de autenticacao
return http.build()
}
@Bean
fun encoder(): PasswordEncoder? {
return BCryptPasswordEncoder()
}
}