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


Java JwtClaims.setClaim方法代碼示例

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


在下文中一共展示了JwtClaims.setClaim方法的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;
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:20,代碼來源:SSOFacadeTest.java

示例2: createJwtClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private static JwtClaims createJwtClaims(
    List<String> audiences,
    String email,
    int expiration,
    String subject,
    int notBefore,
    String issuer) {

  JwtClaims jwtClaims = new JwtClaims();
  jwtClaims.setAudience(audiences);
  jwtClaims.setExpirationTimeMinutesInTheFuture(expiration);
  jwtClaims.setClaim("email", email);
  jwtClaims.setSubject(subject);
  jwtClaims.setNotBeforeMinutesInThePast(notBefore);
  jwtClaims.setIssuer(issuer);
  return jwtClaims;
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:18,代碼來源:AuthenticatorTest.java

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

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

示例5: 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();
}
 
開發者ID:LearnLib,項目名稱:alex,代碼行數:29,代碼來源:JWTHelper.java

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

示例7: 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();
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:36,代碼來源:TestAuthTokenRequestFilter.java

示例8: generateToken

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

示例9: generateToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public String generateToken(boolean forcenew) {
	JwtClaims claims = new JwtClaims();
	claims.setClaim("appID", appId);
	claims.setClaim("userID", userId);
	claims.setClaim("keyID", keyId);
	claims.setExpirationTimeMinutesInTheFuture(10);
	claims.setNotBeforeMinutesInThePast(10);
	
	JsonWebSignature jws = new JsonWebSignature();
	
	jws.setKey(eCDSAPrivateKey);
	jws.setPayload(claims.toJson());
	jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.ECDSA_USING_P256_CURVE_AND_SHA256);
	try {
		return jws.getCompactSerialization();
	} catch (JoseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:callstats-io,項目名稱:callstats.java,代碼行數:22,代碼來源:LocalTokenGenerator.java

示例10: 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; 
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:16,代碼來源:SSOFacadeTest.java

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

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

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

示例14: mockCcClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims mockCcClaims(String clientId, String scopeString, Map<String, Object> formMap) {
    JwtClaims claims = JwtHelper.getDefaultJwtClaims();
    claims.setClaim("client_id", clientId);
    List<String> scope = Arrays.asList(scopeString.split("\\s+"));
    claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
    if(formMap != null) {
        for(Map.Entry<String, Object> entry : formMap.entrySet()) {
            claims.setClaim(entry.getKey(), entry.getValue());
        }
    }
    return claims;
}
 
開發者ID:networknt,項目名稱:light-oauth2,代碼行數:13,代碼來源:Oauth2TokenPostHandler.java

示例15: mockAcClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims mockAcClaims(String clientId, String scopeString, String userId, String userType, Map<String, Object> formMap) {
    JwtClaims claims = JwtHelper.getDefaultJwtClaims();
    claims.setClaim("user_id", userId);
    claims.setClaim("user_type", userType);
    claims.setClaim("client_id", clientId);
    List<String> scope = Arrays.asList(scopeString.split("\\s+"));
    claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
    if(formMap != null) {
        for(Map.Entry<String, Object> entry : formMap.entrySet()) {
            claims.setClaim(entry.getKey(), entry.getValue());
        }
    }
    return claims;
}
 
開發者ID:networknt,項目名稱:light-oauth2,代碼行數:15,代碼來源:Oauth2TokenPostHandler.java


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