本文整理匯總了Java中org.jose4j.jwt.JwtClaims.setGeneratedJwtId方法的典型用法代碼示例。如果您正苦於以下問題:Java JwtClaims.setGeneratedJwtId方法的具體用法?Java JwtClaims.setGeneratedJwtId怎麽用?Java JwtClaims.setGeneratedJwtId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jose4j.jwt.JwtClaims
的用法示例。
在下文中一共展示了JwtClaims.setGeneratedJwtId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: generateJWT
import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
* Generates a JWT as String representation.
* Encodes the id and the role of the user as "userId" and "userRole" in the claims of the jwt
*
* @param user
* The user to generate the JWT from.
* @return The string representation of the jwt.
* @throws JoseException
* If the Jose library failed to create a JWT token.
*/
public static String generateJWT(User user) throws JoseException {
// generate claims with user data
JwtClaims claims = new JwtClaims();
claims.setIssuer("ALEX");
claims.setGeneratedJwtId();
claims.setClaim("id", user.getId());
claims.setClaim("role", user.getRole());
claims.setClaim("email", user.getEmail());
// create signature
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setKey(getKey().getPrivateKey());
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
// return signed jwt
return jws.getCompactSerialization();
}
示例5: signToken
import org.jose4j.jwt.JwtClaims; //導入方法依賴的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();
}
示例6: signToken
import org.jose4j.jwt.JwtClaims; //導入方法依賴的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();
}
示例7: 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);
}
}
示例8: createMalformedClaims
import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
* Create a JwtClaims object with prefilled sane defaults and missing mandatory claims.
* @return JwtClaims
*/
private JwtClaims createMalformedClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer(SSODataTest.DATA_ISSUER); // who creates the token and signs it
claims.setGeneratedJwtId(); // a unique identifier for the token
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;
}
示例9: 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;
}
示例10: 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();
}
示例11: rsaPublicKeyEncodingDecodingAndSign
import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
@Test
public void rsaPublicKeyEncodingDecodingAndSign() throws Exception
{
PublicJsonWebKey publicJsonWebKey = ExampleRsaJwksFromJwe.APPENDIX_A_1;
String pem = KeyPairUtil.pemEncode(publicJsonWebKey.getPublicKey());
String expectedPem = "-----BEGIN PUBLIC KEY-----\r\n" +
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoahUIoWw0K0usKNuOR6H\r\n" +
"4wkf4oBUXHTxRvgb48E+BVvxkeDNjbC4he8rUWcJoZmds2h7M70imEVhRU5djINX\r\n" +
"tqllXI4DFqcI1DgjT9LewND8MW2Krf3Spsk/ZkoFnilakGygTwpZ3uesH+PFABNI\r\n" +
"UYpOiN15dsQRkgr0vEhxN92i2asbOenSZeyaxziK72UwxrrKoExv6kc5twXTq4h+\r\n" +
"QChLOln0/mtUZwfsRaMStPs6mS6XrgxnxbWhojf663tuEQueGC+FCMfra36C9knD\r\n" +
"FGzKsNa7LZK2djYgyD3JR/MB/4NUJW/TqOQtwHYbxevoJArm+L5StowjzGy+/bq6\r\n" +
"GwIDAQAB\r\n" +
"-----END PUBLIC KEY-----";
Assert.assertThat(pem, equalTo(expectedPem));
RsaKeyUtil rsaKeyUtil = new RsaKeyUtil();
PublicKey publicKey = rsaKeyUtil.fromPemEncoded(pem);
Assert.assertThat(publicKey, equalTo(publicJsonWebKey.getPublicKey()));
JwtClaims claims = new JwtClaims();
claims.setSubject("meh");
claims.setExpirationTimeMinutesInTheFuture(20);
claims.setGeneratedJwtId();
claims.setAudience("you");
claims.setIssuer("me");
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setKey(publicJsonWebKey.getPrivateKey());
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);
String jwt = jws.getCompactSerialization();
Logger log = LoggerFactory.getLogger(this.getClass());
log.debug("The following JWT and public key should be (and were on 11/11/15) usable and produce a valid " +
"result at jwt.io (related to http://stackoverflow.com/questions/32744172):\n" + jwt + "\n" + pem);
}
示例12: 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);
}
}
示例13: payload2token
import org.jose4j.jwt.JwtClaims; //導入方法依賴的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;
}
示例14: constructJWTAssertion
import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private String constructJWTAssertion(NumericDate now) {
JwtClaims claims = new JwtClaims();
claims.setIssuer(this.getClientID());
claims.setAudience(JWT_AUDIENCE);
if (now == null) {
claims.setExpirationTimeMinutesInTheFuture(1.0f);
} else {
now.addSeconds(60L);
claims.setExpirationTime(now);
}
claims.setSubject(this.entityID);
claims.setClaim("box_sub_type", this.entityType.toString());
claims.setGeneratedJwtId(64);
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setKey(this.decryptPrivateKey());
jws.setAlgorithmHeaderValue(this.getAlgorithmIdentifier());
jws.setHeader("typ", "JWT");
if ((this.publicKeyID != null) && !this.publicKeyID.isEmpty()) {
jws.setHeader("kid", this.publicKeyID);
}
String assertion;
try {
assertion = jws.getCompactSerialization();
} catch (JoseException e) {
throw new BoxAPIException("Error serializing JSON Web Token assertion.", e);
}
return assertion;
}
示例15: getBaseClaims
import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims getBaseClaims() {
JwtClaims jwtClaims = new JwtClaims();
jwtClaims.setGeneratedJwtId();
jwtClaims.setExpirationTimeMinutesInTheFuture(60000);
jwtClaims.setAudience(ENTITY_IDENTIFIER);
jwtClaims.setIssuer(PLATFORM_IDENTIFIER);
jwtClaims.setIssuedAtToNow();
jwtClaims.setNotBeforeMinutesInThePast(0);
return jwtClaims;
}