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


Java Claims.put方法代码示例

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


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

示例1: createRefreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public JwtToken createRefreshToken(UserContext userContext) {
  if (StringUtils.isBlank(userContext.getTenantId())) 
    throw new IllegalArgumentException("Cannot create JWT Token without tenantId");

  if (StringUtils.isBlank(userContext.getOrgId())) 
    throw new IllegalArgumentException("Cannot create JWT Token without orgId");

    DateTime currentTime = new DateTime();

    Claims claims = Jwts.claims().setSubject(userContext.getOrgId());
    claims.put("scopes", userContext.getAuthorities().stream().map(s -> s.toString()).collect(Collectors.toList()));
    claims.put("tenant", userContext.getTenantId());
    
    String token = Jwts.builder()
      .setClaims(claims)
      .setIssuer(settings.getTokenIssuer())
      .setId(UUID.randomUUID().toString())
      .setIssuedAt(currentTime.toDate())
      .setExpiration(currentTime.plusMinutes(settings.getRefreshTokenExpTime()).toDate())
      .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey())
    .compact();

    return new AccessJwtToken(token, claims);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:25,代码来源:JwtTokenFactory.java

示例2: createRefreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public JwtToken createRefreshToken(SecurityUser securityUser) {
  if (StringUtils.isBlank(securityUser.getEmail())) {
    throw new IllegalArgumentException("Cannot create JWT Token without username/email");
  }

  DateTime currentTime = new DateTime();

  UserPrincipal principal = securityUser.getUserPrincipal();
  Claims claims = Jwts.claims().setSubject(principal.getValue());
  claims.put(SCOPES, Arrays.asList(Authority.REFRESH_TOKEN.name()));
  claims.put(USER_ID, securityUser.getId().getId().toString());
  claims.put(IS_PUBLIC, principal.getType() == UserPrincipal.Type.PUBLIC_ID);

  String token = Jwts.builder().setClaims(claims).setIssuer(settings.getTokenIssuer())
      .setId(UUID.randomUUID().toString()).setIssuedAt(currentTime.toDate())
      .setExpiration(currentTime.plusSeconds(settings.getRefreshTokenExpTime()).toDate())
      .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey()).compact();

  return new AccessJwtToken(token, claims);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:21,代码来源:JwtTokenFactory.java

示例3: createRefreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public JwtToken createRefreshToken(UserContext userContext) {
    if (StringUtils.isBlank(userContext.getUsername())) {
        throw new IllegalArgumentException("Cannot create JWT Token without username");
    }

    LocalDateTime currentTime = LocalDateTime.now();

    Claims claims = Jwts.claims().setSubject(userContext.getUsername());
    claims.put("scopes", Arrays.asList(Scopes.REFRESH_TOKEN.authority()));
    
    String token = Jwts.builder()
      .setClaims(claims)
      .setIssuer(AppConfig.prop.getProperty("security.tokenIssuer"))
      .setId(UUID.randomUUID().toString())
      .setIssuedAt(Date.from(currentTime.atZone(ZoneId.systemDefault()).toInstant()))
      .setExpiration(Date.from(currentTime
          .plusMinutes(Long.parseLong(AppConfig.prop.getProperty("security.refreshTokenExpTime")))
          .atZone(ZoneId.systemDefault()).toInstant()))
      .signWith(SignatureAlgorithm.HS512, AppConfig.prop.getProperty("security.tokenSigningKey"))
    .compact();

    return new AccessJwtToken(token, claims);
}
 
开发者ID:mjfcolas,项目名称:infotaf,代码行数:24,代码来源:JwtTokenFactory.java

示例4: getEnterpriseToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * Get the enterprise token witch can used to invoke admin api,such as managing departments and groups
 *
 * @param enterpriseId Your enterprise id
 * @param expirationTimeSeconds Expiration time seconds in the future(can not be bigger than 60)
 * @return Detailed user access information
 * @throws YfyException
 */
public YfyAuthFinish getEnterpriseToken(long enterpriseId, int expirationTimeSeconds) throws YfyException {
    Claims claims = new DefaultClaims();
    claims.put("yifangyun_sub_type", "enterprise");
    claims.setSubject(String.valueOf(enterpriseId));
    claims.setExpiration(getExpirationTimeSecondsInTheFuture(expirationTimeSeconds));
    claims.setIssuedAt(new Date());
    claims.setId(getGeneratedJwtId(16));
    final String compactJws = Jwts.builder().setHeader(headers).setClaims(claims).signWith(SignatureAlgorithm.RS256, key).compact();

    return YfyRequestUtil.doPostInAuth(
            requestConfig,
            YfyAppInfo.getHost().getAuth(),
            "oauth/token",
            new HashMap<String, String>() {{
                put("grant_type", "jwt");
                put("assertion", compactJws);
            }},
            YfyAuthFinish.class);
}
 
开发者ID:yifangyun,项目名称:fangcloud-java-sdk,代码行数:28,代码来源:YfyEnterpriseAuth.java

示例5: addAuthentication

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
void addAuthentication(HttpServletResponse response, String username, Collection<? extends GrantedAuthority> authorities) throws IOException {
    List<String> roles = authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
    Claims claims = Jwts.claims()
            .setSubject(username)
            .setExpiration(new Date(System.currentTimeMillis() + expirationTime * 60 * 1000));
    claims.put(ROLE_KEY, roles.stream().collect(Collectors.joining(ROLE_DELIMITER)));

    String JWT = Jwts.builder()
            .setClaims(claims)
            .signWith(SignatureAlgorithm.HS512, secret)
            .compact();

    response.addHeader(headerString, headerStartWith + JWT);

    JwtAuthenticatedUser user = new JwtAuthenticatedUser(username, roles);

    PrintWriter printWriter = response.getWriter();
    printWriter.print(mapper.writeValueAsString(user));
    printWriter.flush();
}
 
开发者ID:TraineeSIIp,项目名称:PepSIIrup-2017,代码行数:21,代码来源:TokenAuthenticationService.java

示例6: createJwtToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
@Override
public String createJwtToken(Authentication authentication, int minutes) {
  Claims claims = Jwts.claims()
      .setId(String.valueOf(IdentityGenerator.generate()))
      .setSubject(authentication.getName())
      .setExpiration(new Date(currentTimeMillis() + minutes * 60 * 1000))
      .setIssuedAt(new Date());

  String authorities = authentication.getAuthorities()
      .stream()
      .map(GrantedAuthority::getAuthority)
      .map(String::toUpperCase)
      .collect(Collectors.joining(","));

  claims.put(AUTHORITIES, authorities);

  return Jwts.builder()
      .setClaims(claims)
      .signWith(HS512, secretkey)
      .compact();
}
 
开发者ID:springuni,项目名称:springuni-particles,代码行数:22,代码来源:JwtTokenServiceImpl.java

示例7: createAccessJwtToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * Factory method for issuing new JWT Tokens.
 * 
 * @param username
 * @param roles
 * @return
 */
public AccessJwtToken createAccessJwtToken(UserContext userContext) {
    if (StringUtils.isBlank(userContext.getUsername())) 
        throw new IllegalArgumentException("Cannot create JWT Token without username");

    if (userContext.getAuthorities() == null || userContext.getAuthorities().isEmpty()) 
        throw new IllegalArgumentException("User doesn't have any privileges");

    Claims claims = Jwts.claims().setSubject(userContext.getUsername());
    claims.put("scopes", userContext.getAuthorities().stream().map(s -> s.toString()).collect(Collectors.toList()));

    LocalDateTime currentTime = LocalDateTime.now();
    
    String token = Jwts.builder()
      .setClaims(claims)
      .setIssuer(AppConfig.prop.getProperty("security.tokenIssuer"))
      .setIssuedAt(Date.from(currentTime.atZone(ZoneId.systemDefault()).toInstant()))
      .setExpiration(Date.from(currentTime
          .plusMinutes(Long.parseLong(AppConfig.prop.getProperty("security.tokenExpirationTime")))
          .atZone(ZoneId.systemDefault()).toInstant()))
      .signWith(SignatureAlgorithm.HS512, AppConfig.prop.getProperty("security.tokenSigningKey"))
    .compact();

    return new AccessJwtToken(token, claims);
}
 
开发者ID:mjfcolas,项目名称:infotaf,代码行数:32,代码来源:JwtTokenFactory.java

示例8: refreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String refreshToken(String token) {
    String refreshedToken;
    try {
        final Claims claims = getClaimsFromToken(token);
        claims.put(CLAIM_KEY_CREATED, timeProvider.now());
        refreshedToken = doGenerateToken(claims);
    } catch (Exception e) {
        refreshedToken = null;
    }
    return refreshedToken;
}
 
开发者ID:rodrigues882013,项目名称:springboot-rest-api-skeleton,代码行数:12,代码来源:JwtTokenUtil.java

示例9: refreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String refreshToken(String token) {
    String refreshedToken;
    try {
        final Claims claims = getClaimsFromToken(token);
        claims.put(CLAIM_KEY_CREATED, new Date());
        refreshedToken = generateToken(claims);
    } catch (Exception e) {
        refreshedToken = null;
    }
    return refreshedToken;
}
 
开发者ID:upcyiban,项目名称:Integrate,代码行数:12,代码来源:JwtTokenUtil.java

示例10: createToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
public String createToken(String username, List<Role> roles) {

    Claims claims = Jwts.claims().setSubject(username);
    claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));

    Date now = new Date();
    Date validity = new Date(now.getTime() + validityInMilliseconds);

    return Jwts.builder()//
        .setClaims(claims)//
        .setIssuedAt(now)//
        .setExpiration(validity)//
        .signWith(SignatureAlgorithm.HS256, secretKey)//
        .compact();
  }
 
开发者ID:murraco,项目名称:spring-boot-jwt,代码行数:16,代码来源:JwtTokenProvider.java

示例11: refreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * Cria um novo token (refresh).
 * 
 * @param token
 * @return String
 */
public String refreshToken(String token) {
	String refreshedToken;
	try {
		Claims claims = getClaimsFromToken(token);
		claims.put(CLAIM_KEY_CREATED, new Date());
		refreshedToken = gerarToken(claims);
	} catch (Exception e) {
		refreshedToken = null;
	}
	return refreshedToken;
}
 
开发者ID:SergioColetto,项目名称:borabeber-api,代码行数:18,代码来源:JwtTokenUtil.java

示例12: refreshToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * 刷新token
 *
 * @param token
 * @return
 */
public String refreshToken ( String token ) {
	String refreshedToken;
	try {
		final Claims claims = getClaimsFromToken( token );
		claims.put( CLAIM_KEY_CREATED , new Date() );
		refreshedToken = generateToken( claims );
	} catch ( Exception e ) {
		refreshedToken = null;
	}
	return refreshedToken;
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:18,代码来源:JwtTokenUtil.java

示例13: createAccessJwtToken

import io.jsonwebtoken.Claims; //导入方法依赖的package包/类
/**
 * Factory method for issuing new JWT Tokens.
 * 
 * @param username
 * @param roles
 * @return
 */
public AccessJwtToken createAccessJwtToken(UserContext userContext) {
    if (StringUtils.isBlank(userContext.getTenantId())) 
        throw new IllegalArgumentException("Cannot create JWT Token without tenantId");

    if (StringUtils.isBlank(userContext.getOrgId())) 
        throw new IllegalArgumentException("Cannot create JWT Token without orgId");

    if (userContext.getAuthorities() == null || userContext.getAuthorities().isEmpty()) 
        throw new IllegalArgumentException("User doesn't have any privileges");

    Claims claims = Jwts.claims().setSubject(userContext.getOrgId());
    claims.put("scopes", userContext.getAuthorities().stream().map(s -> s.toString()).collect(Collectors.toList()));
    claims.put("tenant", userContext.getTenantId());

    DateTime currentTime = new DateTime();

    String token = Jwts.builder()
      .setClaims(claims)
      .setIssuer(settings.getTokenIssuer())
      .setIssuedAt(currentTime.toDate())
      .setExpiration(currentTime.plusMinutes(settings.getTokenExpirationTime()).toDate())
      .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey())
    .compact();

    return new AccessJwtToken(token, claims);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:34,代码来源:JwtTokenFactory.java


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