com.auth0.jwt.interfaces.Verification.acceptLeeway()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(200)

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

Verification.acceptLeeway介绍

暂无

代码示例

代码示例来源:origin: line/armeria

JwtBasedSamlRequestIdManager(String issuer, Algorithm algorithm,
               int validSeconds, int leewaySeconds) {
  this.issuer = requireNonNull(issuer, "issuer");
  this.algorithm = requireNonNull(algorithm, "algorithm");
  this.validSeconds = validSeconds;
  this.leewaySeconds = leewaySeconds;
  checkArgument(validSeconds > 0,
         "invalid valid duration: " + validSeconds + " (expected: > 0)");
  checkArgument(leewaySeconds >= 0,
         "invalid leeway duration:" + leewaySeconds + " (expected: >= 0)");
  un1 = getUniquifierPrefix();
  verifier = JWT.require(algorithm)
         .withIssuer(issuer)
         .acceptLeeway(leewaySeconds)
         .build();
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldThrowOnNegativeCustomLeeway() throws Exception {
  exception.expect(IllegalArgumentException.class);
  exception.expectMessage("Leeway value can't be negative.");
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier.init(algorithm)
      .acceptLeeway(-1);
}

代码示例来源:origin: auth0/java-jwt

@SuppressWarnings("RedundantCast")
@Test
public void shouldAddCustomLeewayToDateClaims() throws Exception {
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier verifier = JWTVerifier.init(algorithm)
      .acceptLeeway(1234L)
      .build();
  assertThat(verifier.claims, is(notNullValue()));
  assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}

代码示例来源:origin: auth0/java-jwt

@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultNotBeforeLeeway() throws Exception {
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier verifier = JWTVerifier.init(algorithm)
      .acceptLeeway(1234L)
      .acceptNotBefore(9999L)
      .build();
  assertThat(verifier.claims, is(notNullValue()));
  assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("nbf", (Object) 9999L));
}

代码示例来源:origin: auth0/java-jwt

@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultExpiresAtLeeway() throws Exception {
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier verifier = JWTVerifier.init(algorithm)
      .acceptLeeway(1234L)
      .acceptExpiresAt(9999L)
      .build();
  assertThat(verifier.claims, is(notNullValue()));
  assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("exp", (Object) 9999L));
  assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}

代码示例来源:origin: auth0/java-jwt

@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultIssuedAtLeeway() throws Exception {
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier verifier = JWTVerifier.init(algorithm)
      .acceptLeeway(1234L)
      .acceptIssuedAt(9999L)
      .build();
  assertThat(verifier.claims, is(notNullValue()));
  assertThat(verifier.claims, hasEntry("iat", (Object) 9999L));
  assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
  assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}

代码示例来源:origin: chengdedeng/waf

public Map<String, String> getTokenPlayload(String token) {
  Map map = new HashMap();
  try {
    Algorithm algorithmHS = buildHMAC256();
    //When the token is not valid , this method will throw SignatureVerificationException
    DecodedJWT jwt = JWT.require(algorithmHS).acceptLeeway(3).build().verify(token);
    Map<String, Claim> claimMap = jwt.getClaims();
    if (Optional.fromNullable(claimMap).isPresent()) {
      claimMap.entrySet().stream().forEach(entry -> {
        map.put(entry.getKey(), entry.getValue().as(String.class));
      });
    }
  } catch (Exception e) {
    logger.error(ExceptionUtils.getFullStackTrace(e));
    throw new RuntimeException(e);
  }
  return map;
}

代码示例来源:origin: com.charlyghislain.authenticator/authenticator-ejb

@Produces
@Dependent
public JWTVerifier produceJwtVerifier() {
  Algorithm algorithm = Algorithm.RSA256(defaultRsaKeyProvider);
  return JWT.require(algorithm)
      .withIssuer(tokenIssuer)
      .acceptLeeway(tokenValidationLeewaySeconds)
      .build();
}

代码示例来源:origin: chengdedeng/waf

public boolean verifyToken(String token) {
  try {
    Algorithm algorithmHS = buildHMAC256();
    //When the token is not valid , this method will throw SignatureVerificationException
    JWT.require(algorithmHS).acceptLeeway(3).build().verify(token);
    return true;
  } catch (TokenExpiredException e) {
    logger.info("Token:[{}] is expired", token);
  } catch (Exception e) {
    logger.warn("Token:[{}] is illegal", token);
  }
  return false;
}

代码示例来源:origin: com.linecorp.armeria/armeria-saml

JwtBasedSamlRequestIdManager(String issuer, Algorithm algorithm,
               int validSeconds, int leewaySeconds) {
  this.issuer = requireNonNull(issuer, "issuer");
  this.algorithm = requireNonNull(algorithm, "algorithm");
  this.validSeconds = validSeconds;
  this.leewaySeconds = leewaySeconds;
  checkArgument(validSeconds > 0,
         "invalid valid duration: " + validSeconds + " (expected: > 0)");
  checkArgument(leewaySeconds >= 0,
         "invalid leeway duration:" + leewaySeconds + " (expected: >= 0)");
  un1 = getUniquifierPrefix();
  verifier = JWT.require(algorithm)
         .withIssuer(issuer)
         .acceptLeeway(leewaySeconds)
         .build();
}

代码示例来源:origin: org.mycore/mycore-restapi

public static void validate(String token) throws JWTVerificationException {
    JWT.require(MCRJWTUtil.getJWTAlgorithm())
      .withAudience(AUDIENCE)
      .acceptLeeway(0)
      .build().verify(token);
  }
}

相关文章