Search in sources :

Example 6 with JWTVerificationException

use of com.auth0.jwt.exceptions.JWTVerificationException in project vboard by voyages-sncf-technologies.

the class AwsCognitoAuthenticationProvider method authenticate.

@Override
@SuppressFBWarnings("CFS_CONFUSING_FUNCTION_SEMANTICS")
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (!supports(authentication.getClass())) {
        return null;
    }
    JsonWebTokenAuthentication jwtAuth = (JsonWebTokenAuthentication) authentication;
    try {
        Algorithm algorithm = Algorithm.ECDSA256(new AwsCognitoECDSAKeyProvider(awsCognitoConfig.getRegion(), jwtAuth.getKeyId()));
        JWT.require(algorithm).build().verify(jwtAuth.getToken());
        jwtAuth.setAuthenticated(true);
        logger.debug("Authenticated with JWT with scopes: {}", authentication.getAuthorities());
        return authentication;
    } catch (JWTVerificationException e) {
        logger.error("JWT ECDSA256 verify error for user: {}", jwtAuth.getName(), e);
        throw new BadCredentialsException("Not a valid token", e);
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) Algorithm(com.auth0.jwt.algorithms.Algorithm) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with JWTVerificationException

use of com.auth0.jwt.exceptions.JWTVerificationException in project open-kilda by telstra.

the class PathVerificationService method parseDiscoveryPacket.

@VisibleForTesting
DiscoveryPacketData parseDiscoveryPacket(DiscoveryPacket discoveryPacket, long switchLatency) {
    ByteBuffer portBb = ByteBuffer.wrap(discoveryPacket.getPortId().getValue());
    portBb.position(1);
    OFPort remotePort = OFPort.of(portBb.getShort());
    DiscoveryPacketData.DiscoveryPacketDataBuilder builder = DiscoveryPacketData.builder();
    builder.remotePort(remotePort);
    builder.pathOrdinal(10);
    builder.switchT0(-1);
    builder.switchT1(-1);
    for (LLDPTLV lldptlv : discoveryPacket.getOptionalTlvList()) {
        if (matchOptionalLldptlv(lldptlv, REMOTE_SWITCH_OPTIONAL_TYPE, 12)) {
            ByteBuffer dpidBb = ByteBuffer.wrap(lldptlv.getValue());
            builder.remoteSwitchId(DatapathId.of(dpidBb.getLong(LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES)));
        } else if (matchOptionalLldptlv(lldptlv, TIMESTAMP_OPTIONAL_TYPE, 12)) {
            // skip OpenFlow OUI (4 bytes above)
            ByteBuffer tsBb = ByteBuffer.wrap(lldptlv.getValue());
            long sendTime = tsBb.getLong(LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES);
            // include the RX switch latency to "subtract" it
            builder.timestamp(sendTime + switchLatency);
        } else if (matchOptionalLldptlv(lldptlv, PATH_ORDINAL_OPTIONAL_TYPE, 8)) {
            ByteBuffer typeBb = ByteBuffer.wrap(lldptlv.getValue());
            builder.pathOrdinal(typeBb.getInt(LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES));
        } else if (matchOptionalLldptlv(lldptlv, SWITCH_T0_OPTIONAL_TYPE, 12)) {
            builder.switchT0(noviflowTimestamp(Arrays.copyOfRange(lldptlv.getValue(), LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES, lldptlv.getValue().length)));
        } else if (matchOptionalLldptlv(lldptlv, SWITCH_T1_OPTIONAL_TYPE, 12)) {
            builder.switchT1(noviflowTimestamp(Arrays.copyOfRange(lldptlv.getValue(), LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES, lldptlv.getValue().length)));
        } else if (matchOptionalLldptlv(lldptlv, TOKEN_OPTIONAL_TYPE)) {
            ByteBuffer bb = ByteBuffer.wrap(lldptlv.getValue());
            bb.position(LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES);
            byte[] tokenArray = new byte[lldptlv.getLength() - LLDP_TLV_OPTIONAL_HEADER_SIZE_IN_BYTES];
            bb.get(tokenArray, 0, tokenArray.length);
            String token = new String(tokenArray);
            try {
                DecodedJWT jwt = verifier.verify(token);
                Claim idClaim = jwt.getClaim("id");
                if (!idClaim.isNull()) {
                    builder.packetId(idClaim.asLong());
                }
                builder.signed(true);
            } catch (JWTVerificationException e) {
                logger.error("Packet verification failed", e);
                builder.signed(false);
            }
        }
    }
    return builder.build();
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) OFPort(org.projectfloodlight.openflow.types.OFPort) ByteBuffer(java.nio.ByteBuffer) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim) LLDPTLV(net.floodlightcontroller.packet.LLDPTLV) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with JWTVerificationException

use of com.auth0.jwt.exceptions.JWTVerificationException in project data-transfer-project by google.

the class JWTTokenManager method getJobIdFromToken.

@Override
public UUID getJobIdFromToken(String token) {
    try {
        DecodedJWT jwt = verifier.verify(token);
        // Token is verified, get claim
        Claim claim = jwt.getClaim(JWTTokenManager.ID_CLAIM_KEY);
        if (claim.isNull()) {
            return null;
        }
        return claim.isNull() ? null : UUID.fromString(claim.asString());
    } catch (JWTVerificationException exception) {
        throw new RuntimeException("Error verifying token: " + token);
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim)

Example 9 with JWTVerificationException

use of com.auth0.jwt.exceptions.JWTVerificationException in project data-transfer-project by google.

the class JWTTokenManager method getJobIdFromToken.

@Override
public UUID getJobIdFromToken(String token) {
    try {
        DecodedJWT jwt = verifier.verify(token);
        // Token is verified, get claim
        Claim claim = jwt.getClaim(JWTTokenManager.ID_CLAIM_KEY);
        if (claim.isNull()) {
            return null;
        }
        return claim.isNull() ? null : UUID.fromString(claim.asString());
    } catch (JWTVerificationException exception) {
        logger.debug("Error verifying token: {}", exception);
        throw new RuntimeException("Error verifying token: " + token);
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim)

Example 10 with JWTVerificationException

use of com.auth0.jwt.exceptions.JWTVerificationException in project wikidata-query-rdf by wikimedia.

the class TimeLimitedAccessTokenFactory method decide.

<T> T decide(String token, Supplier<T> good, Supplier<T> bad) {
    if (token == null) {
        return bad.get();
    }
    DecodedJWT decoded;
    try {
        decoded = verifier.verify(token);
    } catch (JWTVerificationException e) {
        return bad.get();
    }
    Claim claim = decoded.getClaim(USERNAME);
    if (claim.isNull()) {
        throw new IllegalStateException(("All valid jwt tokens must have a username claim"));
    }
    if (bannedUsernames.contains(claim.asString())) {
        return bad.get();
    }
    return good.get();
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim)

Aggregations

JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)11 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)7 Claim (com.auth0.jwt.interfaces.Claim)5 Algorithm (com.auth0.jwt.algorithms.Algorithm)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 LLDPTLV (net.floodlightcontroller.packet.LLDPTLV)2 OFPort (org.projectfloodlight.openflow.types.OFPort)2 JWTCreator (com.auth0.jwt.JWTCreator)1 JWTVerifier (com.auth0.jwt.JWTVerifier)1 AlgorithmMismatchException (com.auth0.jwt.exceptions.AlgorithmMismatchException)1 InvalidClaimException (com.auth0.jwt.exceptions.InvalidClaimException)1 SignatureVerificationException (com.auth0.jwt.exceptions.SignatureVerificationException)1 TokenExpiredException (com.auth0.jwt.exceptions.TokenExpiredException)1 NullClaim (com.auth0.jwt.impl.NullClaim)1 DecodedGoogleJWTWrapper (com.example.compute.signedmetadata.token.DecodedGoogleJWTWrapper)1 TokenVerifier (com.example.compute.signedmetadata.token.TokenVerifier)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1