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


Java JsonWebSignature.setKeyIdHeaderValue方法代码示例

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


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

示例1: generateJWTAssertion

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String generateJWTAssertion(String email, String privateKeyBase64,
    float expiryInSeconds) {
  PrivateKey privateKey = getPrivateKey(privateKeyBase64);
  final JwtClaims claims = new JwtClaims();
  claims.setSubject(email);
  claims.setAudience("https://api.metamind.io/v1/oauth2/token");
  claims.setExpirationTimeMinutesInTheFuture(expiryInSeconds / 60);
  claims.setIssuedAtToNow();

  // Generate the payload
  final JsonWebSignature jws = new JsonWebSignature();
  jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
  jws.setPayload(claims.toJson());
  jws.setKeyIdHeaderValue(UUID.randomUUID().toString());

  // Sign using the private key
  jws.setKey(privateKey);
  try {
    return jws.getCompactSerialization();
  } catch (JoseException e) {
    return null;
  }
}
 
开发者ID:MetaMind,项目名称:quickstart,代码行数:24,代码来源:AssertionGenerator.java

示例2: prepareJsonWebSignatureForIdTokenSigning

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private void prepareJsonWebSignatureForIdTokenSigning(final OidcRegisteredService svc, final JsonWebSignature jws,
                                                      final RsaJsonWebKey jsonWebKey) {
    LOGGER.debug("Service [{}] is set to sign id tokens", svc);

    jws.setKey(jsonWebKey.getPrivateKey());
    jws.setAlgorithmConstraints(AlgorithmConstraints.DISALLOW_NONE);
    if (StringUtils.isBlank(jsonWebKey.getKeyId())) {
        jws.setKeyIdHeaderValue(UUID.randomUUID().toString());
    } else {
        jws.setKeyIdHeaderValue(jsonWebKey.getKeyId());
    }
    LOGGER.debug("Signing id token with key id header value [{}]", jws.getKeyIdHeaderValue());
    jws.setAlgorithmHeaderValue(getJsonWebKeySigningAlgorithm());

    LOGGER.debug("Signing id token with algorithm [{}]", jws.getAlgorithmHeaderValue());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:OidcIdTokenSigningAndEncryptionService.java

示例3: sign

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public String sign(final JwtClaims claims) {

    try {
        final RsaJsonWebKey aSigningKey = cachedDataProvider.getASigningKey();
        final JsonWebSignature jws = new JsonWebSignature();
        jws.setPayload(claims.toJson());
        jws.setKeyIdHeaderValue(aSigningKey.getKeyId());
        jws.setKey(aSigningKey.getPrivateKey());
        jws.setAlgorithmHeaderValue(aSigningKey.getAlgorithm());
        jws.sign();
        return jws.getCompactSerialization();
    } catch (final JoseException e) {
        throw new InternalServerErrorException(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:20,代码来源:JcaCryptoOps.java

示例4: generateJwt

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String generateJwt(RsaJsonWebKey jwk, Optional<String> keyId)
    throws JoseException {
  JwtClaims claims = new JwtClaims();
  claims.setIssuer("Issuer");
  claims.setAudience("Audience");

  JsonWebSignature jws = new JsonWebSignature();
  jws.setPayload(claims.toJson());
  jws.setKey(jwk.getPrivateKey());
  jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

  if (keyId.isPresent()) {
    jws.setKeyIdHeaderValue(keyId.get());
  }

  return jws.getCompactSerialization();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:18,代码来源:DefaultAuthTokenVerifierTest.java

示例5: uniqueKidTestFRJwksEndpoint

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void uniqueKidTestFRJwksEndpoint() throws JoseException
{
    // JSON content from https://demo.forgerock.com:8443/openam/oauth2/connect/jwk_uri on Jan 8, 2015
    String json = "{\"keys\":[{\"kty\":\"RSA\",\"kid\":\"fb301b61-9b8a-4c34-9212-5d6fb9df1a57\",\"use\":\"sig\",\"alg\":\"RS256\",\"n\":\"AK0kHP1O-RgdgLSoWxkuaYoi5Jic6hLKeuKw8WzCfsQ68ntBDf6tVOTn_kZA7Gjf4oJAL1dXLlxIEy-kZWnxT3FF-0MQ4WQYbGBfaW8LTM4uAOLLvYZ8SIVEXmxhJsSlvaiTWCbNFaOfiII8bhFp4551YB07NfpquUGEwOxOmci_\",\"e\":\"AQAB\"}]}";

    JsonWebKeySet jwks = new JsonWebKeySet(json);

    VerificationJwkSelector verificationJwkSelector = new VerificationJwkSelector();
    JsonWebSignature jws = new JsonWebSignature();
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
    jws.setKeyIdHeaderValue("fb301b61-9b8a-4c34-9212-5d6fb9df1a57");
    List<JsonWebKey> jsonWebKeys = jwks.getJsonWebKeys();
    List<JsonWebKey> selected = verificationJwkSelector.selectList(jws, jsonWebKeys);
    assertThat(1, equalTo(selected.size()));
    assertThat("fb301b61-9b8a-4c34-9212-5d6fb9df1a57", equalTo(selected.get(0).getKeyId()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:18,代码来源:VerificationJwkSelectorTest.java

示例6: uniqueKidTestMiterJwksEndpoint

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void uniqueKidTestMiterJwksEndpoint() throws JoseException
{
    // JSON content from https://mitreid.org/jwk on Jan 8, 2015
    String json = "{\"keys\":[{\"alg\":\"RS256\",\"e\":\"AQAB\",\"n\":\"23zs5r8PQKpsKeoUd2Bjz3TJkUljWqMD8X98SaIb1LE7dCQzi9jwO58FGL0ieY1Dfnr9-g1iiY8sNzV-byawK98W9yFiopaghfoKtxXgUD8pi0fLPeWmAkntjn28Z_WZvvA265ELbBhphPXEJcFhdzUfgESHVuqFMEqp1pB-CP0\"," +
            "\"kty\":\"RSA\",\"kid\":\"rsa1\"}]}";

    JsonWebKeySet jwks = new JsonWebKeySet(json);

    VerificationJwkSelector verificationJwkSelector = new VerificationJwkSelector();
    JsonWebSignature jws = new JsonWebSignature();
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
    jws.setKeyIdHeaderValue("rsa1");
    List<JsonWebKey> jsonWebKeys = jwks.getJsonWebKeys();
    List<JsonWebKey> selected = verificationJwkSelector.selectList(jws, jsonWebKeys);
    assertThat(1, equalTo(selected.size()));
    assertThat("rsa1", equalTo(selected.get(0).getKeyId()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:19,代码来源:VerificationJwkSelectorTest.java

示例7: uniqueKidTestNriPhpJwksEndpoint

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void uniqueKidTestNriPhpJwksEndpoint() throws JoseException
{
    // JSON content from https://connect.openid4.us/connect4us.jwk on Jan 8, 2015
    String json = "{\n" +
            " \"keys\":[\n" +
            "  {\n" +
            "   \"kty\":\"RSA\",\n" +
            "   \"n\":\"tf_sB4M0sHearRLzz1q1JRgRdRnwk0lz-IcVDFlpp2dtDVyA-ZM8Tu1swp7upaTNykf7cp3Ne_6uW3JiKvRMDdNdvHWCzDHmbmZWGdnFF9Ve-D1cUxj4ETVpUM7AIXWbGs34fUNYl3Xzc4baSyvYbc3h6iz8AIdb_1bQLxJsHBi-ydg3NMJItgQJqBiwCmQYCOnJlekR-Ga2a5XlIx46Wsj3Pz0t0dzM8gVSU9fU3QrKKzDFCoFHTgig1YZNNW5W2H6QwANL5h-nbgre5sWmDmdnfiU6Pj5GOQDmp__rweinph8OAFNF6jVqrRZ3QJEmMnO42naWOsxV2FAUXafksQ\",\n" +
            "   \"e\":\"AQAB\",\n" +
            "   \"kid\":\"ABOP-00\"\n" +
            "  }\n" +
            " ]\n" +
            "}\n";

    JsonWebKeySet jwks = new JsonWebKeySet(json);

    VerificationJwkSelector verificationJwkSelector = new VerificationJwkSelector();
    JsonWebSignature jws = new JsonWebSignature();
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA384);
    jws.setKeyIdHeaderValue("ABOP-00");
    List<JsonWebKey> jsonWebKeys = jwks.getJsonWebKeys();
    List<JsonWebKey> selected = verificationJwkSelector.selectList(jws, jsonWebKeys);
    assertThat(1, equalTo(selected.size()));
    assertThat("ABOP-00", equalTo(selected.get(0).getKeyId()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:27,代码来源:VerificationJwkSelectorTest.java

示例8: testAnEx

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void testAnEx() throws Exception
{
    String location = "https://www.example.org/";

    Get mockGet = mock(Get.class);
    when(mockGet.get(location)).thenThrow(new IOException(location + "says 'no GET for you!'"));
    HttpsJwks httpsJkws = new HttpsJwks(location);
    httpsJkws.setSimpleHttpGet(mockGet);
    HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(httpsJkws);

    JsonWebSignature jws = new JsonWebSignature();
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.ECDSA_USING_P256_CURVE_AND_SHA256);
    jws.setKeyIdHeaderValue("nope");
    try
    {
        Key key = resolver.resolveKey(jws, Collections.<JsonWebStructure>emptyList());
        fail("shouldn't have resolved a key but got " + key);

    }
    catch (UnresolvableKeyException e)
    {
        log.debug("this was expected and is okay: {}", e.toString());
    }
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:26,代码来源:HttpsJwksVerificationKeyResolverTest.java

示例9: signToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Signs an JWT authentication token, acting as simulated authentication
 * endpoint that issues auth tokens.
 *
 * @param tokenIssuer
 * @param signatureKeyPair
 * @param expirationTime
 *            Expiration time in minutes to set for {@code exp} claim. Can
 *            be <code>null</code>, in which case the header is left out.
 * @return
 * @throws JoseException
 */
private String signToken(String tokenIssuer, RsaJsonWebKey signatureKeyPair, DateTime expirationTime)
        throws JoseException {
    // Create the Claims, which will be the content of the JWT
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(tokenIssuer);
    if (expirationTime != null) {
        claims.setExpirationTime(NumericDate.fromMilliseconds(expirationTime.getMillis()));
    }
    claims.setGeneratedJwtId();
    NumericDate now = NumericDate.fromMilliseconds(UtcTime.now().getMillis());
    claims.setIssuedAt(now);
    // the subject/principal is whom the token is about
    claims.setSubject(TOKEN_SUBJECT);
    // additional claims
    claims.setClaim("role", TOKEN_ROLE);

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(signatureKeyPair.getPrivateKey());
    jws.setKeyIdHeaderValue(signatureKeyPair.getKeyId());
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
    return jws.getCompactSerialization();
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:36,代码来源:TestAuthTokenHeaderValidator.java

示例10: signToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Signs an JWT authentication token, acting as simulated authentication
 * endpoint that issues auth tokens.
 *
 * @param tokenIssuer
 * @param signatureKeyPair
 * @param expirationTime
 *            Expiration time in minutes to set for {@code exp} claim. Can
 *            be <code>null</code>, in which case the header is left out.
 * @return
 * @throws JoseException
 */
private String signToken(String tokenIssuer, RsaJsonWebKey signatureKeyPair, DateTime expirationTime)
        throws JoseException {
    // Create the Claims, which will be the content of the JWT
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(tokenIssuer);
    if (expirationTime != null) {
        claims.setExpirationTime(NumericDate.fromMilliseconds(expirationTime.getMillis()));
    }
    claims.setGeneratedJwtId();
    NumericDate now = NumericDate.fromMilliseconds(UtcTime.now().getMillis());
    claims.setIssuedAt(now);
    // the subject/principal is whom the token is about
    claims.setSubject("[email protected]");
    // additional claims
    claims.setClaim("role", "user");

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(signatureKeyPair.getPrivateKey());
    jws.setKeyIdHeaderValue(signatureKeyPair.getKeyId());
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
    return jws.getCompactSerialization();
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:36,代码来源:TestAuthTokenRequestFilter.java

示例11: generateAuthToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Generate an auth token with the given claims and sign the token with the
 * private key in the provided {@link RsaJsonWebKey}.
 */
public static String generateAuthToken(
    Optional<Collection<String>> audiences,
    Optional<String> email,
    NumericDate expirationTime,
    Optional<String> issuer,
    NumericDate notBefore,
    Optional<String> subject,
    RsaJsonWebKey rsaJsonWebKey) {
  JwtClaims claims = new JwtClaims();
  if (audiences.isPresent()) {
    claims.setAudience(ImmutableList.copyOf(audiences.get()));
  }
  if (email.isPresent()) {
    claims.setClaim("email", email.get());
  }
  if (issuer.isPresent()) {
    claims.setIssuer(issuer.get());
  }
  if (subject.isPresent()) {
    claims.setSubject(subject.get());
  }
  claims.setExpirationTime(expirationTime);
  claims.setNotBefore(notBefore);

  JsonWebSignature jsonWebSignature = new JsonWebSignature();
  jsonWebSignature.setPayload(claims.toJson());
  jsonWebSignature.setKey(rsaJsonWebKey.getPrivateKey());
  jsonWebSignature.setKeyIdHeaderValue(rsaJsonWebKey.getKeyId());
  jsonWebSignature.setAlgorithmHeaderValue(rsaJsonWebKey.getAlgorithm());

  try {
    return jsonWebSignature.getCompactSerialization();
  } catch (JoseException exception) {
    throw new RuntimeException("failed to generate JWT", exception);
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:41,代码来源:TestUtils.java

示例12: getJwt

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * A static method that generate JWT token from JWT claims object
 *
 * @param claims JwtClaims object
 * @return A string represents jwt token
 * @throws JoseException JoseException
 */
public static String getJwt(JwtClaims claims) throws JoseException {
    String jwt;
    RSAPrivateKey privateKey = (RSAPrivateKey) getPrivateKey(
            jwtConfig.getKey().getFilename(), jwtConfig.getKey().getPassword(), jwtConfig.getKey().getKeyName());

    // A JWT is a JWS and/or a JWE with JSON claims as the payload.
    // In this example it is a JWS nested inside a JWE
    // So we first create a JsonWebSignature object.
    JsonWebSignature jws = new JsonWebSignature();

    // The payload of the JWS is JSON content of the JWT Claims
    jws.setPayload(claims.toJson());

    // The JWT is signed using the sender's private key
    jws.setKey(privateKey);
    jws.setKeyIdHeaderValue(jwtConfig.getKey().getKid());

    // Set the signature algorithm on the JWT/JWS that will integrity protect the claims
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

    // Sign the JWS and produce the compact serialization, which will be the inner JWT/JWS
    // representation, which is a string consisting of three dot ('.') separated
    // base64url-encoded parts in the form Header.Payload.Signature
    jwt = jws.getCompactSerialization();
    return jwt;
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:34,代码来源:JwtHelper.java

示例13: getJwt

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String getJwt(JwtClaims claims) throws JoseException {
    String jwt;

    RSAPrivateKey privateKey = (RSAPrivateKey) getPrivateKey(
            "/config/oauth/primary.jks", "password", "selfsigned");

    // A JWT is a JWS and/or a JWE with JSON claims as the payload.
    // In this example it is a JWS nested inside a JWE
    // So we first create a JsonWebSignature object.
    JsonWebSignature jws = new JsonWebSignature();

    // The payload of the JWS is JSON content of the JWT Claims
    jws.setPayload(claims.toJson());

    // The JWT is signed using the sender's private key
    jws.setKey(privateKey);
    jws.setKeyIdHeaderValue("100");

    // Set the signature algorithm on the JWT/JWS that will integrity protect the claims
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

    // Sign the JWS and produce the compact serialization, which will be the inner JWT/JWS
    // representation, which is a string consisting of three dot ('.') separated
    // base64url-encoded parts in the form Header.Payload.Signature
    jwt = jws.getCompactSerialization();
    return jwt;
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:28,代码来源:Http2ClientIT.java

示例14: createJwt

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private String createJwt(String subject) throws Exception {
    JwtClaims claims = new JwtClaims();
    claims.setSubject(subject);
    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(jsonWebKey.getKey());
    jws.setKeyIdHeaderValue(jsonWebKey.getKeyId());
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);

    return jws.getCompactSerialization();
}
 
开发者ID:andban,项目名称:dropwizard-auth-jwt,代码行数:12,代码来源:BaseJwtAuthenticatorTest.java

示例15: payload2token

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String payload2token(String subject, Object payload, long minutes) throws JoseException {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(TOKEN_ISSUER);
    claims.setAudience(TOKEN_AUDIENCE);
    claims.setExpirationTimeMinutesInTheFuture(minutes);
    claims.setGeneratedJwtId();
    claims.setIssuedAtToNow();
    claims.setNotBeforeMinutesInThePast(2);
    claims.setSubject(subject);
    claims.setStringClaim(CLAIM_KEY, jsonHelper.object2json(payload));

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());

    jws.setKey(getKey());
    jws.setKeyIdHeaderValue(KEY_ID);
    jws.setAlgorithmHeaderValue(getAlgorithm());


    String token = jws.getCompactSerialization();
    if (!tokenService.contains(token)) {
        tokenService.store(token, null); //todo
    }

    return token;

}
 
开发者ID:chonglou,项目名称:itpkg,代码行数:28,代码来源:JwtHelper.java


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