use of com.auth0.android.jwt.JWT in project iris-client by iris-connect.
the class JWTAuthorizationFilter method authenticate.
/**
* This method is called if the user supplied a jwt token.
*
* @param token JSON Web Token
* @return
*/
private UserAccountAuthentication authenticate(String token) {
DecodedJWT jwt = jwtVerifier.verify(token);
var userName = jwt.getSubject();
var userAccount = userService.findByUsername(userName);
if (userAccount.isPresent() && jwtVerifier.isTokenWhitelisted(token)) {
var authority = new SimpleGrantedAuthority(jwt.getClaim(JWT_CLAIM_USER_ROLE).asString());
return new UserAccountAuthentication(userAccount.get(), true, List.of(authority));
}
return null;
}
use of com.auth0.android.jwt.JWT in project cloud-pipeline by epam.
the class JWTGenerator method buildToken.
private JWTCreator.Builder buildToken(JwtTokenClaims claims) {
JWTCreator.Builder tokenBuilder = JWT.create();
tokenBuilder.withHeader(Collections.singletonMap("typ", "JWT"));
tokenBuilder.withIssuedAt(new Date()).withJWTId(StringUtils.isEmpty(claims.getJwtTokenId()) ? UUID.randomUUID().toString() : claims.getJwtTokenId()).withSubject(claims.getUserName()).withClaim(CLAIM_USER_ID, claims.getUserId()).withClaim(CLAIM_ORG_UNIT_ID, claims.getOrgUnitId()).withArrayClaim(CLAIM_GROUPS, claims.getGroups().toArray(new String[claims.getRoles().size()])).withArrayClaim(CLAIM_ROLES, claims.getRoles().toArray(new String[claims.getRoles().size()]));
return tokenBuilder;
}
use of com.auth0.android.jwt.JWT in project cloud-pipeline by epam.
the class JwtTokenGenerator method buildToken.
private JWTCreator.Builder buildToken(JwtTokenClaims claims) {
JWTCreator.Builder tokenBuilder = JWT.create();
tokenBuilder.withHeader(ImmutableMap.of("typ", "JWT"));
tokenBuilder.withIssuedAt(new Date()).withJWTId(Strings.isNullOrEmpty(claims.getJwtTokenId()) ? UUID.randomUUID().toString() : claims.getJwtTokenId()).withSubject(claims.getUserName()).withClaim(CLAIM_USER_ID, claims.getUserId()).withClaim(CLAIM_ORG_UNIT_ID, claims.getOrgUnitId()).withArrayClaim(CLAIM_GROUPS, claims.getGroups().toArray(new String[claims.getGroups().size()])).withArrayClaim(CLAIM_ROLES, claims.getRoles().toArray(new String[claims.getRoles().size()]));
if (claims.isExternal()) {
tokenBuilder.withClaim(CLAIM_EXTERNAL, claims.isExternal());
}
return tokenBuilder;
}
use of com.auth0.android.jwt.JWT in project foundation-java by soffalabs.
the class DefaultJwtProcessor method decode.
@Override
public Optional<Authentication> decode(String token, ClaimsExtractor claimsExtractor) {
try {
Algorithm algorithm = Algorithm.HMAC256(config.getSecret());
JWTVerifier verifier = JWT.require(algorithm).withIssuer(config.getIssuer()).build();
DecodedJWT jwt = verifier.verify(token);
Map<String, Claim> baseClaims = jwt.getClaims();
Map<String, Object> claims = new HashMap<>();
for (Map.Entry<String, Claim> entry : baseClaims.entrySet()) {
claims.put(entry.getKey(), entry.getValue().asString());
}
return Optional.of(claimsExtractor.extractInfo(new Jwt(token, jwt.getSubject(), claims)));
} catch (Exception e) {
LOG.error(e);
return Optional.empty();
}
}
use of com.auth0.android.jwt.JWT in project open-kilda by telstra.
the class PathVerificationService method handlePacketIn.
private IListener.Command handlePacketIn(IOFSwitch sw, OFPacketIn pkt, FloodlightContext context) {
long time = System.currentTimeMillis();
logger.debug("packet_in {} received from {}", pkt.getXid(), sw.getId());
VerificationPacket verificationPacket = null;
Ethernet eth = IFloodlightProviderService.bcStore.get(context, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
try {
verificationPacket = deserialize(eth);
} catch (Exception exception) {
logger.error("Deserialization failure: {}, exception: {}", exception.getMessage(), exception);
return Command.CONTINUE;
}
try {
OFPort inPort = pkt.getVersion().compareTo(OFVersion.OF_12) < 0 ? pkt.getInPort() : pkt.getMatch().get(MatchField.IN_PORT);
ByteBuffer portBB = ByteBuffer.wrap(verificationPacket.getPortId().getValue());
portBB.position(1);
OFPort remotePort = OFPort.of(portBB.getShort());
long timestamp = 0;
int pathOrdinal = 10;
IOFSwitch remoteSwitch = null;
boolean signed = false;
for (LLDPTLV lldptlv : verificationPacket.getOptionalTLVList()) {
if (lldptlv.getType() == 127 && lldptlv.getLength() == 12 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x0) {
ByteBuffer dpidBB = ByteBuffer.wrap(lldptlv.getValue());
remoteSwitch = switchService.getSwitch(DatapathId.of(dpidBB.getLong(4)));
} else if (lldptlv.getType() == 127 && lldptlv.getLength() == 12 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x01) {
ByteBuffer tsBB = ByteBuffer.wrap(lldptlv.getValue());
/* skip OpenFlow OUI (4 bytes above) */
long swLatency = sw.getLatency().getValue();
timestamp = tsBB.getLong(4);
/* include the RX switch latency to "subtract" it */
timestamp = timestamp + swLatency;
} else if (lldptlv.getType() == 127 && lldptlv.getLength() == 8 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x02) {
ByteBuffer typeBB = ByteBuffer.wrap(lldptlv.getValue());
pathOrdinal = typeBB.getInt(4);
} else if (lldptlv.getType() == 127 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x03) {
ByteBuffer bb = ByteBuffer.wrap(lldptlv.getValue());
bb.position(4);
byte[] tokenArray = new byte[lldptlv.getLength() - 4];
bb.get(tokenArray, 0, tokenArray.length);
String token = new String(tokenArray);
try {
DecodedJWT jwt = verifier.verify(token);
signed = true;
} catch (JWTVerificationException e) {
logger.error("Packet verification failed", e);
return Command.STOP;
}
}
}
if (remoteSwitch == null) {
return Command.STOP;
}
if (!signed) {
logger.warn("verification packet without sign");
return Command.STOP;
}
U64 latency = (timestamp != 0 && (time - timestamp) > 0) ? U64.of(time - timestamp) : U64.ZERO;
logger.debug("link discovered: {}-{} ===( {} ms )===> {}-{}", remoteSwitch.getId(), remotePort, latency.getValue(), sw.getId(), inPort);
// this verification packet was sent from remote switch/port to received switch/port
// so the link direction is from remote switch/port to received switch/port
List<PathNode> nodes = Arrays.asList(new PathNode(remoteSwitch.getId().toString(), remotePort.getPortNumber(), 0, latency.getValue()), new PathNode(sw.getId().toString(), inPort.getPortNumber(), 1));
OFPortDesc port = sw.getPort(inPort);
long speed = Integer.MAX_VALUE;
if (port.getVersion().compareTo(OFVersion.OF_13) > 0) {
for (OFPortDescProp prop : port.getProperties()) {
if (prop.getType() == 0x0) {
speed = ((OFPortDescPropEthernet) prop).getCurrSpeed();
}
}
} else {
speed = port.getCurrSpeed();
}
IslInfoData path = new IslInfoData(latency.getValue(), nodes, speed, IslChangeType.DISCOVERED, getAvailableBandwidth(speed));
Message message = new InfoMessage(path, System.currentTimeMillis(), "system", null);
final String json = MAPPER.writeValueAsString(message);
logger.debug("about to send {}", json);
producer.send(new ProducerRecord<>(TOPIC, json));
logger.debug("packet_in processed for {}-{}", sw.getId(), inPort);
} catch (JsonProcessingException exception) {
logger.error("could not create json for path packet_in: {}", exception.getMessage(), exception);
} catch (UnsupportedOperationException exception) {
logger.error("could not parse packet_in message: {}", exception.getMessage(), exception);
} catch (Exception exception) {
logger.error("unknown error during packet_in message processing: {}", exception.getMessage(), exception);
throw exception;
}
return Command.STOP;
}
Aggregations