Class LdapActorRegistrationMapper

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.security.LdapActorRegistrationMapper
All Implemented Interfaces:
org.springframework.security.ldap.userdetails.UserDetailsContextMapper

public class LdapActorRegistrationMapper extends Object implements org.springframework.security.ldap.userdetails.UserDetailsContextMapper
Converts the response of an LDAP server to an Actor object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull LdapActor
    mapUserFromContext(@NonNull org.springframework.ldap.core.DirContextOperations context, @NonNull String userName, @NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
    Creates an Actor from the attributes returned by the LDAP server.
    void
    mapUserToContext(org.springframework.security.core.userdetails.UserDetails ignoredUser, org.springframework.ldap.core.DirContextAdapter ignoredContext)
    Warning! Not implemented!
    private @NonNull Optional<String>
    parseEMailAddress(@NonNull org.springframework.ldap.core.DirContextOperations context)
    Determines the Actor.eMailAddress from the given DirContextOperations, trying
    private @NonNull Optional<String>
    parseName(@NonNull org.springframework.ldap.core.DirContextOperations context)
    Determine's the user's Actor.name from the given DirContextOperations, trying the attributes:
    private @NonNull Optional<ActorRole>
    parseRole(@NonNull org.springframework.ldap.core.DirContextOperations context, @NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
    Determines the Actor.role from the given DirContextOperations (trying the attribute eduPersonAffiliation) and GrantedAuthorities.

    Methods inherited from class Object

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

    • LOG

      private static final org.slf4j.Logger LOG
  • Constructor Details

    • LdapActorRegistrationMapper

      public LdapActorRegistrationMapper()
  • Method Details

    • mapUserFromContext

      @NonNull public @NonNull LdapActor mapUserFromContext(@NonNull @NonNull org.springframework.ldap.core.DirContextOperations context, @NonNull @NonNull String userName, @NonNull @NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)

      Creates an Actor from the attributes returned by the LDAP server.

      Warning! It is possible that an Actor with the same user name already exists in the local database.

      Specified by:
      mapUserFromContext in interface org.springframework.security.ldap.userdetails.UserDetailsContextMapper
      Parameters:
      context - The actual LDAP attributes.
      userName - The Actor.userName that was used for authentication with the LDAP server.
      authorities - Other Spring authorities associated with the user. May be empty.
      Returns:
      A new Actor object based on the LDAP response.
    • parseRole

      @NonNull private @NonNull Optional<ActorRole> parseRole(@NonNull @NonNull org.springframework.ldap.core.DirContextOperations context, @NonNull @NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
      Determines the Actor.role from the given DirContextOperations (trying the attribute eduPersonAffiliation) and GrantedAuthorities.
      Parameters:
      context - The response from the LDAP server.
      authorities - Other Spring authorities associated with the user.
      Returns:
      The user's role. Empty if it could not be found.
    • parseName

      @NonNull private @NonNull Optional<String> parseName(@NonNull @NonNull org.springframework.ldap.core.DirContextOperations context)

      Determine's the user's Actor.name from the given DirContextOperations, trying the attributes:

      1. displayname
      2. givenName + FSUCompleteSurname
      3. FSUFirstName + FSUCompleteSurname
      Parameters:
      context - The response from the LDAP server.
      Returns:
      The user's name. Empty if it could not be found.
    • parseEMailAddress

      @NonNull private @NonNull Optional<String> parseEMailAddress(@NonNull @NonNull org.springframework.ldap.core.DirContextOperations context)

      Determines the Actor.eMailAddress from the given DirContextOperations, trying

      1. the mail attribute
      2. the mailLocalAddress attribute
      3. the mailRoutingAddress attribute.
      Parameters:
      context - The response from the LDAP server.
      Returns:
      The user's e-mail address. Empty if none could be found.
    • mapUserToContext

      @Contract("_, _ -> fail") public void mapUserToContext(org.springframework.security.core.userdetails.UserDetails ignoredUser, org.springframework.ldap.core.DirContextAdapter ignoredContext) throws org.apache.commons.lang3.NotImplementedException
      Warning! Not implemented!
      Specified by:
      mapUserToContext in interface org.springframework.security.ldap.userdetails.UserDetailsContextMapper
      Throws:
      org.apache.commons.lang3.NotImplementedException - Always!