當前位置: 首頁>>代碼示例>>Java>>正文


Java JwtClaims.toJson方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:32,代碼來源:OidcIdTokenSigningAndEncryptionService.java

示例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;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:24,代碼來源:BasePasswordManagementService.java

示例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();
}
 
開發者ID:gahana,項目名稱:edge-jwt-sample,代碼行數:39,代碼來源:JWTValidator.java

示例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();
}
 
開發者ID:gahana,項目名稱:edge-jwt-sample,代碼行數:13,代碼來源:JWTUtil.java

示例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;
	}
 
開發者ID:erwah,項目名稱:acetest,代碼行數:56,代碼來源:JWT.java

示例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;
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:24,代碼來源:ServerState.java


注:本文中的org.jose4j.jwt.JwtClaims.toJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。