private String encodeJwt(HttpMethod httpMethod, URI targetPath, Map<String, String[]> params, String userKeyValue,
AcHost acHost) throws JwtUnknownIssuerException, JwtIssuerLacksSharedSecretException {
checkArgument(null != httpMethod, "HttpMethod argument cannot be null");
checkArgument(null != targetPath, "URI argument cannot be null");
JwtJsonBuilder jsonBuilder = new JsonSmartJwtJsonBuilder()
.issuedAt(TimeUtil.currentTimeSeconds())
.expirationTime(TimeUtil.currentTimePlusNSeconds(jwtExpiryWindowSeconds))
.issuer(AC.PLUGIN_KEY)
.audience(acHost.getKey());
if (null != userKeyValue) {
jsonBuilder = jsonBuilder.subject(userKeyValue);
}
Map<String, String[]> completeParams = params;
try {
if (!StringUtils.isEmpty(targetPath.getQuery())) {
completeParams = new HashMap<String, String[]>(params);
completeParams.putAll(constructParameterMap(targetPath));
}
CanonicalHttpUriRequest canonicalHttpUriRequest = new CanonicalHttpUriRequest(httpMethod.toString(),
targetPath.getPath(), "", completeParams);
LOGGER.debug("Canonical request is: " + CanonicalRequestUtil.toVerboseString(canonicalHttpUriRequest));
JwtClaimsBuilder.appendHttpRequestClaims(jsonBuilder, canonicalHttpUriRequest);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
return issueJwt(jsonBuilder.build(), acHost);
}