use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldValidateIssuedAtIfPresent.
@Test
public void shouldValidateIssuedAtIfPresent() {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Nzc1OTJ9.0WJky9eLN7kuxLyZlmbcXRL3Wy8hLoNCEk5CCl2M4lo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.build(mockNow).verify(token);
assertThat(jwt, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldAddCustomLeewayToDateClaims.
@Test
public void shouldAddCustomLeewayToDateClaims() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).build();
assertThat(verifier.expectedChecks, is(notNullValue()));
assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideDefaultIssuedAtLeeway.
@Test
public void shouldOverrideDefaultIssuedAtLeeway() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).acceptIssuedAt(9999L).build();
assertThat(verifier.expectedChecks, is(notNullValue()));
assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(9999L));
assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
use of com.auth0.jwt.interfaces.Verification in project open-kilda by telstra.
the class PathVerificationService method sendDiscoveryMessage.
@Override
public boolean sendDiscoveryMessage(DatapathId srcSwId, OFPort port, DatapathId dstSwId) {
boolean result = false;
try {
IOFSwitch srcSwitch = switchService.getSwitch(srcSwId);
if (srcSwitch != null && srcSwitch.getPort(port) != null) {
IOFSwitch dstSwitch = (dstSwId == null) ? null : switchService.getSwitch(dstSwId);
OFPacketOut ofPacketOut = generateVerificationPacket(srcSwitch, port, dstSwitch, true);
if (ofPacketOut != null) {
logger.debug("==> Sending verification packet out {}/{}: {}", srcSwitch.getId().toString(), port.getPortNumber(), Hex.encodeHexString(ofPacketOut.getData()));
result = srcSwitch.write(ofPacketOut);
} else {
logger.error("<== Received null from generateVerificationPacket, inputs where: " + "srcSwitch: {}, port: {}, dstSwitch: {}", srcSwitch, port, dstSwitch);
}
}
} catch (Exception exception) {
logger.error("Error trying to sendDiscoveryMessage: {}", exception);
}
return result;
}
use of com.auth0.jwt.interfaces.Verification in project engine by Lumeer.
the class AuthenticationControllerProvider method getVerifier.
protected static JWTVerifier getVerifier(final String domain) {
try {
final String pem = (String) ((JSONArray) ((JSONObject) ((JSONArray) AuthenticationControllerProvider.readJsonFromUrl("https://" + domain + "/.well-known/jwks.json").get("keys")).get(0)).get("x5c")).get(0);
final StringBuilder sb = new StringBuilder("-----BEGIN CERTIFICATE-----\n");
int i = 0;
while (i < pem.length()) {
sb.append(pem, i, Math.min(i + 64, pem.length()));
sb.append("\n");
i += 64;
}
sb.append("-----END CERTIFICATE-----");
final String pemN = sb.toString();
final RSAPublicKey pubKey = AuthenticationControllerProvider.getPublicKeyFromCertificate(pemN);
final Verification verification = JWT.require(Algorithm.RSA256(pubKey, null));
final JWTVerifier verifier = verification.acceptExpiresAt(60).build();
return verifier;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations