io.jsonwebtoken.Claims.entrySet()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中io.jsonwebtoken.Claims.entrySet()方法的一些代码示例,展示了Claims.entrySet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Claims.entrySet()方法的具体详情如下:
包路径:io.jsonwebtoken.Claims
类名称:Claims
方法名:entrySet

Claims.entrySet介绍

暂无

代码示例

代码示例来源:origin: jloisel/securing-rest-api-spring-security

private static Map<String, String> parseClaims(final Supplier<Claims> toClaims) {
 try {
  final Claims claims = toClaims.get();
  final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  for (final Map.Entry<String, Object> e: claims.entrySet()) {
   builder.put(e.getKey(), String.valueOf(e.getValue()));
  }
  return builder.build();
 } catch (final IllegalArgumentException | JwtException e) {
  return ImmutableMap.of();
 }
}

代码示例来源:origin: getheimdall/heimdall

/**
 * Generate a new {@link TokenOAuth} from other token valid.
 *
 * @param token            The token
 * @param privateKey       The privateKey to be encoded
 * @param timeAccessToken  Time to expire accessToken
 * @param timeRefreshToken Time to expire refreshToken
 * @return The new {@link TokenOAuth}
 */
private TokenOAuth generateTokenOAuthFromOtherToken(String token, String privateKey, int timeAccessToken, int timeRefreshToken) throws HeimdallException {
  String secretKey = JwtUtils.encodePrivateKey(privateKey);
  Claims claimsFromTheToken = JwtUtils.getClaimsFromTheToken(token, secretKey);
  Map<String, Object> claims = claimsFromTheToken.entrySet().stream()
      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
  return JwtUtils.generateTokenOAuth(privateKey, timeAccessToken, timeRefreshToken, claims);
}

代码示例来源:origin: getheimdall/heimdall

/**
 * Generate a new {@link TokenImplicit} from other token valid.
 *
 * @param token      The token
 * @param privateKey The privateKey to be encoded
 * @return The new {@link TokenImplicit}
 */
public TokenImplicit generateTokenImplicitFromOtherToken(String token, String privateKey, int timeAccessToken) throws HeimdallException {
  String secretKey = JwtUtils.encodePrivateKey(privateKey);
  Claims claimsFromTheToken = JwtUtils.getClaimsFromTheToken(token, secretKey);
  Map<String, Object> claims = claimsFromTheToken.entrySet().stream()
      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
  return JwtUtils.generateTokenImplicit(privateKey, timeAccessToken, claims);
}

代码示例来源:origin: Jasig/uPortal

public Preferences parsePreferences(String preferencesToken) {

    final Jws<Claims> claims = parseEncryptedToken(preferencesToken, Preferences.class);

    final String username = claims.getBody().getSubject();

    final Map<String, List<String>> preferencesMap = new HashMap<>();
    for (Map.Entry<String, Object> y : claims.getBody().entrySet()) {
      final String key = y.getKey();
      if (JwtClaims.forName(key) != null) {
        // Skip these;  we handle these differently
        continue;
      }

      if (y.getValue() instanceof List) {
        @SuppressWarnings("unchecked")
        final List<String> values = (List<String>) y.getValue();
        preferencesMap.put(key, values);
      } else {
        logger.warn("Unexpected claim '{}' was not a List;  skipping", key);
      }
    }

    Preferences rslt = new Preferences(preferencesToken, preferencesMap);
    logger.debug("Produced the following Preferences for user '{}':  {}", username, rslt);
    return rslt;
  }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

String refresh(Claims token, int expirationTimeInSeconds) {
 checkIsStarted();
 long now = system2.now();
 JwtBuilder jwtBuilder = Jwts.builder();
 for (Map.Entry<String, Object> entry : token.entrySet()) {
  jwtBuilder.claim(entry.getKey(), entry.getValue());
 }
 jwtBuilder.setExpiration(new Date(now + expirationTimeInSeconds * 1000))
  .signWith(SIGNATURE_ALGORITHM, secretKey);
 return jwtBuilder.compact();
}

代码示例来源:origin: pravega/pravega

@Override
public boolean verifyToken(String resource, String token, AuthHandler.Permissions expectedLevel) {
  if (config.isAuthEnabled()) {
    try {
      Jws<Claims> claims = Jwts.parser()
                   .setSigningKey(config.getTokenSigningKey().getBytes())
                   .parseClaimsJws(token);
      Optional<Map.Entry<String, Object>> matchingClaim = claims.getBody().entrySet().stream().filter(entry ->
          validateEntry(entry, resource)
          && expectedLevel.compareTo(AuthHandler.Permissions.valueOf(entry.getValue().toString()))
          <= 0).findFirst();
      if (matchingClaim.isPresent()) {
        log.debug("Found a matching claim {} for resource {}", matchingClaim, resource);
        return true;
      } else {
        log.debug("Could not find a matching claim {} for resource {} in claims {}",
            expectedLevel, resource, claims);
        return false;
      }
    } catch (JwtException e) {
      log.warn("Claim verification failed for resource {} because {}", resource, e);
      return false;
    }
  } else {
    return true;
  }
}

代码示例来源:origin: Jasig/uPortal

for (Map.Entry<String, Object> y : claims.getBody().entrySet()) {
  final String key = y.getKey();
  if (JwtClaims.forName(key) != null) {

相关文章