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


Java JwtClaims.setStringListClaim方法代碼示例

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


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

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

示例2: buildInternalJWTClaimsSet

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public JwtClaims buildInternalJWTClaimsSet(final JwtClaims claims) {

    try {

        final JwtClaims newClaims = claims;
        newClaims.setSubject("internal-subject-" + newClaims.getSubject());
        newClaims.setStringListClaim(Qualifiers.ROLES, "users");
        return newClaims;
    } catch (final MalformedClaimException e) {
        throw new InternalServerErrorException(e);
    }
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:17,代碼來源:SampleInternalClaimsBuilder.java

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

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

示例5: testJwtGen

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
@Test
public void testJwtGen() throws Exception {
    JwtClaims claims = JwtHelper.getDefaultJwtClaims();
    claims.setClaim("user_id", "steve");
    claims.setClaim("user_type", "EMPLOYEE");
    claims.setClaim("client_id", "ddcaf0ba-1131-2232-3313-d6f2753f25dc");
    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

    String jwt = JwtHelper.getJwt(claims);
    Assert.assertNotNull(jwt);
    System.out.println(jwt);
}
 
開發者ID:networknt,項目名稱:light-oauth2,代碼行數:14,代碼來源:JwtGeneratorTest.java

示例6: mockClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public JwtClaims mockClaims() {
    JwtClaims claims = JwtHelper.getDefaultJwtClaims();
    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,代碼行數:10,代碼來源:JwtMockHandler.java

示例7: getTestClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims getTestClaims(String userId, String userType, String clientId, List<String> scope) {
    JwtClaims claims = JwtHelper.getDefaultJwtClaims();
    claims.setClaim("user_id", userId);
    claims.setClaim("user_type", userType);
    claims.setClaim("client_id", clientId);
    claims.setStringListClaim("scope", scope); // multi-valued claims work too and will end up as a JSON array
    return claims;
}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:9,代碼來源:JwtHelperTest.java

示例8: createJwt

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private String createJwt(String subject, RsaJsonWebKey rsaJsonWebKey) throws Exception {
	//
	// JSON Web Token is a compact URL-safe means of representing claims/attributes to be transferred between two parties.
	// This example demonstrates producing and consuming a signed JWT
	//

	// Create the Claims, which will be the content of the JWT
	JwtClaims claims = new JwtClaims();
	claims.setIssuer("eetlite.cz"); // who creates the token and signs it
	// claims.setAudience("roman"); // 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
	List<String> groups = Arrays.asList("ROLE_USER", "ROLE_MANAGER");
	claims.setStringListClaim("groups", groups); // multi-valued claims work too and will end up as a JSON array

	// A JWT is a JWS and/or a JWE with JSON claims as the payload.
	// In this example it is a JWS so we 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 private key
	jws.setKey(rsaJsonWebKey.getPrivateKey());

	// Set the Key ID (kid) header because it's just the polite thing to do.
	// We only have one key in this example but a using a Key ID helps
	// facilitate a smooth key rollover process
	// jws.setKeyIdHeaderValue(rsaJsonWebKey.getKeyId());

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

	// Sign the JWS and produce the compact serialization or the complete JWT/JWS
	// representation, which is a string consisting of three dot ('.') separated
	// base64url-encoded parts in the form Header.Payload.Signature
	// If you wanted to encrypt it, you can simply set this jwt as the payload
	// of a JsonWebEncryption object and set the cty (Content Type) header to "jwt".
	String jwt = jws.getCompactSerialization();
	return jwt;
}
 
開發者ID:eetlite,項目名稱:eet.osslite.cz,代碼行數:46,代碼來源:JwtRest.java

示例9: generateClaims

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private JwtClaims generateClaims(String dn, ConfigManager cfg, URL url, OpenIDConnectTrust trust, String nonce)
		throws LDAPException, ProvisioningException {
	StringBuffer issuer = new StringBuffer();
	issuer.append(url.getProtocol()).append("://").append(url.getHost());
	if (url.getPort() > 0) {
		issuer.append(':').append(url.getPort());
	}

	issuer.append(cfg.getAuthIdPPath()).append(this.idpName);
	
	
	// Create the Claims, which will be the content of the JWT
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(issuer.toString());  // who creates the token and signs it
    claims.setAudience(trust.getClientID()); // to whom the token is intended to be sent
    claims.setExpirationTimeMinutesInTheFuture(trust.getAccessTokenTimeToLive() / 1000 / 60); // 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(trust.getAccessTokenSkewMillis() / 1000 / 60); // time before which the token is not yet valid (2 minutes ago)
    //claims.setSubject(dn); // the subject/principal is whom the token is about
    if (nonce != null) {
    	claims.setClaim("nonce", nonce);
    }
    ArrayList<String> attrs = new ArrayList<String>();
    LDAPSearchResults res = cfg.getMyVD().search(dn,0, "(objectClass=*)", attrs);
    
    res.hasMore();
    LDAPEntry entry = res.next();
    
    User user = new User(entry); 
    user = this.mapper.mapUser(user, true);
    
    
    
    for (String attrName : user.getAttribs().keySet()) {
    	Attribute attr = user.getAttribs().get(attrName);
    	if (attr != null) {
	    	if (attr.getName().equalsIgnoreCase("sub")) {
	    		claims.setSubject(attr.getValues().get(0));
	    	} else if (attr.getValues().size() == 1) {
	    		claims.setClaim(attrName,attr.getValues().get(0));
	    	} else {
	    		claims.setStringListClaim(attrName, attr.getValues());
	    	}
    	}
    }
	return claims;
}
 
開發者ID:TremoloSecurity,項目名稱:OpenUnison,代碼行數:50,代碼來源:OpenIDConnectIdP.java


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