use of com.auth0.jwt.exceptions.JWTCreationException in project LogHub by fbacchella.
the class JwtToken method processRequest.
@Override
protected void processRequest(FullHttpRequest request, ChannelHandlerContext ctx) throws HttpRequestFailure {
Principal p = ctx.channel().attr(AbstractNettyServer.PRINCIPALATTRIBUTE).get();
try {
String token = alg.getToken(p);
ByteBuf content = Unpooled.copiedBuffer(token + "\r\n", CharsetUtil.UTF_8);
writeResponse(ctx, request, content, content.readableBytes());
} catch (JWTCreationException exception) {
throw new HttpRequestFailure(HttpResponseStatus.SERVICE_UNAVAILABLE, "JWT creation failed", Collections.emptyMap());
}
}
use of com.auth0.jwt.exceptions.JWTCreationException in project structr by structr.
the class JWTHelper method createTokensForUserWithSecret.
private static Map<String, String> createTokensForUserWithSecret(Principal user, Date accessTokenExpirationDate, Date refreshTokenExpirationDate, String instanceName) throws FrameworkException {
final String secret = Settings.JWTSecret.getValue();
final String jwtIssuer = Settings.JWTIssuer.getValue();
try {
final Algorithm alg = Algorithm.HMAC256(secret.getBytes(StandardCharsets.UTF_8));
return createTokens(user, alg, accessTokenExpirationDate, refreshTokenExpirationDate, instanceName, jwtIssuer);
} catch (JWTCreationException ex) {
throw new FrameworkException(500, "The configured secret is too weak (must be at least 32 characters)");
}
}
use of com.auth0.jwt.exceptions.JWTCreationException in project dockstore by dockstore.
the class GitHubHelper method checkJWT.
/**
* Refresh the JWT for GitHub apps
* @param gitHubAppId
* @param gitHubPrivateKeyFile
*/
public static void checkJWT(String gitHubAppId, String gitHubPrivateKeyFile) {
RSAPrivateKey rsaPrivateKey = null;
System.out.println("working dir=" + Paths.get("").toAbsolutePath().toString());
try {
String pemFileContent = FileUtils.readFileToString(new File(gitHubPrivateKeyFile), StandardCharsets.UTF_8);
final PemReader.Section privateKey = PemReader.readFirstSectionAndClose(new StringReader(pemFileContent), "PRIVATE KEY");
if (privateKey != null) {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKey.getBase64DecodedBytes());
rsaPrivateKey = (RSAPrivateKey) keyFactory.generatePrivate(pkcs8EncodedKeySpec);
} else {
LOG.error("No private key found in " + gitHubPrivateKeyFile);
}
} catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException ex) {
LOG.error(ex.getMessage(), ex);
}
if (rsaPrivateKey != null) {
final int tenMinutes = 600000;
try {
Algorithm algorithm = Algorithm.RSA256(null, rsaPrivateKey);
String jsonWebToken = JWT.create().withIssuer(gitHubAppId).withIssuedAt(new Date()).withExpiresAt(new Date(Calendar.getInstance().getTimeInMillis() + tenMinutes)).sign(algorithm);
CacheConfigManager.setJsonWebToken(jsonWebToken);
} catch (JWTCreationException ex) {
LOG.error(ex.getMessage(), ex);
}
}
}
use of com.auth0.jwt.exceptions.JWTCreationException in project toy by gmoon92.
the class JwtUtils method generate.
public String generate(User user) {
try {
ZonedDateTime today = ZonedDateTime.now();
String token = JWT.create().withIssuer(apiVersion).withClaim("username", user.getUsername()).withClaim("role", user.getRole().name()).withIssuedAt(Date.from(today.toInstant())).withExpiresAt(Date.from(today.plusDays(DAY_OF_EXPIRATION).toInstant())).sign(algorithm);
return String.format("%s %s", AuthenticationSchema.BEARER.getName(), token);
} catch (JWTCreationException e) {
throw new JWTCreationException("Invalid Signing configuration or Couldn't convert Claims.", e);
}
}
Aggregations