So below is the controller from which i am getting the error message as : “Cannot invoke “org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder.getObject()” because “this.authenticationManagerBuilder” is null
open class UserJWTController(
private val tokenProvider: TokenProvider,
private val authenticationManagerBuilder: AuthenticationManagerBuilder
) {
@PostMapping("/authenticate")
fun authorize(@RequestBody loginVM: @Valid LoginVM?): ResponseEntity<JWTToken> {
// Create an authentication token using the provided username and password
val authenticationToken =
UsernamePasswordAuthenticationToken(loginVM!!.username, loginVM.password)
// Authenticate the user
val authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken)
SecurityContextHolder.getContext().authentication = authentication
response
return getJwtTokenResponseEntity(tokenProvider.createToken(authentication))
}
// Helper method to create a ResponseEntity containing the JWT token
private fun getJwtTokenResponseEntity(token: String): ResponseEntity<JWTToken> {
return ResponseEntity.ok(JWTToken(token))
}
}
data class LoginVM(
val username: String,
val password: String
)
response
data class JWTToken(val idToken: String)
1