Class NimbusJwtEncoder
java.lang.Object
org.springframework.security.oauth2.jwt.NimbusJwtEncoder
- All Implemented Interfaces:
- JwtEncoder
An implementation of a 
JwtEncoder that encodes a JSON Web Token (JWT) using the
 JSON Web Signature (JWS) Compact Serialization format. The private/secret key used for
 signing the JWS is supplied by the com.nimbusds.jose.jwk.source.JWKSource
 provided via the constructor.
 NOTE: This implementation uses the Nimbus JOSE + JWT SDK.
- Since:
- 5.6
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classstatic final classA builder for creatingNimbusJwtEncoderinstances configured with aKeyPair.static final classA builder for creatingNimbusJwtEncoderinstances configured with aSecretKey.
- 
Constructor SummaryConstructorsConstructorDescriptionNimbusJwtEncoder(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> jwkSource) Constructs aNimbusJwtEncoderusing the provided parameters.
- 
Method SummaryModifier and TypeMethodDescriptionencode(JwtEncoderParameters parameters) Encode the JWT to its compact claims representation format.voidsetJwkSelector(org.springframework.core.convert.converter.Converter<List<com.nimbusds.jose.jwk.JWK>, com.nimbusds.jose.jwk.JWK> jwkSelector) Use this strategy to reduce the list of matching JWKs when there is more than one.withKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) Creates a builder for constructing aNimbusJwtEncoderusing the providedwithKeyPair(RSAPublicKey publicKey, RSAPrivateKey privateKey) Creates a builder for constructing aNimbusJwtEncoderusing the providedwithSecretKey(SecretKey secretKey) Creates a builder for constructing aNimbusJwtEncoderusing the provided
- 
Constructor Details- 
NimbusJwtEncoderpublic NimbusJwtEncoder(com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> jwkSource) Constructs aNimbusJwtEncoderusing the provided parameters.- Parameters:
- jwkSource- the- com.nimbusds.jose.jwk.source.JWKSource
 
 
- 
- 
Method Details- 
setJwkSelectorpublic void setJwkSelector(org.springframework.core.convert.converter.Converter<List<com.nimbusds.jose.jwk.JWK>, com.nimbusds.jose.jwk.JWK> jwkSelector) Use this strategy to reduce the list of matching JWKs when there is more than one.For example, you can call setJwkSelector(List::getFirst)in order to have this encoder select the first match.By default, the class with throw an exception. - Since:
- 6.5
 
- 
encodeDescription copied from interface:JwtEncoderEncode the JWT to its compact claims representation format.- Specified by:
- encodein interface- JwtEncoder
- Parameters:
- parameters- the parameters containing the JOSE header and JWT Claims Set
- Returns:
- a Jwt
- Throws:
- JwtEncodingException- if an error occurs while attempting to encode the JWT
 
- 
withKeyPairpublic static NimbusJwtEncoder.RsaKeyPairJwtEncoderBuilder withKeyPair(RSAPublicKey publicKey, RSAPrivateKey privateKey) Creates a builder for constructing aNimbusJwtEncoderusing the provided- Parameters:
- publicKey- the- RSAPublicKeyand @Param privateKey the- RSAPrivateKeyto use for signing JWTs
- Returns:
- a NimbusJwtEncoder.RsaKeyPairJwtEncoderBuilder
- Since:
- 7.0
 
- 
withKeyPairpublic static NimbusJwtEncoder.EcKeyPairJwtEncoderBuilder withKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) Creates a builder for constructing aNimbusJwtEncoderusing the provided- Parameters:
- publicKey- the- ECPublicKeyand @param privateKey the- ECPrivateKeyto use for signing JWTs
- Returns:
- a NimbusJwtEncoder.EcKeyPairJwtEncoderBuilder
- Since:
- 7.0
 
- 
withSecretKeyCreates a builder for constructing aNimbusJwtEncoderusing the provided- Parameters:
- secretKey-
- Returns:
- a NimbusJwtEncoder.SecretKeyJwtEncoderBuilderfor configuring theJWK
- Since:
- 7.0
 
 
-