当前位置: 首页>>代码示例>>Java>>正文


Java JwtBuilder.claim方法代码示例

本文整理汇总了Java中io.jsonwebtoken.JwtBuilder.claim方法的典型用法代码示例。如果您正苦于以下问题:Java JwtBuilder.claim方法的具体用法?Java JwtBuilder.claim怎么用?Java JwtBuilder.claim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.jsonwebtoken.JwtBuilder的用法示例。


在下文中一共展示了JwtBuilder.claim方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jwtBuilder

import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
protected JwtBuilder jwtBuilder(long exp, Map<String, Object> ext){
    JwtBuilder jwt = Jwts.builder()
            .claim("user_id","43FE6476-CD7B-493B-8044-C7E3149D0876")
            .claim("scope","perm")
            .claim("client_id","console")
            .claim("username","admin");
    if(ext != null){
        for (Entry<String, Object> entry : ext.entrySet()){
            jwt.claim(entry.getKey(),entry.getValue());
        }
    }
    jwt.setExpiration(new Date(exp));
    return jwt;
}
 
开发者ID:bingo-oss,项目名称:sso-client,代码行数:15,代码来源:SSOClientTest.java

示例2: processAuthPermissions

import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
private static void processAuthPermissions(JwtBuilder builder, Authentication authentication) {
	builder.claim(AuthenticationClaims.CLAIM_NAME_ROOT, Boolean.valueOf(authentication.isRoot()));

	Collection<Permission> permissions = authentication.getPermissions();
	if (permissions != null && !permissions.isEmpty()) {
		Collection<String> ps = new ArrayList<>(permissions.size());
		for (Permission permission : permissions) {
			permission.getPermission().ifPresent(p -> ps.add(p));
		}
		if (!ps.isEmpty()) {
			builder.claim(AuthenticationClaims.CLAIM_NAME_PERMISSIONS, ps);
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:15,代码来源:JwtTokenBuilder.java

示例3: createJwtToken

import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
private String createJwtToken(String subject, LocalDateTime tokenExpirationDateTime, boolean isRefreshToken) {

		JwtBuilder jwtBuilder = Jwts.builder()
				.setSubject(subject)
				.signWith(SignatureAlgorithm.HS512, privateKey)
				.setExpiration(toDate(tokenExpirationDateTime));

		if (isRefreshToken) {
			jwtBuilder.claim(REFRESH_TOKEN_CLAIM_KEY, true);
		}

		return jwtBuilder.compact();
	}
 
开发者ID:ipalbeniz,项目名称:spring-demo-jwt,代码行数:14,代码来源:SecurityService.java

示例4: createToken

import io.jsonwebtoken.JwtBuilder; //导入方法依赖的package包/类
@Override
public String createToken(Authentication authentication, Boolean rememberMe) {

  Optional<Authentication> auth = Optional.ofNullable(authentication);

  String authorities = extractAuthorities(auth.map(Authentication::getAuthorities).orElseThrow(IllegalArgumentException::new));

  Date validity = provideValidityDate(rememberMe);

  String subject = auth.map(Authentication::getName).orElseThrow(IllegalArgumentException::new);

  JwtBuilder jwtBuilder = Jwts.builder()
    .setSubject(subject)
    .signWith(SignatureAlgorithm.HS256, jwtProperties.getToken().getSecret())
    .setExpiration(validity);

  if (!"".equals(authorities.trim())) {
    jwtBuilder.claim(jwtProperties.getToken().getPayload().getAuthoritiesKey(), authorities);
  }

  return jwtBuilder.compact();
}
 
开发者ID:Cobrijani,项目名称:jwt-security-spring-boot-starter,代码行数:23,代码来源:JJWTTokenProvider.java


注:本文中的io.jsonwebtoken.JwtBuilder.claim方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。