当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebSignature.setDoKeyValidation方法代码示例

本文整理汇总了Java中org.jose4j.jws.JsonWebSignature.setDoKeyValidation方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.setDoKeyValidation方法的具体用法?Java JsonWebSignature.setDoKeyValidation怎么用?Java JsonWebSignature.setDoKeyValidation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jose4j.jws.JsonWebSignature的用法示例。


在下文中一共展示了JsonWebSignature.setDoKeyValidation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String generateToken(String subject) {
    final JwtClaims claims = new JwtClaims();
    claims.setSubject(subject);
    claims.setExpirationTimeMinutesInTheFuture(TOKEN_EXPIRATION_IN_MINUTES);

    final JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setAlgorithmHeaderValue(HMAC_SHA256);
    jws.setKey(new HmacKey(tokenSecret));
    jws.setDoKeyValidation(false); //relaxes hmac key length restrictions

    try {
        return jws.getCompactSerialization();
    } catch (JoseException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:18,代码来源:TokenGenerator.java

示例2: createToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String createToken(Key key, JsonObject jsonClaims) {

        JwtClaims claims = new JwtClaims();
        claims.setSubject(jsonClaims.toString());
        claims.setIssuedAtToNow();
        claims.setExpirationTime(NumericDate.fromSeconds(NumericDate.now().getValue() + JWT_TOKEN_EXPIRES_TIME));

        JsonWebSignature jws = new JsonWebSignature();
        jws.setDoKeyValidation(false);
        jws.setPayload(claims.toJson());
        jws.setKey(key);
        jws.setAlgorithmHeaderValue(ALG);

        try {
            return jws.getCompactSerialization();
        } catch (JoseException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }

        return null;
    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:22,代码来源:JWTokenFactory.java

示例3: createExternalAccountBinding

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Creates a JSON structure for external account binding.
 *
 * @param kid
 *            Key Identifier provided by the CA
 * @param accountKey
 *            {@link PublicKey} of the account to register
 * @param macKey
 *            {@link SecretKey} to sign the key identifier with
 * @param resource
 *            "newAccount" resource URL
 * @return Created JSON structure
 */
private Map<String, Object> createExternalAccountBinding(String kid,
            PublicKey accountKey, SecretKey macKey, URL resource)
            throws AcmeException {
    try {
        PublicJsonWebKey keyJwk = PublicJsonWebKey.Factory.newPublicJwk(accountKey);

        JsonWebSignature innerJws = new JsonWebSignature();
        innerJws.setPayload(keyJwk.toJson());
        innerJws.getHeaders().setObjectHeaderValue("url", resource);
        innerJws.getHeaders().setObjectHeaderValue("kid", kid);
        innerJws.setAlgorithmHeaderValue(macKeyAlgorithm(macKey));
        innerJws.setKey(macKey);
        innerJws.setDoKeyValidation(false);
        innerJws.sign();

        JSONBuilder outerClaim = new JSONBuilder();
        outerClaim.put("protected", innerJws.getHeaders().getEncodedHeader());
        outerClaim.put("signature", innerJws.getEncodedSignature());
        outerClaim.put("payload", innerJws.getEncodedPayload());
        return outerClaim.toMap();
    } catch (JoseException ex) {
        throw new AcmeException("Could not create external account binding", ex);
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:38,代码来源:AccountBuilder.java

示例4: generateToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String generateToken(boolean forcenew) {
	JwtClaims claims = new JwtClaims();
	claims.setClaim("appID", appId);
	claims.setClaim("userID", userId);
	if (keyId != null) {
		claims.setClaim("keyID", keyId);
	}
	claims.setExpirationTimeMinutesInTheFuture(10);
	claims.setNotBeforeMinutesInThePast(10);
	
	JsonWebSignature jws = new JsonWebSignature();
	jws.setPayload(claims.toJson());
	jws.setKey(key);
	jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
	// For backwards compatibility with old app secrets
	jws.setDoKeyValidation(false);
	try {
		String jwt = jws.getCompactSerialization();
		return jwt;
	} catch (JoseException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:callstats-io,项目名称:callstats.java,代码行数:25,代码来源:TokenGeneratorHs256.java

示例5: toToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String toToken(byte[] key, JwtClaims claims) {
    final JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setAlgorithmHeaderValue(HMAC_SHA256);
    jws.setKey(new HmacKey(key));
    jws.setDoKeyValidation(false);

    try {
        return jws.getCompactSerialization();
    }
    catch (JoseException e) { throw Throwables.propagate(e); }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:13,代码来源:AuthorizationHelper.java

示例6: jwsSign

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String jwsSign(Key key, String payload) throws Exception {
	JsonWebSignature jws = new JsonWebSignature();
	jws.setPayload(payload);
	jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA512);
	jws.setKey(key);
	jws.setDoKeyValidation(false);
	return jws.getCompactSerialization();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:9,代码来源:JWTUtil.java

示例7: jwsVerify

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String jwsVerify(Key key, String jwt) throws Exception {
	JsonWebSignature jws = new JsonWebSignature();
	jws.setCompactSerialization(jwt);
	jws.setKey(key);
	jws.setDoKeyValidation(false);
	boolean signatureVerified = jws.verifySignature();

	System.out.println("JWS signature verification: " + signatureVerified);
	System.out.println("JWT Headers: " + jws.getHeaders().getFullHeaderAsJsonString() );

	return jws.getPayload();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:13,代码来源:JWTUtil.java

示例8: verifyJWS

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private void verifyJWS(Key key, String jwt) {
	try {
		JsonWebSignature jws = new JsonWebSignature();
		jws.setKey(key);
		jws.setCompactSerialization(jwt);
		jws.setDoKeyValidation(false);
		assertTrue(jws.verifySignature());
		JwtClaims claims = JwtClaims.parse(jws.getPayload());
		assertEquals("abc xyz", claims.getSubject());
		assertEquals("[email protected]", claims.getClaimValue("email"));
	} catch (Exception e) {
		fail();
	}
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:15,代码来源:JWTGeneratorTest.java

示例9: createJWT

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String createJWT(final String secret, final String payload) throws JoseException
{
	String token;
	JsonWebSignature sig = new JsonWebSignature();
	//sig.setKey(new HmacKey(DigestUtils.sha256(secret.getBytes(StandardCharsets.UTF_8))));
	sig.setKey(new HmacKey(secret.getBytes(StandardCharsets.UTF_8)));
	sig.setDoKeyValidation(false);
	sig.setPayload(payload);
	sig.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
	sig.setHeader(HeaderParameterNames.TYPE, "JWT");

	token = sig.getCompactSerialization();
	return token;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:15,代码来源:JwtCreationRestServiceImpl.java


注:本文中的org.jose4j.jws.JsonWebSignature.setDoKeyValidation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。