Bom dia Pessoal Ao tentar realizar uma requisição POST para http://localhost:8080/login recebo como retorno o status 403(Forbidden. Ja no log da aplicação recebo o seguinte erro, estou usando spring na versão : 3.0.4, mas ja baixei o projeto do curso e o erro permanece.
2023-03-19T02:34:25.223-03:00 ERROR 5164 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause
java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at io.jsonwebtoken.impl.Base64Codec.encode(Base64Codec.java:21) ~[jjwt-0.9.1.jar:0.9.1]
at io.jsonwebtoken.impl.Base64UrlCodec.encode(Base64UrlCodec.java:22) ~[jjwt-0.9.1.jar:0.9.1]
at io.jsonwebtoken.impl.DefaultJwtBuilder.base64UrlEncode(DefaultJwtBuilder.java:349) ~[jjwt-0.9.1.jar:0.9.1]
at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:295) ~[jjwt-0.9.1.jar:0.9.1]
at br.com.raffa.forum.config.JWTUtil.generateToken(JWTUtil.kt:24) ~[classes/:na]
at br.com.raffa.forum.security.JWTLoginFilter.successfulAuthentication(JWTLoginFilter.kt:32) ~[classes/:na]
Classe JWTUtil
package br.com.raffa.forum.config
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.SignatureAlgorithm
import org.springframework.beans.factory.annotation.Value
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication
import org.springframework.stereotype.Component
import java.lang.IllegalArgumentException
import java.util.*
@Component
class JWTUtil {
private val expiration: Long = 60_000
@Value("\${jwt.secret}")
private lateinit var secret: String
fun generateToken(username: String): String?{
return Jwts.builder()
.setSubject(username)
.setExpiration(Date(System.currentTimeMillis() + expiration))
.signWith(SignatureAlgorithm.HS512, secret.toByteArray())
.compact()
}
fun isValid(jwt: String?): Boolean {
return try {
Jwts.parser().setSigningKey(secret.toByteArray()).parseClaimsJws(jwt)
true
} catch (e: IllegalArgumentException){
false
}
}
fun getAuthentication(jwt: String?): Authentication {
val username = Jwts.parser().setSigningKey(secret.toByteArray()).parseClaimsJws(jwt).body.subject
return UsernamePasswordAuthenticationToken(username, null, null)
}
}