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


Java JwtClaims.setIssuedAtToNow方法代碼示例

本文整理匯總了Java中org.jose4j.jwt.JwtClaims.setIssuedAtToNow方法的典型用法代碼示例。如果您正苦於以下問題:Java JwtClaims.setIssuedAtToNow方法的具體用法?Java JwtClaims.setIssuedAtToNow怎麽用?Java JwtClaims.setIssuedAtToNow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jose4j.jwt.JwtClaims的用法示例。


在下文中一共展示了JwtClaims.setIssuedAtToNow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateJWTAssertion

import org.jose4j.jwt.JwtClaims; //導入方法依賴的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: createDefaultClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Create a JwtClaims object with prefilled sane defaults.
 * @return JwtClaims
 */
private JwtClaims createDefaultClaims() {

  JwtClaims claims = new JwtClaims();

  claims.setIssuer(SSODataTest.DATA_ISSUER);  // who creates the token and signs it
  claims.setAudience(SSODataTest.DATA_AUDIENCE); // to whom the token is intended to be sent
  claims.setExpirationTimeMinutesInTheFuture(10); // time when the token will expire (10 minutes from now)
  claims.setGeneratedJwtId(); // a unique identifier for the token
  claims.setIssuedAtToNow();  // when the token was issued/created (now)
  claims.setNotBeforeMinutesInThePast(2); // time before which the token is not yet valid (2 minutes ago)
  claims.setSubject(SSODataTest.DATA_USER_ID); // the subject/principal is whom the token is about
  claims.setClaim(SSOData.KEY_INSTANCE_ID, SSODataTest.DATA_INSTANCE_ID); // additional claims/attributes about the subject can be added

  return claims;
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:20,代碼來源:SSOFacadeTest.java

示例3: testMissingNBFCLaim

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Test proper signed token missing mandatory nbf claim.
 * @throws JoseException
 */
@Test(expected=SSOException.class)
public void testMissingNBFCLaim() throws JoseException, SSOException {

  RsaJsonWebKey jwk = this.generateRsaJwk();
  JwtClaims claims = this.createMalformedClaims();

  claims.setExpirationTimeMinutesInTheFuture(10);
  claims.setIssuedAtToNow();
  //claims.setNotBeforeMinutesInThePast(2);

  String jwt = this.createSignedTokenFromClaims(claims, jwk);

  final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
  ssoFac.verify(jwt);
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:20,代碼來源:SSOFacadeTest.java

示例4: testFutureNBFCLaim

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Test proper signed token valid in an hour.
 * @throws JoseException
 */
@Test(expected=SSOException.class)
public void testFutureNBFCLaim() throws JoseException, SSOException {

  RsaJsonWebKey jwk = this.generateRsaJwk();
  JwtClaims claims = this.createMalformedClaims();

  NumericDate nbf = NumericDate.now();
  nbf.addSeconds(3600);

  claims.setExpirationTimeMinutesInTheFuture(10);
  claims.setIssuedAtToNow();
  claims.setNotBefore(nbf);

  String jwt = this.createSignedTokenFromClaims(claims, jwk);

  final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
  ssoFac.verify(jwt);
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:23,代碼來源:SSOFacadeTest.java

示例5: testMissingEXPCLaim

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Test proper signed token missing mandatory exp claim.
 * @throws JoseException
 */
@Test(expected=SSOException.class)
public void testMissingEXPCLaim() throws JoseException, SSOException {

  RsaJsonWebKey jwk = this.generateRsaJwk();
  JwtClaims claims = this.createMalformedClaims();

  //claims.setExpirationTimeMinutesInTheFuture(10);
  claims.setIssuedAtToNow();
  claims.setNotBeforeMinutesInThePast(2);

  String jwt = this.createSignedTokenFromClaims(claims, jwk);

  final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
  ssoFac.verify(jwt);
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:20,代碼來源:SSOFacadeTest.java

示例6: testPastEXPCLaim

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Test proper signed token already expired.
 * @throws JoseException
 */
@Test(expected=SSOException.class)
public void testPastEXPCLaim() throws JoseException, SSOException  {

  RsaJsonWebKey jwk = this.generateRsaJwk();
  JwtClaims claims = this.createMalformedClaims();

  NumericDate exp = NumericDate.now();
  exp.addSeconds(-3600);

  claims.setExpirationTime(exp);
  claims.setIssuedAtToNow();
  claims.setNotBeforeMinutesInThePast(2);

  String jwt = this.createSignedTokenFromClaims(claims, jwk);

  final SSOFacade ssoFac = SSOFacade.create(jwk.getRsaPublicKey());
  ssoFac.verify(jwt);
 }
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:23,代碼來源:SSOFacadeTest.java

示例7: 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

示例8: getDefaultJwtClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Construct a default JwtClaims
 *
 * @return JwtClaims
 */
public static JwtClaims getDefaultJwtClaims() {
    JwtConfig config = (JwtConfig) Config.getInstance().getJsonObjectConfig(JWT_CONFIG, JwtConfig.class);

    JwtClaims claims = new JwtClaims();

    claims.setIssuer(config.getIssuer());
    claims.setAudience(config.getAudience());
    claims.setExpirationTimeMinutesInTheFuture(config.getExpiredInMinutes());
    claims.setGeneratedJwtId(); // a unique identifier for the token
    claims.setIssuedAtToNow();  // when the token was issued/created (now)
    claims.setNotBeforeMinutesInThePast(2); // time before which the token is not yet valid (2 minutes ago)
    claims.setClaim("version", config.getVersion());
    return claims;

}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:21,代碼來源:JwtHelper.java

示例9: getTestClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private static JwtClaims getTestClaims() {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer("urn:com:networknt:oauth2:v1");
    claims.setAudience("urn:com.networknt");
    claims.setExpirationTimeMinutesInTheFuture(10);
    claims.setGeneratedJwtId(); // a unique identifier for the token
    claims.setIssuedAtToNow();  // when the token was issued/created (now)
    claims.setNotBeforeMinutesInThePast(2); // time before which the token is not yet valid (2 minutes ago)
    claims.setClaim("version", "1.0");

    claims.setClaim("user_id", "steve");
    claims.setClaim("user_type", "EMPLOYEE");
    claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
    List<String> scope = Arrays.asList("api.r", "api.w");
    claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
    return claims;
}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:18,代碼來源:Http2ClientIT.java

示例10: createToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的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

示例11: createToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
@NotNull
public static String createToken(@NotNull JsonWebEncryption jwe, @NotNull User user, @NotNull NumericDate expireAt) {
  try {
    JwtClaims claims = new JwtClaims();
    claims.setExpirationTime(expireAt);
    claims.setGeneratedJwtId(); // a unique identifier for the token
    claims.setIssuedAtToNow();  // when the token was issued/created (now)
    claims.setNotBeforeMinutesInThePast(0.5f); // time before which the token is not yet valid (30 seconds ago)
    if (!user.isAnonymous()) {
      claims.setSubject(user.getUserName()); // the subject/principal is whom the token is about
      setClaim(claims, "email", user.getEmail());
      setClaim(claims, "name", user.getRealName());
      setClaim(claims, "external", user.getExternalId());
    }
    jwe.setPayload(claims.toJson());
    return jwe.getCompactSerialization();
  } catch (JoseException e) {
    throw new IllegalStateException(e);
  }
}
 
開發者ID:bozaro,項目名稱:git-as-svn,代碼行數:21,代碼來源:TokenHelper.java

示例12: getJwtClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims getJwtClaims() {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer("Issuer");  // who creates the token and signs it
    claims.setAudience("Audience"); // to whom the token is intended to be sent
    claims.setExpirationTimeMinutesInTheFuture(10); // time when the token will expire (10 minutes from now)
    claims.setGeneratedJwtId(); // a unique identifier for the token
    claims.setIssuedAtToNow();  // when the token was issued/created (now)
    claims.setNotBeforeMinutesInThePast(2); // time before which the token is not yet valid (2 minutes ago)
    claims.setSubject("subject"); // the subject/principal is whom the token is about
    claims.setClaim("email", "[email protected]"); // additional claims/attributes about the subject can be added
    return claims;
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro,代碼行數:13,代碼來源:Jose4JTest.java

示例13: createTokenFromUsername

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public String createTokenFromUsername(String username) throws JoseException {
    JwtClaims claims = new JwtClaims();
    claims.setExpirationTimeMinutesInTheFuture(60 * 24);
    claims.setIssuedAtToNow();
    claims.setClaim("username", username);

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(signatureKey);
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA512);

    String token = jws.getCompactSerialization();
    return token;
}
 
開發者ID:tosinoni,項目名稱:SECP,代碼行數:15,代碼來源:TokenController.java

示例14: 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

示例15: getToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public String getToken(TokenDTO data) {

	try {

	    ZonedDateTime expiration = ZonedDateTime.now(ZoneOffset.UTC).plus(daysOfValidity, ChronoUnit.DAYS);

	    Key key = new HmacKey(secret.getBytes("UTF-8"));

	    JwtClaims claims = new JwtClaims();
	    claims.setExpirationTime(NumericDate.fromMilliseconds(expiration.toInstant().toEpochMilli()));
	    claims.setGeneratedJwtId();
	    claims.setIssuedAtToNow();
	    claims.setNotBeforeMinutesInThePast(2);
	    claims.setSubject(data.getSubject());
	    claims.setIssuer(data.getIssuer());
	    claims.setClaim(EMAIL_KEY, data.getEmail());

	    JsonWebSignature jws = new JsonWebSignature();
	    jws.setPayload(claims.toJson());
	    jws.setKey(key);
	    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);

	    return jws.getCompactSerialization();

	} catch (JoseException | UnsupportedEncodingException e) {
	    throw new RuntimeException("An error occured while building a token", e);
	}

    }
 
開發者ID:tomacla,項目名稱:auth-token,代碼行數:30,代碼來源:TokenManager.java


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