updated libraries

This commit is contained in:
Joern Muehlencord
2021-02-21 16:30:23 +01:00
parent b129228b36
commit cd2e3b0642
5 changed files with 103 additions and 105 deletions

View File

@ -31,22 +31,8 @@ limitations under the License.
<dependencies>
<dependency>
<groupId>com.inversoft</groupId>
<artifactId>prime-jwt</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
<groupId>io.fusionauth</groupId>
<artifactId>fusionauth-jwt</artifactId>
</dependency>
<dependency>
<groupId>javax</groupId>

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -15,80 +15,73 @@
*/
package de.muehlencord.shared.jeeutil.jwt;
import io.fusionauth.jwt.Verifier;
import io.fusionauth.jwt.domain.JWT;
import io.fusionauth.jwt.hmac.HMACVerifier;
import java.time.ZonedDateTime;
import org.primeframework.jwt.Verifier;
import org.primeframework.jwt.domain.JWT;
import org.primeframework.jwt.domain.JWTException;
import org.primeframework.jwt.hmac.HMACVerifier;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class JWTDecoder {
private boolean parsedSuccessfully = false;
private JWT jwt = null;
private boolean parsedSuccessfully;
private JWT jwt = null;
public JWTDecoder(String password, String issuer, String jwtString) throws JWTException {
if ((password == null) || (issuer == null) || (jwtString == null)) {
throw new JWTException("password, issuer and jwt must not be null");
}
Verifier verifier = HMACVerifier.newVerifier(password);
// Verifier verifier = RSAVerifier.newVerifier(new String(Files.readAllBytes(Paths.get("public_key.pem"))));
try {
jwt = JWT.getDecoder().decode(jwtString, verifier);
parsedSuccessfully = jwt.issuer.equals(issuer);
} catch (JWTException ex) {
jwt = null;
}
public JWTDecoder(String password, String issuer, String jwtString) throws JWTException {
if ((password == null) || (issuer == null) || (jwtString == null)) {
throw new JWTException("password, issuer and jwt must not be null");
}
Verifier verifier = HMACVerifier.newVerifier(password);
jwt = JWT.getDecoder().decode(jwtString, verifier);
parsedSuccessfully = jwt != null && jwt.issuer.equals(issuer);
}
public String getIssuer() {
if (jwt == null) {
return null;
} else {
return jwt.issuer;
}
public String getIssuer() {
if (jwt == null) {
return null;
} else {
return jwt.issuer;
}
}
public ZonedDateTime getIssuedAt() {
if (jwt == null) {
return null;
} else {
return jwt.issuedAt;
}
public ZonedDateTime getIssuedAt() {
if (jwt == null) {
return null;
} else {
return jwt.issuedAt;
}
}
public String getSubject() {
if (jwt == null) {
return null;
} else {
return jwt.subject;
}
public String getSubject() {
if (jwt == null) {
return null;
} else {
return jwt.subject;
}
}
public String getUniqueId() {
if (jwt == null) {
return null;
} else {
return jwt.uniqueId;
}
public String getUniqueId() {
if (jwt == null) {
return null;
} else {
return jwt.uniqueId;
}
}
public ZonedDateTime getExpiration() {
if (jwt == null) {
return null;
} else {
return jwt.expiration;
}
public ZonedDateTime getExpiration() {
if (jwt == null) {
return null;
} else {
return jwt.expiration;
}
}
public boolean isValid() {
if ((jwt == null) || (jwt.isExpired())) {
return false;
} else {
return this.parsedSuccessfully;
}
public boolean isValid() {
if ((jwt == null) || (jwt.isExpired())) {
return false;
} else {
return this.parsedSuccessfully;
}
}
}

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.jwt;
import io.fusionauth.jwt.Signer;
import io.fusionauth.jwt.domain.JWT;
import io.fusionauth.jwt.hmac.HMACSigner;
import java.time.ZonedDateTime;
import org.primeframework.jwt.Signer;
import org.primeframework.jwt.domain.JWT;
import org.primeframework.jwt.hmac.HMACSigner;
/**
*