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);
}
}
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();
}
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);
}
}
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);
}
}
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();
}
Aggregations