Search in sources :

Example 31 with Verification

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()));
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Test(org.junit.Test)

Example 32 with Verification

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));
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 33 with Verification

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));
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Test(org.junit.Test)

Example 34 with Verification

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;
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FloodlightModuleException(net.floodlightcontroller.core.module.FloodlightModuleException)

Example 35 with Verification

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;
    }
}
Also used : JSONObject(org.json.simple.JSONObject) RSAPublicKey(java.security.interfaces.RSAPublicKey) Verification(com.auth0.jwt.interfaces.Verification) JWTVerifier(com.auth0.jwt.JWTVerifier) IOException(java.io.IOException) ParseException(org.json.simple.parser.ParseException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Test (org.junit.Test)29 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)28 Algorithm (com.auth0.jwt.algorithms.Algorithm)14 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)11 Date (java.util.Date)11 Verification (com.auth0.jwt.interfaces.Verification)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 JWTVerifier (com.auth0.jwt.JWTVerifier)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 Job (com.auth0.json.mgmt.jobs.Job)4 Claim (com.auth0.jwt.interfaces.Claim)4 Clock (com.auth0.jwt.interfaces.Clock)4 List (java.util.List)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 JWT (com.auth0.jwt.JWT)3 JWTVerifier (com.auth0.jwt.interfaces.JWTVerifier)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 FloodlightModuleException (net.floodlightcontroller.core.module.FloodlightModuleException)3