Class EntraIssuerValidator

java.lang.Object
com.irurueta.authserver.authorization.api.web.social.EntraIssuerValidator
All Implemented Interfaces:
org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>

public class EntraIssuerValidator extends Object implements org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>
Validates the issuer of an ID token of Microsoft Entra ID in a multi-tenant application.

Such a token is issued by the tenant its user belongs to (https://login.microsoftonline.com/{tid}/v2.0) while the discovery document of the common endpoint advertises a {tenantid} placeholder as the issuer, so the framework's check against one fixed issuer would reject every token. This validator takes the tenant from the token's own tid claim, requires the iss to be exactly that tenant's issuer, and, when a list is given, requires the tenant to be one of the permitted ones. The signature has already been verified against Entra's published keys by then, so the tid is the one Entra put in the token.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Error code of a refused token.
    private final List<String>
    Tenants accepted; empty accepts any tenant.
    (package private) static final String
    Claim that holds the id of the tenant the user belongs to.
  • Constructor Summary

    Constructors
    Constructor
    Description
    EntraIssuerValidator(List<String> permittedTenants)
    Creates the validator.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static org.springframework.security.oauth2.core.OAuth2TokenValidatorResult
    failure(String description)
    Builds a failed result.
    org.springframework.security.oauth2.core.OAuth2TokenValidatorResult
    validate(org.springframework.security.oauth2.jwt.Jwt token)
    Validates the issuer of a token.

    Methods inherited from class java.lang.Object

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

    • TENANT_CLAIM

      static final String TENANT_CLAIM
      Claim that holds the id of the tenant the user belongs to.
      See Also:
    • INVALID_TOKEN

      static final String INVALID_TOKEN
      Error code of a refused token.
      See Also:
    • permittedTenants

      private final List<String> permittedTenants
      Tenants accepted; empty accepts any tenant.
  • Constructor Details

    • EntraIssuerValidator

      public EntraIssuerValidator(List<String> permittedTenants)
      Creates the validator.
      Parameters:
      permittedTenants - ids of the tenants accepted, compared ignoring case; empty accepts any tenant.
  • Method Details

    • validate

      public org.springframework.security.oauth2.core.OAuth2TokenValidatorResult validate(org.springframework.security.oauth2.jwt.Jwt token)
      Validates the issuer of a token.
      Specified by:
      validate in interface org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>
      Parameters:
      token - the ID token, already decoded and signature-verified.
      Returns:
      a success, or a failure when the token has no tenant, its issuer is not the issuer of its tenant, or its tenant is not permitted.
    • failure

      private static org.springframework.security.oauth2.core.OAuth2TokenValidatorResult failure(String description)
      Builds a failed result.
      Parameters:
      description - the reason.
      Returns:
      the result.