Skip to content

Commit

Permalink
Fixed JWTS API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Dec 4, 2023
1 parent a1825c3 commit 6f49a94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import de.fraunhofer.iosb.ilt.sta.jackson.customtyping.SweTypeIdResolver;

/**
*
* @author Michael Jacoby
* Mixin to resolve SWE types from their type field.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonTypeIdResolver(SweTypeIdResolver.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureException;
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.security.SignatureException;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -224,19 +225,19 @@ private void autoRefresh() {

public boolean validateToken(String token) {
try {
if (Jwts.parser().isSigned(token)) {
if (Jwts.parser().build().isSigned(token)) {
if (keyType != null) {
X509EncodedKeySpec spec = new X509EncodedKeySpec(apiKeyBytes);
KeyFactory fact = KeyFactory.getInstance(keyType);
PublicKey key = fact.generatePublic(spec);
Jwts.parser().setSigningKey(key).parse(token);
Jwts.parser().verifyWith(key).build().parse(token);
} else if (apiKeyBytes != null) {
Jwts.parser().setSigningKey(apiKeyBytes).parse(token);
Jwts.parser().verifyWith(Keys.hmacShaKeyFor(apiKeyBytes)).build().parse(token);
} else {
LOGGER.debug("Can not validate token, please set the signing key.");
}
} else {
Jwts.parser().parse(token);
Jwts.parser().build().parse(token);
}
return true;
} catch (SignatureException | NoSuchAlgorithmException | InvalidKeySpecException e) {
Expand Down

0 comments on commit 6f49a94

Please sign in to comment.