Class LdapLoginService
Implementation of ILoginService that authenticates users against an LDAP server. It retrieves user information and authorities based on the LDAP entry and maps them to the application's user model. The service also handles the creation of new users in the application if they do not already exist, based on the LDAP information. It uses configuration settings for connecting to the LDAP server and for mapping LDAP attributes to user properties and authorities.
public class LdapLoginService : ILoginService
- Inheritance
-
LdapLoginService
- Implements
- Inherited Members
- Extension Methods
Constructors
LdapLoginService(IOptions<LdapConfig>, IValidator<LdapConfig>, Lazy<IUserService>, IAuthorityService, ILogger<LdapLoginService>)
Constructor for LdapLoginService. It initializes the service with the necessary dependencies and validates the LDAP configuration.
public LdapLoginService(IOptions<LdapConfig> ldapConfig, IValidator<LdapConfig> validator, Lazy<IUserService> userService, IAuthorityService authorityService, ILogger<LdapLoginService> logger)
Parameters
ldapConfigIOptions<LdapConfig>The LDAP configuration options.
validatorIValidator<LdapConfig>The validator for the LDAP configuration.
userServiceLazy<IUserService>The user service for managing user information.
authorityServiceIAuthorityServiceThe authority service for managing user authorities.
loggerILogger<LdapLoginService>The logger for logging LDAP login operations.
Properties
AllowPassword
Indicates that this login service allows password authentication, as it connects to an LDAP server which typically requires a username and password for authentication.
public bool AllowPassword { get; }
Property Value
Method
Indicates that this login service does not allow token-based authentication, as it is designed to authenticate users against an LDAP server using their credentials rather than tokens.
public UserEnum.LoginMethod Method { get; }
Property Value
Methods
Authenticate(string, string)
This method is not implemented in the LdapLoginService, as the authentication process is handled through the Login(string username, string password) method.
public Task<User> Authenticate(string username, string password)
Parameters
usernamestringThe username of the user to authenticate.
passwordstringThe password of the user to authenticate.
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
GetAllUsers()
This method is not implemented in the LdapLoginService, as the user retrieval process is handled through the Login(string username, string password) method and the GetOrCreateUser(User userEntryLdap, LdapEntry entry) method.
public Task<List<User>> GetAllUsers()
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
GetByEmail(string)
This method is not implemented in the LdapLoginService, as the user retrieval process is handled through the Login(string username, string password) method and the GetOrCreateUser(User userEntryLdap, LdapEntry entry) method.
public Task<User?> GetByEmail(string email)
Parameters
emailstringThe email of the user to retrieve.
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
GetById(ObjectId)
This method is not implemented in the LdapLoginService, as the user retrieval process is handled through the Login(string username, string password) method and the GetOrCreateUser(User userEntryLdap, LdapEntry entry) method.
public Task<User?> GetById(ObjectId id)
Parameters
idObjectIdThe ID of the user to retrieve.
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
GetByUsername(string)
This method is not implemented in the LdapLoginService, as the user retrieval process is handled through the Login(string username, string password) method and the GetOrCreateUser(User userEntryLdap, LdapEntry entry) method.
public Task<User?> GetByUsername(string username)
Parameters
usernamestringThe username of the user to retrieve.
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
Login(HttpContext)
This method is not implemented in the LdapLoginService, as the login process is handled through the Login(string username, string password) method.
public Task<User> Login(HttpContext context)
Parameters
contextHttpContextThe HTTP context of the request.
Returns
Exceptions
- LoginServicesException
Thrown when the method is not implemented.
Login(string, string)
Authenticates a user against the LDAP server using the provided username and password.
public Task<User> Login(string username, string password)
Parameters
usernamestringThe username of the user to authenticate.
passwordstringThe password of the user to authenticate.
Returns
Exceptions
- LoginServicesException
Thrown when there is an error during the login process.
- UserNotFoundException
Thrown when the user is not found in the LDAP directory.