java.lang.Object
com.irurueta.authserver.serviceclient.infrastructure.resourceserver.PrincipalMapper

@Component public class PrincipalMapper extends Object
Builds the principals the authorized client manager caches tokens under. There is no security context in the service client, so every call names its principal.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Bytes of the digest of the subject token kept in the name.
    private static final String
    Key of the principal of the service client itself.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    Digests a token.
    org.springframework.security.core.Authentication
    Builds the principal of the service client, which the client credentials token is cached under.
    private static String
    Reads the sub claim of a JWT without verifying it.
    org.springframework.security.core.Authentication
    user(String subjectToken)
    Builds the principal of a user whose token is exchanged.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SERVICE_CLIENT_KEY

      private static final String SERVICE_CLIENT_KEY
      Key of the principal of the service client itself.
      See Also:
    • DIGEST_BYTES

      private static final int DIGEST_BYTES
      Bytes of the digest of the subject token kept in the name.
      See Also:
  • Constructor Details

    • PrincipalMapper

      public PrincipalMapper()
  • Method Details

    • serviceClient

      public org.springframework.security.core.Authentication serviceClient(String clientId)
      Builds the principal of the service client, which the client credentials token is cached under.
      Parameters:
      clientId - identifier of the client, used as the name.
      Returns:
      the principal.
    • user

      public org.springframework.security.core.Authentication user(String subjectToken)
      Builds the principal of a user whose token is exchanged. Its name is the sub claim of the token when it is a readable JWT, followed by a digest of the whole token: the claim is not verified here (the authorization server does that), so the digest keeps two different tokens from ever sharing a cached exchange.
      Parameters:
      subjectToken - access token of the user.
      Returns:
      the principal, whose principal object is the token, as the exchange provider expects.
    • subjectOf

      private static String subjectOf(String token)
      Reads the sub claim of a JWT without verifying it.
      Parameters:
      token - the token.
      Returns:
      the claim, or "user" when the token is opaque or has no subject.
    • digestOf

      private static String digestOf(String token)
      Digests a token.
      Parameters:
      token - the token.
      Returns:
      the first bytes of its SHA-256 digest, in hexadecimal.