feat: LdapOptions erstellt anstelle statischer (fest codierter) Konfigurationswerte, LdapOptions und Abhängigkeitsinjektionen dafür hinzugefügt
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
using HRD.LDAPService.JWT;
|
||||
using HRD.LDAPService.Ldap;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
using System.Linq;
|
||||
|
||||
namespace HRD.LDAPService
|
||||
{
|
||||
public static class LdapAuthenticationService
|
||||
public class LdapAuthenticationService
|
||||
{
|
||||
private const string LDAP_DOMAIN = "dhr.local";
|
||||
private readonly string LDAP_DOMAIN;
|
||||
|
||||
private static UserPrincipal GetUserPrincipal(string loginName, PrincipalContext principalContext)
|
||||
public LdapAuthenticationService(IOptions<LdapOptions> options)
|
||||
{
|
||||
LDAP_DOMAIN = options.Value.LDAP_DOMAIN;
|
||||
}
|
||||
|
||||
private UserPrincipal GetUserPrincipal(string loginName, PrincipalContext principalContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -36,7 +43,7 @@ namespace HRD.LDAPService
|
||||
/// </summary>
|
||||
/// <param name="ldapUser"></param>
|
||||
/// <returns></returns>
|
||||
public static LdapUser RenewIdentity(string token)
|
||||
public LdapUser RenewIdentity(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) { throw new ArgumentNullException("Token is empty!"); }
|
||||
|
||||
@@ -64,7 +71,7 @@ namespace HRD.LDAPService
|
||||
/// </summary>
|
||||
/// <param name="ldapUser"></param>
|
||||
/// <returns></returns>
|
||||
public static LdapUser RenewIdentity(LdapUser ldapUser)
|
||||
public LdapUser RenewIdentity(LdapUser ldapUser)
|
||||
{
|
||||
if (ldapUser == default) { return default; }
|
||||
try
|
||||
@@ -127,7 +134,7 @@ namespace HRD.LDAPService
|
||||
/// </summary>
|
||||
/// <param name="ldapUser"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CheckAndUpdateIdentityWithPassword(LdapUser ldapUser)
|
||||
public bool CheckAndUpdateIdentityWithPassword(LdapUser ldapUser)
|
||||
{
|
||||
if (ldapUser == default) { return false; }
|
||||
try
|
||||
@@ -184,7 +191,7 @@ namespace HRD.LDAPService
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateLdapUserFromPrincipalContext(ref LdapUser ldapUser, PrincipalContext principalContext)
|
||||
private void UpdateLdapUserFromPrincipalContext(ref LdapUser ldapUser, PrincipalContext principalContext)
|
||||
{
|
||||
UserPrincipal userPrincipal = GetUserPrincipal(ldapUser.LoginName, principalContext);
|
||||
if (userPrincipal == default)
|
||||
|
||||
25
HRD.LDAPService/Ldap/LdapOptions.cs
Normal file
25
HRD.LDAPService/Ldap/LdapOptions.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace HRD.LDAPService.Ldap
|
||||
{
|
||||
public class LdapOptions
|
||||
{
|
||||
public bool LDAP_WebAppGroup_Is_Live { get; init; }
|
||||
|
||||
public string LDAP_WINDREAM { get; init; }
|
||||
|
||||
public string LDAP_DOMAIN { get; init; }
|
||||
|
||||
public string LDAP_PATH_EDM { get; init; }
|
||||
|
||||
public string LDAP_PATH_WEBAPPS { get; init; }
|
||||
|
||||
public string LDAP_EDMUser_Prefix { get; init; }
|
||||
|
||||
public string LDAP_EDMAdmin_Prefix { get; init; }
|
||||
|
||||
public string LDAP_EDM_Prefix { get; init; }
|
||||
|
||||
public string LDAP_WebAppp_Prefix { get; init; }
|
||||
|
||||
public string LDAP_Prefix_Test { get; init; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user