本文整理汇总了Java中org.jose4j.jwt.JwtClaims.toJson方法的典型用法代码示例。如果您正苦于以下问题:Java JwtClaims.toJson方法的具体用法?Java JwtClaims.toJson怎么用?Java JwtClaims.toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.jwt.JwtClaims
的用法示例。
在下文中一共展示了JwtClaims.toJson方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
/**
* Sign id token claim string.
*
* @param svc the service
* @param claims the claims
* @return the string
* @throws JoseException the jose exception
*/
public String encode(final OidcRegisteredService svc, final JwtClaims claims) throws JoseException {
try {
LOGGER.debug("Attempting to produce id token generated for service [{}]", svc);
final JsonWebSignature jws = new JsonWebSignature();
final String jsonClaims = claims.toJson();
jws.setPayload(jsonClaims);
LOGGER.debug("Generated claims to put into id token are [{}]", jsonClaims);
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.NONE);
jws.setAlgorithmConstraints(AlgorithmConstraints.NO_CONSTRAINTS);
String innerJwt = svc.isSignIdToken() ? signIdToken(svc, jws) : jws.getCompactSerialization();
if (svc.isEncryptIdToken() && StringUtils.isNotBlank(svc.getIdTokenEncryptionAlg())
&& StringUtils.isNotBlank(svc.getIdTokenEncryptionEncoding())) {
innerJwt = encryptIdToken(svc, jws, innerJwt);
}
return innerJwt;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw Throwables.propagate(e);
}
}
示例2: createToken
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
@Override
public String createToken(final String to) {
try {
final String token = UUID.randomUUID().toString();
final JwtClaims claims = new JwtClaims();
claims.setJwtId(token);
claims.setIssuer(issuer);
claims.setAudience(issuer);
claims.setExpirationTimeMinutesInTheFuture(passwordManagementProperties.getReset().getExpirationMinutes());
claims.setIssuedAtToNow();
final ClientInfo holder = ClientInfoHolder.getClientInfo();
claims.setStringClaim("origin", holder.getServerIpAddress());
claims.setStringClaim("client", holder.getClientIpAddress());
claims.setSubject(to);
final String json = claims.toJson();
return this.cipherExecutor.encode(json);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例3: verifyJWT
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
private String verifyJWT() throws Exception {
JwtConsumerBuilder builder = new JwtConsumerBuilder();
// Basics
builder.setRequireExpirationTime();
builder.setRequireSubject();
if (!isEmpty(this.issuer)) {
builder.setExpectedIssuer(this.issuer);
}
if (!isEmpty(this.audience)) {
builder.setExpectedAudience(this.audience);
}
if (this.jws) {
AlgorithmConstraints jwsAlgConstraints =
new AlgorithmConstraints(ConstraintType.WHITELIST,ALGORITHMS.get(jwsAlgo));
builder.setJwsAlgorithmConstraints(jwsAlgConstraints);
builder.setVerificationKey(getJWSKey(this.jwsKey, this.jwsAlgo));
}
if (this.jwe) {
if (!this.jws) {
builder.setDisableRequireSignature();
}
AlgorithmConstraints jweAlgConstraints =
new AlgorithmConstraints(ConstraintType.WHITELIST, ALGORITHMS.get(jweKeyAlgo));
builder.setJweAlgorithmConstraints(jweAlgConstraints);
AlgorithmConstraints jweEncConstraints =
new AlgorithmConstraints(ConstraintType.WHITELIST, ALGORITHMS.get(jweAlgo));
builder.setJweContentEncryptionAlgorithmConstraints(jweEncConstraints);
builder.setDecryptionKey(getJWEKey(this.jweKey, this.jweKeyAlgo, this.jweKeyPassword));
}
JwtConsumer jwtConsumer = builder.build();
JwtClaims claims = jwtConsumer.processToClaims(jwt);
return claims.toJson();
}
示例4: getSamplePayload
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
private static String getSamplePayload() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("issue-idp-1");
claims.setAudience("aud-1", "aud-2");
claims.setExpirationTimeMinutesInTheFuture(299);
claims.setGeneratedJwtId();
claims.setIssuedAtToNow();
claims.setNotBeforeMinutesInThePast(2);
claims.setSubject("johndoe");
claims.setClaim("email","[email protected]");
return claims.toJson();
}
示例5: generateJWT
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
public AccessToken generateJWT(boolean isSymmetric, EllipticCurveJsonWebKey signingKey, String aud, String scopes, JsonWebKey popKey, String encryptedSymmetricPopKey) throws Exception {
AccessToken token = new AccessToken();
token.setAudience(aud);
token.setScopes(scopes);
token.setKey(popKey);
// add the claims for aud, issuedAt
JwtClaims claims = new JwtClaims();
claims.setAudience(aud); // to whom the token is intended to be sent
claims.setGeneratedJwtId(); // a unique identifier for the token
claims.setIssuedAtToNow(); // when the token was issued/created (now)
token.setIssuedAt(new Date(claims.getIssuedAt().getValue()));
JsonWebSignature jws = new JsonWebSignature();
String claimsJson = claims.toJson();
// TODO: this is just a quick fix to handle objects in JwtClaims. Remove scary parsing.
String cnf = "";
// TODO: Verify against spec. It talks about cnf.ck instead.
if(isSymmetric) {
// TODO: is jwe the correct claim name to put it in?
cnf = "\"cnf\": {\"jwe\": \"" + encryptedSymmetricPopKey + "\"}";
}
else {
cnf = "\"cnf\": {\"jwk\":" + popKey.toJson(OutputControlLevel.INCLUDE_PRIVATE) + "}";
}
// remove last } sign
claimsJson = claimsJson.substring(0, claimsJson.length()-1);
// add cnf and add back the }
claimsJson += ", " + cnf + "}";
// set payload
jws.setPayload(claimsJson);
// JWT should be signed with AS private key
jws.setKey(signingKey.getPrivateKey());
jws.setKeyIdHeaderValue(signingKey.getKeyId());
// Set the signature algorithm on the JWT/JWS that will integrity protect the claims
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.ECDSA_USING_P256_CURVE_AND_SHA256);
// Sign
String tokenStr = jws.getCompactSerialization();
token.setAccessToken(tokenStr);
return token;
}
示例6: ServerState
import org.jose4j.jwt.JwtClaims; //导入方法依赖的package包/类
/**
* Constructs ServerState.
*
* @param clientState
* client side state
* @param additionalClaims
* additional claims
* @param nonce
* nonce
* @param clientCredentials
* client credentials suitable for the Authorization header and
* expected to be Basic authorization.
*/
public ServerState(final String clientState,
final JwtClaims additionalClaims,
final String nonce,
final String clientCredentials) {
this.clientState = clientState;
additionalClaimsJson = additionalClaims.toJson();
this.nonce = nonce;
this.clientCredentials = clientCredentials;
}