Package dev.paseto.jpaseto
Interface PasetoParserBuilder
-
public interface PasetoParserBuilderA builder for constructing aPasetoParser. The constructed parser will work for multiple versions/purpose token when configured.Typical usage:
Pasetos.parserBuilder() .setSharedSecret(...) // ... .requireIssuer("https://example.com/issuer) .build()- Since:
- 0.1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description PasetoParserbuild()default PasetoParserBuilderrequire(java.lang.String claimName, java.lang.Object value)Ensures that the specifiedclaimNameexists in the parsed Paseto.PasetoParserBuilderrequire(java.lang.String claimName, java.util.function.Predicate<java.lang.Object> value)default PasetoParserBuilderrequireAudience(java.lang.String aud)Ensures that the specifiedaudexists in the parsed Paseto.default PasetoParserBuilderrequireExpiration(java.time.Instant exp)Ensures that the specifiedexpexists in the parsed Paseto.PasetoParserBuilderrequireFooter(java.lang.String claimName, java.util.function.Predicate<java.lang.Object> value)default PasetoParserBuilderrequireIssuedAt(java.time.Instant iat)Ensures that the specifiediatexists in the parsed Paseto.default PasetoParserBuilderrequireIssuer(java.lang.String iss)Ensures that the specifiedissexists in the parsed Paseto.default PasetoParserBuilderrequireKeyId(java.lang.String kid)Ensures that the specifiedkidexists in the parsed Paseto footer.default PasetoParserBuilderrequireNotBefore(java.time.Instant nbf)Ensures that the specifiednbfexists in the parsed Paseto.default PasetoParserBuilderrequireSubject(java.lang.String sub)Ensures that the specifiedsubexists in the parsed Paseto.default PasetoParserBuilderrequireTokenId(java.lang.String jti)Ensures that the specifiedjtiexists in the parsed Paseto.PasetoParserBuildersetAllowedClockSkew(java.time.Duration allowedClockSkew)Sets the amount of clock skew tolerate when verifying the local time against theexpandnbfclaims.PasetoParserBuildersetClock(java.time.Clock clock)Sets theClockthat determines the timestamp to use when validating the parsed Paseto.PasetoParserBuildersetDeserializer(Deserializer<java.util.Map<java.lang.String,java.lang.Object>> deserializer)PasetoParserBuildersetKeyResolver(KeyResolver keyResolver)Sets theKeyResolverused to acquire thesigning keythat should be used to verify a paseto tokens's signature.PasetoParserBuildersetPublicKey(java.security.PublicKey publicKey)default PasetoParserBuildersetSharedSecret(byte[] sharedSecret)PasetoParserBuildersetSharedSecret(javax.crypto.SecretKey sharedSecret)
-
-
-
Method Detail
-
setKeyResolver
PasetoParserBuilder setKeyResolver(KeyResolver keyResolver)
Sets theKeyResolverused to acquire thesigning keythat should be used to verify a paseto tokens's signature.Specifying a
SigningKeyResolveris necessary when the signing key is not already known before parsing the token and the footer must be inspected first to determine how to look up the signing key. Once returned by the resolver, the PasetoParser will then verify the paseto token's signature with the returned key. For example:Paseto token = Pasetos.parserBuilder().setSigningKeyResolver(new KeyResolverAdapter() { @Override public byte[] resolvePublicKeyBytes(Paseto paseto) { //inspect the header or claims, lookup and return the signing key return getPublicKeyBytes(paseto); //implement me }}) .build() .parse(tokenString);A
SigningKeyResolveris invoked once during parsing before the signature is verified.This method should only be used if a signing key is not provided by the other
To construct a PasetoParser use the corresponding builder viasetSigningKey*builder methods.Pasetos.parserBuilder(). This will construct an immutablePasetoParser.- Parameters:
keyResolver- the signing key resolver used to retrieve the signing key.- Returns:
- the parser builder for method chaining.
-
setPublicKey
PasetoParserBuilder setPublicKey(java.security.PublicKey publicKey)
-
setSharedSecret
default PasetoParserBuilder setSharedSecret(byte[] sharedSecret)
-
setSharedSecret
PasetoParserBuilder setSharedSecret(javax.crypto.SecretKey sharedSecret)
-
setDeserializer
PasetoParserBuilder setDeserializer(Deserializer<java.util.Map<java.lang.String,java.lang.Object>> deserializer)
-
build
PasetoParser build()
-
requireIssuer
default PasetoParserBuilder requireIssuer(java.lang.String iss)
Ensures that the specifiedissexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
iss- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireSubject
default PasetoParserBuilder requireSubject(java.lang.String sub)
Ensures that the specifiedsubexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
sub- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireAudience
default PasetoParserBuilder requireAudience(java.lang.String aud)
Ensures that the specifiedaudexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
aud- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireExpiration
default PasetoParserBuilder requireExpiration(java.time.Instant exp)
Ensures that the specifiedexpexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
exp- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireNotBefore
default PasetoParserBuilder requireNotBefore(java.time.Instant nbf)
Ensures that the specifiednbfexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
nbf- expected claim value- Returns:
- the parser builder for method chaining
- See Also:
MissingClaimException,IncorrectClaimException
-
requireIssuedAt
default PasetoParserBuilder requireIssuedAt(java.time.Instant iat)
Ensures that the specifiediatexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
iat- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireTokenId
default PasetoParserBuilder requireTokenId(java.lang.String jti)
Ensures that the specifiedjtiexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
jti- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
requireKeyId
default PasetoParserBuilder requireKeyId(java.lang.String kid)
Ensures that the specifiedkidexists in the parsed Paseto footer. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
kid- expected claim value- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
require
default PasetoParserBuilder require(java.lang.String claimName, java.lang.Object value)
Ensures that the specifiedclaimNameexists in the parsed Paseto. If missing or if the parsed value does not equal the specified value, an exception will be thrown indicating that the Paseto is invalid and may not be used.- Parameters:
claimName-value-- Returns:
- the parser builder for method chaining.
- See Also:
MissingClaimException,IncorrectClaimException
-
require
PasetoParserBuilder require(java.lang.String claimName, java.util.function.Predicate<java.lang.Object> value)
-
requireFooter
PasetoParserBuilder requireFooter(java.lang.String claimName, java.util.function.Predicate<java.lang.Object> value)
-
setClock
PasetoParserBuilder setClock(java.time.Clock clock)
Sets theClockthat determines the timestamp to use when validating the parsed Paseto. The parser uses a default Clock implementation that simply returnsnew Date()when called.- Parameters:
clock- aClockobject to return the timestamp to use when validating the parsed Paseto.- Returns:
- the parser builder for method chaining.
-
setAllowedClockSkew
PasetoParserBuilder setAllowedClockSkew(java.time.Duration allowedClockSkew)
Sets the amount of clock skew tolerate when verifying the local time against theexpandnbfclaims.- Parameters:
allowedClockSkew- the duration to tolerate for clock skew when verifyingexpornbfclaims.- Returns:
- the parser builder for method chaining.
-
-