Olá, estou com um problema em que todo tipo de requisição que faço no postman gera 403(forbidden), já tentei várias coisa porém nada funciona. Segue meu código abaixo:
-----class JWTUtil
@Component
class JWTUtil(
private val userService: UsuarioService
) {
@Value("\${jwt.secret}")
private var secret: String = "$2a$12$3aDgJRIR.dkUKsqd2iPGbeFP3n/htcWkQ442mbWo9J6jY8ZftvSuW"
private val expiration: Long = 60000
private val key = Keys.hmacShaKeyFor(secret.toByteArray(StandardCharsets.UTF_8))
fun generateToken(username: String, authorities: MutableCollection<out GrantedAuthority>): String {
return Jwts
.builder()
.subject(username)
.claim("role", authorities)
.expiration(Date(System.currentTimeMillis() + expiration))
.signWith(key)
.compact()
}
fun isValid(jwt: String?): Boolean {
return try {
Jwts.parser()
.verifyWith(key)
.build()
.parseSignedClaims(jwt)
true
} catch (e: IllegalArgumentException) {
false
}
}
fun getAuthentication(jwt: String?): UsernamePasswordAuthenticationToken {
val username = Jwts.parser()
.verifyWith(key)
.build()
.parseSignedClaims(jwt)
.payload
.subject
val user = userService.loadUserByUsername(username.toString())
return UsernamePasswordAuthenticationToken(username, null, user.authorities)
}
}