java_src/src/main/java/com/google/crypto/tink/jwt/JwtValidator.java
/**
   * Validates that all claims in this validator are also present in {@code target}.
   * @throws JwtInvalidException when {@code target} contains an invalid claim or header
   */
Validates that all claims in this validator are also present in  target.
@throws JwtInvalidException when  target contains an invalid claim or header
Validates that all claims in this validator are also present in target . @throws JwtInvalidException when target contains an invalid claim or header
VerifiedJwt validate(RawJwt target) throws JwtInvalidException {
    validateTimestampClaims(target);
    if (this.expectedTypeHeader.isPresent()) {
      if (!target.hasTypeHeader()) {
        throw new JwtInvalidException(
            String.format(
                "invalid JWT; missing expected type header %s.", this.expectedTypeHeader.get()));
      }
      if (!target.getTypeHeader().equals(this.expectedTypeHeader.get())) {
        throw new JwtInvalidException(
            String.format(
                "invalid JWT; expected type header %s, but got %s",
                this.expectedTypeHeader.get(), target.getTypeHeader()));
      }
    } else {
      if (target.hasTypeHeader() && !this.ignoreTypeHeader) {
        throw new JwtInvalidException("invalid JWT; token has type header set, but validator not.");
      }
    }
    if (this.expectedIssuer.isPresent()) {
      if (!target.hasIssuer()) {
        throw new JwtInvalidException(
            String.format("invalid JWT; missing expected issuer %s.", this.expectedIssuer.get()));
      }
      if (!target.getIssuer().equals(this.expectedIssuer.get())) {
        throw new JwtInvalidException(
            String.format(
                "invalid JWT; expected issuer %s, but got %s",
                this.expectedIssuer.get(), target.getIssuer()));
      }
    } else {
      if (target.hasIssuer() && !this.ignoreIssuer) {
        throw new JwtInvalidException("invalid JWT; token has issuer set, but validator not.");
      }
    }
    if (this.expectedSubject.isPresent()) {
      if (!target.hasSubject()) {
        throw new JwtInvalidException(
            String.format("invalid JWT; missing expected subject %s.", this.expectedSubject.get()));
      }
      if (!target.getSubject().equals(this.expectedSubject.get())) {
        throw new JwtInvalidException(
            String.format(
                "invalid JWT; expected subject %s, but got %s",
                this.expectedSubject.get(), target.getSubject()));
      }
    } else {
      if (target.hasSubject() && !this.ignoreSubject) {
        throw new JwtInvalidException("invalid JWT; token has subject set, but validator not.");
      }
    }
    if (this.expectedAudience.isPresent()) {
      if (!target.hasAudiences() || !target.getAudiences().contains(this.expectedAudience.get())) {
        throw new JwtInvalidException(
            String.format(
                "invalid JWT; missing expected audience %s.", this.expectedAudience.get()));
      }
    } else {
      if (target.hasAudiences() && !this.ignoreAudiences) {
        throw new JwtInvalidException("invalid JWT; token has audience set, but validator not.");
      }
    }
    return new VerifiedJwt(target);
  }
VerifiedJwt validate ( RawJwt target ) throws JwtInvalidException { validateTimestampClaims ( target ) ; if ( this . expectedTypeHeader . isPresent ( ) ) { if ( ! target . hasTypeHeader ( ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; missing expected type header %s." , this . expectedTypeHeader . get ( ) ) ) ; } if ( ! target . getTypeHeader ( ) . equals ( this . expectedTypeHeader . get ( ) ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; expected type header %s, but got %s" , this . expectedTypeHeader . get ( ) , target . getTypeHeader ( ) ) ) ; } } else { if ( target . hasTypeHeader ( ) && ! this . ignoreTypeHeader ) { throw new JwtInvalidException ( "invalid JWT; token has type header set, but validator not." ) ; } } if ( this . expectedIssuer . isPresent ( ) ) { if ( ! target . hasIssuer ( ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; missing expected issuer %s." , this . expectedIssuer . get ( ) ) ) ; } if ( ! target . getIssuer ( ) . equals ( this . expectedIssuer . get ( ) ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; expected issuer %s, but got %s" , this . expectedIssuer . get ( ) , target . getIssuer ( ) ) ) ; } } else { if ( target . hasIssuer ( ) && ! this . ignoreIssuer ) { throw new JwtInvalidException ( "invalid JWT; token has issuer set, but validator not." ) ; } } if ( this . expectedSubject . isPresent ( ) ) { if ( ! target . hasSubject ( ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; missing expected subject %s." , this . expectedSubject . get ( ) ) ) ; } if ( ! target . getSubject ( ) . equals ( this . expectedSubject . get ( ) ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; expected subject %s, but got %s" , this . expectedSubject . get ( ) , target . getSubject ( ) ) ) ; } } else { if ( target . hasSubject ( ) && ! this . ignoreSubject ) { throw new JwtInvalidException ( "invalid JWT; token has subject set, but validator not." ) ; } } if ( this . expectedAudience . isPresent ( ) ) { if ( ! target . hasAudiences ( ) || ! target . getAudiences ( ) . contains ( this . expectedAudience . get ( ) ) ) { throw new JwtInvalidException ( String . format ( "invalid JWT; missing expected audience %s." , this . expectedAudience . get ( ) ) ) ; } } else { if ( target . hasAudiences ( ) && ! this . ignoreAudiences ) { throw new JwtInvalidException ( "invalid JWT; token has audience set, but validator not." ) ; } } return new VerifiedJwt ( target ) ; }
Validates that all claims in this validator are also present in {@code target}.
Validates that all claims in this validator are also present in { @code target } .