# Class LdapLoginService

Namespace
  adas_core.LdapLogin

Assembly
  adas-core.LdapLogin.dll

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
  object
  LdapLoginService

Implements
  ILoginService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## 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

`ldapConfig` IOptions<LdapConfig>

  The LDAP configuration options.

`validator` IValidator<LdapConfig>

  The validator for the LDAP configuration.

`userService` Lazy<IUserService>

  The user service for managing user information.

`authorityService` IAuthorityService

  The authority service for managing user authorities.

`logger` ILogger<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

bool

### 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

UserEnum.LoginMethod

## 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

`username` string

  The username of the user to authenticate.

`password` string

  The password of the user to authenticate.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

Task<List<User>>

  A task representing the asynchronous operation.

#### 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

`email` string

  The email of the user to retrieve.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

`id` ObjectId

  The ID of the user to retrieve.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

`username` string

  The username of the user to retrieve.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

`context` HttpContext

  The HTTP context of the request.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

`username` string

  The username of the user to authenticate.

`password` string

  The password of the user to authenticate.

#### Returns

Task<User>

  The authenticated user.

#### Exceptions

LoginServicesException

  Thrown when there is an error during the login process.

UserNotFoundException

  Thrown when the user is not found in the LDAP directory.