Class FederatedUserMapper

java.lang.Object
com.irurueta.authserver.authorization.api.web.social.FederatedUserMapper

@Component public class FederatedUserMapper extends Object
Maps the user an external provider described onto the user the rest of the server sees: the principal of the session, whose name is the local account's username (so it is the sub of the issued tokens, as it is for every other way of signing in), whose authorities are the account's own, and which still carries the claims of the provider (the amr among them).

The principal is stored with the authorization and read back at the token request through a polymorphic allow-list, so every claim is normalised to a JSON-friendly value first: lists are mutable lists (an immutable one is not on the allow-list), instants are epoch seconds and URLs are strings.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Claim of the upstream authentication methods (RFC 8176).
    (package private) static final String
    Claim that says that the provider verified the e-mail address (the standard OIDC one).
    (package private) static final String
    Optional claim of Microsoft Entra ID that says that the owner of the e-mail domain verified the address.
    static final String
    Name of the attribute that holds the username of the local account.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    emailVerified(org.springframework.security.oauth2.core.oidc.user.OidcUser user)
    Tells whether the provider vouches for the e-mail address of an OpenID Connect user.
    private Object
    safe(Object value)
    Normalises a value.
    private Map<String,Object>
    Normalises a claim map.
    org.springframework.security.oauth2.core.oidc.user.OidcUser
    toLocalUser(org.springframework.security.oauth2.core.oidc.user.OidcUser upstream, String username, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
    Maps an OpenID Connect user.
    org.springframework.security.oauth2.core.user.OAuth2User
    toLocalUser(org.springframework.security.oauth2.core.user.OAuth2User upstream, Collection<String> kept, String email, String username, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
    Maps an OAuth 2.0 user.
    upstreamAmr(org.springframework.security.oauth2.core.user.OAuth2User user)
    Reads the amr values the provider reported.

    Methods inherited from class java.lang.Object

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

    • LOCAL_USERNAME_ATTRIBUTE

      public static final String LOCAL_USERNAME_ATTRIBUTE
      Name of the attribute that holds the username of the local account.
      See Also:
    • AMR_CLAIM

      public static final String AMR_CLAIM
      Claim of the upstream authentication methods (RFC 8176).
      See Also:
    • EMAIL_VERIFIED_CLAIM

      static final String EMAIL_VERIFIED_CLAIM
      Claim that says that the provider verified the e-mail address (the standard OIDC one).
      See Also:
    • ENTRA_DOMAIN_VERIFIED_CLAIM

      static final String ENTRA_DOMAIN_VERIFIED_CLAIM
      Optional claim of Microsoft Entra ID that says that the owner of the e-mail domain verified the address.
      See Also:
  • Constructor Details

    • FederatedUserMapper

      public FederatedUserMapper()
  • Method Details

    • toLocalUser

      public org.springframework.security.oauth2.core.oidc.user.OidcUser toLocalUser(org.springframework.security.oauth2.core.oidc.user.OidcUser upstream, String username, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
      Maps an OpenID Connect user.
      Parameters:
      upstream - the user the provider described.
      username - username of the local account.
      authorities - authorities of the local account.
      Returns:
      a user named after the account, with the claims of the provider.
    • toLocalUser

      public org.springframework.security.oauth2.core.user.OAuth2User toLocalUser(org.springframework.security.oauth2.core.user.OAuth2User upstream, Collection<String> kept, String email, String username, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
      Maps an OAuth 2.0 user. Only the attributes in kept are carried over (the profile of such a provider may hold nested objects that have no business in the session).
      Parameters:
      upstream - the user the provider described.
      kept - names of the attributes to keep.
      email - verified e-mail address, or null; it replaces the provider's email.
      username - username of the local account.
      authorities - authorities of the local account.
      Returns:
      a user named after the account.
    • emailVerified

      public boolean emailVerified(org.springframework.security.oauth2.core.oidc.user.OidcUser user)
      Tells whether the provider vouches for the e-mail address of an OpenID Connect user. The standard email_verified claim does (a string "true" too, as Apple sends it); Microsoft Entra ID has no such claim in its default tokens, so its optional xms_edov claim counts, and without either the address is not verified: Entra's email can be set by a tenant administrator to any value.
      Parameters:
      user - the user the provider described.
      Returns:
      true when the address is verified.
    • upstreamAmr

      public List<String> upstreamAmr(org.springframework.security.oauth2.core.user.OAuth2User user)
      Reads the amr values the provider reported.
      Parameters:
      user - the user, as mapped by this class or as the provider described it.
      Returns:
      the values, as strings; empty when there is none.
    • safeClaims

      private Map<String,Object> safeClaims(Map<String,Object> claims)
      Normalises a claim map.
      Parameters:
      claims - the claims.
      Returns:
      a new, mutable map of JSON-friendly values.
    • safe

      private Object safe(Object value)
      Normalises a value.
      Parameters:
      value - the value.
      Returns:
      a JSON-friendly equivalent.