Class NimbusSignedTokenService

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.NimbusSignedTokenService
All Implemented Interfaces:
SignedTokenService

@Component public class NimbusSignedTokenService extends Object implements SignedTokenService
Issues and verifies purpose-bound tokens as JWTs signed with the active signing key and verified against the published keys. Verification checks the signature, the issuer, the timestamps and then the purpose; every failure is reported the same way, as an empty result.
  • Field Details

    • clock

      private final Clock clock
      Source of the current time.
    • issuer

      private final String issuer
      Issuer written to, and required of, every token.
    • encoder

      private final org.springframework.security.oauth2.jwt.JwtEncoder encoder
      Signs tokens.
    • decoder

      private final org.springframework.security.oauth2.jwt.JwtDecoder decoder
      Verifies tokens.
  • Constructor Details

    • NimbusSignedTokenService

      public NimbusSignedTokenService(org.springframework.security.oauth2.jwt.JwtEncoder encoder, com.nimbusds.jose.jwk.source.JWKSource<com.nimbusds.jose.proc.SecurityContext> jwkSource, Clock clock, @Value("${spring.security.oauth2.authorizationserver.issuer}") String issuer)
      Creates the service.
      Parameters:
      encoder - signs tokens with the active key.
      jwkSource - public keys the signatures are verified against.
      clock - source of the current time.
      issuer - issuer of the tokens (spring.security.oauth2.authorizationserver.issuer).
  • Method Details

    • issue

      public String issue(String subject, String purpose, Duration ttl)
      Issues a signed token.
      Specified by:
      issue in interface SignedTokenService
      Parameters:
      subject - who or what the token is about.
      purpose - what the token allows.
      ttl - how long the token stays valid.
      Returns:
      the compact token.
    • verify

      public Optional<String> verify(String token, String purpose)
      Verifies a token.
      Specified by:
      verify in interface SignedTokenService
      Parameters:
      token - the compact token.
      purpose - purpose the token must have been issued for.
      Returns:
      the subject, or an empty optional when the token is expired, tampered, malformed, from another issuer or issued for another purpose.