org.springframework.security.oauth2.jwt.Jwt.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(306)

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

Jwt.<init>介绍

[英]Constructs a Jwt using the provided parameters.
[中]使用提供的参数构造Jwt。

代码示例

代码示例来源:origin: spring-projects/spring-security

private Jwt createJwt(JWT parsedJwt, JWTClaimsSet jwtClaimsSet) {
  Map<String, Object> headers = new LinkedHashMap<>(parsedJwt.getHeader().toJSONObject());
  Map<String, Object> claims = this.claimSetConverter.convert(jwtClaimsSet.getClaims());
  Instant expiresAt = (Instant) claims.get(JwtClaimNames.EXP);
  Instant issuedAt = (Instant) claims.get(JwtClaimNames.IAT);
  return new Jwt(parsedJwt.getParsedString(), issuedAt, expiresAt, headers, claims);
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
  Map<String, Object> headers = new HashMap<>();
  headers.put("alg", JwsAlgorithms.RS256);
  return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
public void constructorWhenClaimsIsEmptyThenThrowIllegalArgumentException() {
  new Jwt(JWT_TOKEN_VALUE, Instant.ofEpochMilli(IAT_VALUE),
    Instant.ofEpochMilli(EXP_VALUE), HEADERS, Collections.emptyMap());
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

private Jwt jwt(Map<String, Object> claims) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("alg", JwsAlgorithms.RS256);

    return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims);
  }
}

代码示例来源:origin: spring-projects/spring-security

private ReactiveJwtDecoder getJwtDecoder() {
    return token -> {
      Map<String, Object> claims = new HashMap<>();
      claims.put(IdTokenClaimNames.SUB, "subject");
      claims.put(IdTokenClaimNames.ISS, "http://localhost/issuer");
      claims.put(IdTokenClaimNames.AUD, Collections.singletonList("client"));
      claims.put(IdTokenClaimNames.AZP, "client");
      Jwt jwt = new Jwt("id-token", Instant.now(), Instant.now().plusSeconds(3600),
          Collections.singletonMap("header1", "value1"), claims);
      return Mono.just(jwt);
    };
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
public void constructorWhenHeadersIsEmptyThenThrowIllegalArgumentException() {
  new Jwt(JWT_TOKEN_VALUE, Instant.ofEpochMilli(IAT_VALUE),
    Instant.ofEpochMilli(EXP_VALUE), Collections.emptyMap(), CLAIMS);
}

代码示例来源:origin: spring-projects/spring-security

private void setUpIdToken(Map<String, Object> claims, Instant issuedAt, Instant expiresAt) {
  Map<String, Object> headers = new HashMap<>();
  headers.put("alg", "RS256");
  Jwt idToken = new Jwt("id-token", issuedAt, expiresAt, headers, claims);
  JwtDecoder jwtDecoder = mock(JwtDecoder.class);
  when(jwtDecoder.decode(anyString())).thenReturn(idToken);
  this.authenticationProvider.setJwtDecoderFactory(registration -> jwtDecoder);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenIssuerMatchesThenReturnsSuccess() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN,
      MOCK_ISSUED_AT,
      MOCK_EXPIRES_AT,
      MOCK_HEADERS,
      Collections.singletonMap("iss", ISSUER));
  assertThat(this.validator.validate(jwt))
      .isEqualTo(OAuth2TokenValidatorResult.success());
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenIssuerMatchesAndIsNotAUriThenReturnsSuccess() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN,
      MOCK_ISSUED_AT,
      MOCK_EXPIRES_AT,
      MOCK_HEADERS,
      Collections.singletonMap(JwtClaimNames.ISS, "issuer"));
  JwtIssuerValidator validator = new JwtIssuerValidator("issuer");
  assertThat(validator.validate(jwt))
      .isEqualTo(OAuth2TokenValidatorResult.success());
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenNotBeforeIsValidAndExpiryIsNotSpecifiedThenReturnsSuccessfulResult() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN_VALUE,
      MOCK_ISSUED_AT,
      null,
      MOCK_HEADER,
      Collections.singletonMap(JwtClaimNames.NBF, Instant.MIN));
  JwtTimestampValidator jwtValidator = new JwtTimestampValidator();
  assertThat(jwtValidator.validate(jwt).hasErrors()).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenNeitherExpiryNorNotBeforeIsSpecifiedThenReturnsSuccessfulResult() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN_VALUE,
      MOCK_ISSUED_AT,
      null,
      MOCK_HEADER,
      MOCK_CLAIM_SET);
  JwtTimestampValidator jwtValidator = new JwtTimestampValidator();
  assertThat(jwtValidator.validate(jwt).hasErrors()).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenIssuerMismatchesThenReturnsError() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN,
      MOCK_ISSUED_AT,
      MOCK_EXPIRES_AT,
      MOCK_HEADERS,
      Collections.singletonMap(JwtClaimNames.ISS, "https://other"));
  OAuth2TokenValidatorResult result = this.validator.validate(jwt);
  assertThat(result.getErrors()).isNotEmpty();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenExpiryIsValidAndNotBeforeIsNotSpecifiedThenReturnsSuccessfulResult() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN_VALUE,
      MOCK_ISSUED_AT,
      Instant.MAX,
      MOCK_HEADER,
      MOCK_CLAIM_SET);
  JwtTimestampValidator jwtValidator = new JwtTimestampValidator();
  assertThat(jwtValidator.validate(jwt).hasErrors()).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void validateWhenJwtHasNoIssuerThenReturnsError() {
  Jwt jwt = new Jwt(
      MOCK_TOKEN,
      MOCK_ISSUED_AT,
      MOCK_EXPIRES_AT,
      MOCK_HEADERS,
      Collections.singletonMap(JwtClaimNames.AUD, "https://aud"));
  OAuth2TokenValidatorResult result = this.validator.validate(jwt);
  assertThat(result.getErrors()).isNotEmpty();
}

代码示例来源:origin: spring-projects/spring-security

private Collection<OAuth2Error> validateIdToken() {
    Jwt idToken = new Jwt("token123", this.issuedAt, this.expiresAt, this.headers, this.claims);
    OidcIdTokenValidator validator = new OidcIdTokenValidator(this.registration.build());
    validator.setClockSkew(this.clockSkew);
    return validator.validate(idToken).getErrors();
  }
}

相关文章