当前位置: 首页>>代码示例>>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;未经允许,请勿转载。