diff --git a/CarParkValidationAPI.sln b/CarParkValidationAPI.sln
index b48e8db..1ca3a36 100644
--- a/CarParkValidationAPI.sln
+++ b/CarParkValidationAPI.sln
@@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarParkValidationAPI", "CarParkValidationAPI\CarParkValidationAPI.csproj", "{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonAD", "CommonAD\CommonAD.csproj", "{43FC73FD-1EE6-4B68-9299-E77049B5E490}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonAD", "..\CommonAD\CommonAD.csproj", "{0E8073C3-27BC-4E2E-B13B-E8692835BA9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +17,10 @@ Global
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Release|Any CPU.Build.0 = Release|Any CPU
- {43FC73FD-1EE6-4B68-9299-E77049B5E490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {43FC73FD-1EE6-4B68-9299-E77049B5E490}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {43FC73FD-1EE6-4B68-9299-E77049B5E490}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {43FC73FD-1EE6-4B68-9299-E77049B5E490}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0E8073C3-27BC-4E2E-B13B-E8692835BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E8073C3-27BC-4E2E-B13B-E8692835BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E8073C3-27BC-4E2E-B13B-E8692835BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E8073C3-27BC-4E2E-B13B-E8692835BA9C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/CarParkValidationAPI/CarParkValidationAPI.csproj b/CarParkValidationAPI/CarParkValidationAPI.csproj
index a95f862..2a33178 100644
--- a/CarParkValidationAPI/CarParkValidationAPI.csproj
+++ b/CarParkValidationAPI/CarParkValidationAPI.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/CarParkValidationAPI/Controllers/UsersController.cs b/CarParkValidationAPI/Controllers/UsersController.cs
index 3f806c1..6e9750a 100644
--- a/CarParkValidationAPI/Controllers/UsersController.cs
+++ b/CarParkValidationAPI/Controllers/UsersController.cs
@@ -40,7 +40,7 @@ namespace CarParkValidationAPI.Controllers
[HttpPost("[action]")]
public async Task LoginApiAD(AuthenticateRequest model)
{
- var response = await _userService.LoginApiAD(model);
+ var response = await _userService.LoginApiAD(model);
return Ok(response);
}
[AllowAnonymous]
diff --git a/CommonAD/ADConfig.cs b/CommonAD/ADConfig.cs
deleted file mode 100644
index c989760..0000000
--- a/CommonAD/ADConfig.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-namespace CommonAD.Models
-{
- public class ADConfig
- {
- public string LDAPPath = "";
- public string LDAPUser = "";
- public string LDAPPassword = "";
- private TimeSpan _ADTimeOut = TimeSpan.FromSeconds(0);
-
- public TimeSpan ADTimeOut
- {
- get
- {
- return _ADTimeOut;
- }
- }
- public string ADTimeOutStr
- {
- set
- {
- if (!string.IsNullOrEmpty(value))
- _ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(value));
- }
- }
-
- /*
- public static void Init()
- {
- LDAPPath = ConfigurationManager.AppSettings["LDAPPath"];
- LDAPUser = ConfigurationManager.AppSettings["LDAPUser"];
- LDAPPassword = ConfigurationManager.AppSettings["LDAPPassword"];
- ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["ADTimeOut"]));
- }
- */
- }
-}
-
-
diff --git a/CommonAD/ADStaffLink.cs b/CommonAD/ADStaffLink.cs
deleted file mode 100644
index 66e380f..0000000
--- a/CommonAD/ADStaffLink.cs
+++ /dev/null
@@ -1,373 +0,0 @@
-using CommonAD.Models;
-using System;
-using System.Collections.Generic;
-using System.DirectoryServices;
-
-
-namespace CommonAD
-{
- public class ADStaffLink
- {
- private ADConfig _adConfig;
- public ADStaffLink (ADConfig adConfig)
- {
- _adConfig = adConfig;
- }
- public MyADObject SearchStaff(string FirstName = "", string LastName = "")
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(givenname={0})(sn={1}))", FirstName, LastName);
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- //LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject SearchStaff(string StaffLinkNo)
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = "(SAMAccountName=" + StaffLinkNo + ")";
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- // LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "SAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.JobTitle = GetUserPropertyValue(sr, "title", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch (Exception ex)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject CheckADCredentials(string user, string pass)
- {
- //dynamic LoginResult = new JObject() as dynamic;
- bool res = true;
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, user, pass))
- {
- try
- {
- //DE.RefreshCache(); // This will force credentials validation
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- //adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
- adsSearcher.Filter = "(sAMAccountName=" + user + ")";
-
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
-
- // we will retrieve the count of staff in DirectReports as a flag to determine if this user is a manager
- // we will assume if no staff then requests lodged by this user will need signoff by their manager
- //LoginResult.StaffListCount = sr.Properties["DirectReports"].Count;
- //LoginResult.PWD = ADConfig.LDAPPassword;
- //LoginResult.User = ADConfig.LDAPUser;
-
-
- /* // we do not think we need actual staff IDs at this point - a count of staff will be enough for this application
- // but leave here in case we need to re-use this in another app.
- List StaffList = new List();
- foreach (string objProperty in sr.Properties["DirectReports"])
- {
-
-
- string emp = objProperty.ToString().Split(',')[0];
- emp = emp.Replace("CN=", "");
- StaffList.Add(emp);
- //emps.Add(emp);
- //user.StaffList += '|';
- //user.StaffList += emp;
- //
- }
- LoginResult.StaffList = JsonConvert.SerializeObject(StaffList);
- */
-
- try
- {
- if (ADObj.Manager != String.Empty)
- {
- String managerInfo = Convert.ToString(ADObj.Manager);
- String managerID = managerInfo.Split(',')[0].Split('=')[1];
- String managerOU = managerInfo.Split(',')[1].Split('=')[1];
- List managerDetails = Search(managerID, managerOU);
- // JToken managerDetails = Search(managerID);
- ADObj.ManagerDetails = managerDetails[0].ToString();
- }
- }
- catch (Exception ex)
- {
- ADObj.ManagerDetails = "Not available: " + ex.Message;
- }
-
- }
- }
- catch (Exception ex2)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- res = false;
- }
- }
- catch
- {
- res = false;
- }
- }
-
- ADObj.result = res;
- // string token = "";
- // long tickTock = DateTime.Now.Ticks;
- // if (res)
- // {
- //string tokenPT = app + "|" + user + "|" + pass + "|" + tickTock + "|" + "NBM";
- //token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- //token = CommonEncoding.Base64Encode(token);
- //}
-
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
-
-
- //return LoginResult;
- return ADObj;
-
- }
- public List Search(string q, string ou)
- {
- //ou = "Nepean Blue Mountains";
- MyADObject ADObj = new Models.MyADObject();
- //ADConfig.Init();
-
- List lstLDAPUser = new List();
-
- if (string.IsNullOrEmpty(q))
- q = "______"; //defualt not found
- System.DirectoryServices.DirectoryEntry dirEntry = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword);
- DirectorySearcher dirSearch = new DirectorySearcher(dirEntry);
- dirSearch.ClientTimeout = _adConfig.ADTimeOut;
- dirSearch.ServerTimeLimit = _adConfig.ADTimeOut;
- dirSearch.ServerPageTimeLimit = _adConfig.ADTimeOut;
- dirSearch.Filter = "(&(objectClass=user)(|(cn=" + q + "*)))";
- dirSearch.SearchRoot = dirEntry;
- dirSearch.SearchScope = SearchScope.Subtree;
- dirSearch.PageSize = 100;
- dirSearch.Sort = new SortOption("displayName", SortDirection.Ascending);
-
-
- using (SearchResultCollection src = dirSearch.FindAll())
- {
- int i = 0;
- foreach (SearchResult sr in src)
- {
- i++;
- if (i > 100)
- break;
- bool bLogindisabled = true;
-
- string sTmp = GetUserPropertyValue(sr, "logindisabled", 0);
- bLogindisabled = (sTmp == string.Empty ? false : Convert.ToBoolean(sTmp));
-
- if (!bLogindisabled)
- {
- sTmp = GetUserPropertyValue(sr, "passwordexpirationtime", 0);
- if (sTmp != "")
- {
- try
- {
- if (DateTime.Now > Convert.ToDateTime(sTmp))
- {
- bLogindisabled = true;
- }
- }
- catch { }
- }
- }
-
- if (!bLogindisabled)
- {
- MyADObject user = new MyADObject();
- // user.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- user.LastName = GetUserPropertyValue(sr, "sn", 0);
- user.Email = GetUserPropertyValue(sr, "mail", 0);
- user.Company = GetUserPropertyValue(sr, "company", 0);
- user.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- user.Department = GetUserPropertyValue(sr, "department", 0);
- user.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- //user.company = GetUserPropertyValue(sr, "company", 0);
- user.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- //user.distinguishedName = GetUserPropertyValue(sr, "distinguishedName", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
-
- lstLDAPUser.Add(user);
- }
-
- }
-
- }
- if (dirSearch != null)
- dirSearch.Dispose();
- if (dirEntry != null)
- dirEntry.Dispose();
- return lstLDAPUser;
-
- }//end method
- private string GetUserPropertyValue(SearchResult res, string sPropertyName, int lIndex)
- {
- try
- {
- if (res.Properties[sPropertyName].Count > lIndex)
- {
- string s;
- object v = res.Properties[sPropertyName][lIndex];
-
- if (v.GetType() == typeof(byte[]))
- {
- s = System.Text.ASCIIEncoding.ASCII.GetString((byte[])v);
- }
- else if (v.GetType() == typeof(DateTime))
- {
- s = ((DateTime)v).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
- }
- else
- {
- s = v.ToString();
- }
- return (s);
- }
- else
- {
- return ("");
- }
- }
- catch
- {
- return ("");
- }
- }
- }
-}
diff --git a/CommonAD/CommonAD.csproj b/CommonAD/CommonAD.csproj
deleted file mode 100644
index d4fb241..0000000
--- a/CommonAD/CommonAD.csproj
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
- net5.0
-
-
-
-
-
-
-
-
diff --git a/CommonAD/MyADObject.cs b/CommonAD/MyADObject.cs
deleted file mode 100644
index c9c9123..0000000
--- a/CommonAD/MyADObject.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-
-namespace CommonAD.Models
-{
- public class MyADObject
- {
- public string StafflinkNo { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public string Company { get; set; }
- public string Location { get; set; }
- public string Department { get; set; }
- public string JobTitle { get; set; }
- public string BadPwdCount { get; set; }
- public string Phone { get; set; }
- public string DisplayName { get; set; }
- public string Manager { get; set; }
- public string ReportsTo { get; set; }
- public string StaffList { get; set; }
- public string ManagerDetails { get; set; }
- public bool result { get; set; }
-
-
- }
-
-
-}
diff --git a/CommonAD/WebAPIUtil.cs b/CommonAD/WebAPIUtil.cs
deleted file mode 100644
index ddc56f2..0000000
--- a/CommonAD/WebAPIUtil.cs
+++ /dev/null
@@ -1,268 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Text;
-using System.Threading.Tasks;
-using CommonAD.Models;
-using System.Net.Http.Json;
-
-namespace CommonAD
-{
- public class WebAPIUtil
- {
- ///
- /// SearchStaff
- ///
- /// "http://virtapp-mdb048/CommonAPI/api/AD/"
- /// "SearchStaff"
- ///
- ///
- ///
- public static MyADObject SearchStaff(string webAPIUri, string actionEntry, string username)
- {
- MyADObject result = null;
- if (!webAPIUri.EndsWith("/"))
- webAPIUri += "/";
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri(webAPIUri);
-
- // We want the response to be JSON.
- // client.DefaultRequestHeaders.Accept.Clear();
- // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- // Build up the data to POST.
- // List> postData = new List>();
- // postData.Add(new KeyValuePair("StaffLinkNo", username));
- // postData.Add(new KeyValuePair("pass", password));
- //postData.Add(new KeyValuePair("client_secret", clientSecret));
-
- //var form = new Dictionary
- //{
- // {"grant_type", "client_credentials"},
-
- //};
- //client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
- //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(username + ":" + password)));
-
- // HttpContent content = new StringContent(json, Encoding.UTF8);
-
- // actionEntry = webAPIUri + actionEntry;
- // FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
- //FormUrlEncodedContent content = new FormUrlEncodedContent(form);
- // Post to the Server and parse the response.
- //HttpResponseMessage response = await client.PostAsync("Token", content);
- // string jsonString = await response.Content.ReadAsStringAsync();
- //HttpResponseMessage response = client.PostAsync(actionEntry, content).GetAwaiter().GetResult();
- actionEntry = actionEntry + "?StaffLinkNo=" + username;
- try
- {
- var myado = client.GetFromJsonAsync(actionEntry).GetAwaiter().GetResult();
- if (myado != null)
- result = myado;
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
-
- return result;
- }
- ///
- /// SearchStaff Async version
- ///
- /// "http://virtapp-mdb048/CommonAPI/api/AD/"
- /// "SearchStaff"
- ///
- ///
- public static async Task SearchStaffAsync(string webAPIUri, string actionEntry, string username)
- {
- MyADObject result = null;
- string error = "";
- if (!webAPIUri.EndsWith("/"))
- webAPIUri += "/";
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri(webAPIUri);
-
- // We want the response to be JSON.
- // client.DefaultRequestHeaders.Accept.Clear();
- // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- // Build up the data to POST.
- // List> postData = new List>();
- // postData.Add(new KeyValuePair("StaffLinkNo", username));
- // postData.Add(new KeyValuePair("pass", password));
- //postData.Add(new KeyValuePair("client_secret", clientSecret));
-
- //var form = new Dictionary
- //{
- // {"grant_type", "client_credentials"},
-
- //};
- //client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
- //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(username + ":" + password)));
-
- // HttpContent content = new StringContent(json, Encoding.UTF8);
-
- // actionEntry = webAPIUri + actionEntry;
- //FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
- //FormUrlEncodedContent content = new FormUrlEncodedContent(form);
- // Post to the Server and parse the response.
- //HttpResponseMessage response = await client.PostAsync("Token", content);
- // string jsonString = await response.Content.ReadAsStringAsync();
- //HttpResponseMessage response = client.PostAsync(actionEntry, content).GetAwaiter().GetResult();
- actionEntry = actionEntry + "?StaffLinkNo=" + username;
- try
- {
- result = await client.GetFromJsonAsync(actionEntry);
- }
- catch (Exception ex)
- {
- error = ex.ToString();
- result = null;
- }
-
- }
-
- return result;
- }
- ///
- /// GetLoginAD webAPIUri "http://virtapp-mdb048/CommonAPI/api/AD/";
- ///
- /// "http://virtapp-mdb048/CommonAPI/api/AD/"
- /// "CheckADCredentials"
- ///
- ///
- ///
- ///
- public static string GetLoginAD(string webAPIUri, string actionEntry, string username, string password, out string error)
- {
- string result = "";
- // string tokenstr = "";
- if (!webAPIUri.EndsWith("/"))
- webAPIUri += "/";
- string mytoken = "";
- error = "";
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri(webAPIUri);
-
- // We want the response to be JSON.
- // client.DefaultRequestHeaders.Accept.Clear();
- // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- // Build up the data to POST.
- // List> postData = new List>();
- // postData.Add(new KeyValuePair("user", username));
- // postData.Add(new KeyValuePair("pass", password));
- //postData.Add(new KeyValuePair("client_secret", clientSecret));
-
- //var form = new Dictionary
- //{
- // {"grant_type", "client_credentials"},
-
- //};
- //client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
- //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(username + ":" + password)));
-
- // HttpContent content = new StringContent(json, Encoding.UTF8);
-
- // actionEntry = webAPIUri + actionEntry;
- // FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
- //FormUrlEncodedContent content = new FormUrlEncodedContent(form);
- // Post to the Server and parse the response.
- //HttpResponseMessage response = await client.PostAsync("Token", content);
- // string jsonString = await response.Content.ReadAsStringAsync();
- //HttpResponseMessage response = client.PostAsync(actionEntry, content).GetAwaiter().GetResult();
- actionEntry = actionEntry + "?user=" + username + "&pass=" + password;
- //client.GetFromJsonAsync(actionEntry);
-
- HttpResponseMessage response = client.GetAsync(actionEntry).GetAwaiter().GetResult();
- if (response.StatusCode == HttpStatusCode.OK)
- {
- mytoken = (response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
-
-
- result = mytoken;
-
- }
- else
- {
- result = response.ReasonPhrase.ToString();
- error = result;
- result = "";
- }
- }
-
- return result;
- }
- ///
- /// GetLoginAD Async version
- ///
- /// "http://virtapp-mdb048/CommonAPI/api/AD/"
- /// "CheckADCredentials"
- ///
- ///
- ///
- public static async Task GetLoginADAsync(string webAPIUri, string actionEntry, string username, string password)
- {
- MyADObject result = null;
- if (!webAPIUri.EndsWith("/"))
- webAPIUri += "/";
- string error = "";
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri(webAPIUri);
-
- // We want the response to be JSON.
- // client.DefaultRequestHeaders.Accept.Clear();
- // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- // Build up the data to POST.
- // List> postData = new List>();
- // postData.Add(new KeyValuePair("user", username));
- // postData.Add(new KeyValuePair("pass", password));
- //postData.Add(new KeyValuePair("client_secret", clientSecret));
-
- //var form = new Dictionary
- //{
- // {"grant_type", "client_credentials"},
-
- //};
- //client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
- //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(username + ":" + password)));
-
- // HttpContent content = new StringContent(json, Encoding.UTF8);
-
- // actionEntry = webAPIUri + actionEntry;
- // FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
- //FormUrlEncodedContent content = new FormUrlEncodedContent(form);
- // Post to the Server and parse the response.
- //HttpResponseMessage response = await client.PostAsync("Token", content);
- // string jsonString = await response.Content.ReadAsStringAsync();
- //HttpResponseMessage response = client.PostAsync(actionEntry, content).GetAwaiter().GetResult();
- actionEntry = actionEntry + "?user=" + username + "&pass=" + password;
- try
- {
- result = await client.GetFromJsonAsync(actionEntry);
- }
- catch (Exception ex)
- {
- error = ex.ToString();
- result = null;
- }
-
- }
- return result;
- }
- }
-}
diff --git a/CommonAuth/ADConfig.cs b/CommonAuth/ADConfig.cs
deleted file mode 100644
index 24354da..0000000
--- a/CommonAuth/ADConfig.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-namespace CommonApi.Models
-{
- public class ADConfig
- {
- public string LDAPPath = "";
- public string LDAPUser = "";
- public string LDAPPassword = "";
- private TimeSpan _ADTimeOut = TimeSpan.FromSeconds(0);
-
- public TimeSpan ADTimeOut
- {
- get
- {
- return _ADTimeOut;
- }
- }
- public string ADTimeOutStr
- {
- set
- {
- if (!string.IsNullOrEmpty(value))
- _ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(value));
- }
- }
-
- /*
- public static void Init()
- {
- LDAPPath = ConfigurationManager.AppSettings["LDAPPath"];
- LDAPUser = ConfigurationManager.AppSettings["LDAPUser"];
- LDAPPassword = ConfigurationManager.AppSettings["LDAPPassword"];
- ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["ADTimeOut"]));
- }
- */
- }
-}
-
-
diff --git a/CommonAuth/ADStaffLink.cs b/CommonAuth/ADStaffLink.cs
deleted file mode 100644
index 4b3e675..0000000
--- a/CommonAuth/ADStaffLink.cs
+++ /dev/null
@@ -1,374 +0,0 @@
-using CommonApi.Models;
-using CommonAuth.Models;
-using System;
-using System.Collections.Generic;
-using System.DirectoryServices;
-
-
-namespace CommonAuth
-{
- public class ADStaffLink
- {
- private ADConfig _adConfig;
- public ADStaffLink (ADConfig adConfig)
- {
- _adConfig = adConfig;
- }
- public MyADObject SearchStaff(string FirstName = "", string LastName = "")
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(givenname={0})(sn={1}))", FirstName, LastName);
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- //LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject SearchStaff(string StaffLinkNo)
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = "(SAMAccountName=" + StaffLinkNo + ")";
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- // LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "SAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.JobTitle = GetUserPropertyValue(sr, "title", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch (Exception ex)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject CheckADCredentials(string user, string pass)
- {
- //dynamic LoginResult = new JObject() as dynamic;
- bool res = true;
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, user, pass))
- {
- try
- {
- //DE.RefreshCache(); // This will force credentials validation
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- //adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
- adsSearcher.Filter = "(sAMAccountName=" + user + ")";
-
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
-
- // we will retrieve the count of staff in DirectReports as a flag to determine if this user is a manager
- // we will assume if no staff then requests lodged by this user will need signoff by their manager
- //LoginResult.StaffListCount = sr.Properties["DirectReports"].Count;
- //LoginResult.PWD = ADConfig.LDAPPassword;
- //LoginResult.User = ADConfig.LDAPUser;
-
-
- /* // we do not think we need actual staff IDs at this point - a count of staff will be enough for this application
- // but leave here in case we need to re-use this in another app.
- List StaffList = new List();
- foreach (string objProperty in sr.Properties["DirectReports"])
- {
-
-
- string emp = objProperty.ToString().Split(',')[0];
- emp = emp.Replace("CN=", "");
- StaffList.Add(emp);
- //emps.Add(emp);
- //user.StaffList += '|';
- //user.StaffList += emp;
- //
- }
- LoginResult.StaffList = JsonConvert.SerializeObject(StaffList);
- */
-
- try
- {
- if (ADObj.Manager != String.Empty)
- {
- String managerInfo = Convert.ToString(ADObj.Manager);
- String managerID = managerInfo.Split(',')[0].Split('=')[1];
- String managerOU = managerInfo.Split(',')[1].Split('=')[1];
- List managerDetails = Search(managerID, managerOU);
- // JToken managerDetails = Search(managerID);
- ADObj.ManagerDetails = managerDetails[0].ToString();
- }
- }
- catch (Exception ex)
- {
- ADObj.ManagerDetails = "Not available: " + ex.Message;
- }
-
- }
- }
- catch (Exception ex2)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- res = false;
- }
- }
- catch
- {
- res = false;
- }
- }
-
- ADObj.result = res;
- // string token = "";
- // long tickTock = DateTime.Now.Ticks;
- // if (res)
- // {
- //string tokenPT = app + "|" + user + "|" + pass + "|" + tickTock + "|" + "NBM";
- //token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- //token = CommonEncoding.Base64Encode(token);
- //}
-
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
-
-
- //return LoginResult;
- return ADObj;
-
- }
- public List Search(string q, string ou)
- {
- //ou = "Nepean Blue Mountains";
- MyADObject ADObj = new Models.MyADObject();
- //ADConfig.Init();
-
- List lstLDAPUser = new List();
-
- if (string.IsNullOrEmpty(q))
- q = "______"; //defualt not found
- System.DirectoryServices.DirectoryEntry dirEntry = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword);
- DirectorySearcher dirSearch = new DirectorySearcher(dirEntry);
- dirSearch.ClientTimeout = _adConfig.ADTimeOut;
- dirSearch.ServerTimeLimit = _adConfig.ADTimeOut;
- dirSearch.ServerPageTimeLimit = _adConfig.ADTimeOut;
- dirSearch.Filter = "(&(objectClass=user)(|(cn=" + q + "*)))";
- dirSearch.SearchRoot = dirEntry;
- dirSearch.SearchScope = SearchScope.Subtree;
- dirSearch.PageSize = 100;
- dirSearch.Sort = new SortOption("displayName", SortDirection.Ascending);
-
-
- using (SearchResultCollection src = dirSearch.FindAll())
- {
- int i = 0;
- foreach (SearchResult sr in src)
- {
- i++;
- if (i > 100)
- break;
- bool bLogindisabled = true;
-
- string sTmp = GetUserPropertyValue(sr, "logindisabled", 0);
- bLogindisabled = (sTmp == string.Empty ? false : Convert.ToBoolean(sTmp));
-
- if (!bLogindisabled)
- {
- sTmp = GetUserPropertyValue(sr, "passwordexpirationtime", 0);
- if (sTmp != "")
- {
- try
- {
- if (DateTime.Now > Convert.ToDateTime(sTmp))
- {
- bLogindisabled = true;
- }
- }
- catch { }
- }
- }
-
- if (!bLogindisabled)
- {
- MyADObject user = new MyADObject();
- // user.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- user.LastName = GetUserPropertyValue(sr, "sn", 0);
- user.Email = GetUserPropertyValue(sr, "mail", 0);
- user.Company = GetUserPropertyValue(sr, "company", 0);
- user.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- user.Department = GetUserPropertyValue(sr, "department", 0);
- user.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- //user.company = GetUserPropertyValue(sr, "company", 0);
- user.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- //user.distinguishedName = GetUserPropertyValue(sr, "distinguishedName", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
-
- lstLDAPUser.Add(user);
- }
-
- }
-
- }
- if (dirSearch != null)
- dirSearch.Dispose();
- if (dirEntry != null)
- dirEntry.Dispose();
- return lstLDAPUser;
-
- }//end method
- private string GetUserPropertyValue(SearchResult res, string sPropertyName, int lIndex)
- {
- try
- {
- if (res.Properties[sPropertyName].Count > lIndex)
- {
- string s;
- object v = res.Properties[sPropertyName][lIndex];
-
- if (v.GetType() == typeof(byte[]))
- {
- s = System.Text.ASCIIEncoding.ASCII.GetString((byte[])v);
- }
- else if (v.GetType() == typeof(DateTime))
- {
- s = ((DateTime)v).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
- }
- else
- {
- s = v.ToString();
- }
- return (s);
- }
- else
- {
- return ("");
- }
- }
- catch
- {
- return ("");
- }
- }
- }
-}
diff --git a/CommonAuth/CommonAuth.csproj b/CommonAuth/CommonAuth.csproj
deleted file mode 100644
index 51d25f4..0000000
--- a/CommonAuth/CommonAuth.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
- netstandard2.0
-
-
-
-
-
-
-
-
-
diff --git a/CommonAuth/MyADObject.cs b/CommonAuth/MyADObject.cs
deleted file mode 100644
index 040b45d..0000000
--- a/CommonAuth/MyADObject.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-
-namespace CommonAuth.Models
-{
- public class MyADObject
- {
- public string StafflinkNo { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public string Company { get; set; }
- public string Location { get; set; }
- public string Department { get; set; }
- public string JobTitle { get; set; }
- public string BadPwdCount { get; set; }
- public string Phone { get; set; }
- public string DisplayName { get; set; }
- public string Manager { get; set; }
- public string ReportsTo { get; set; }
- public string StaffList { get; set; }
- public string ManagerDetails { get; set; }
- public bool result { get; set; }
-
-
- }
-
-
-}
diff --git a/CommonAuth_old/ADConfig.cs b/CommonAuth_old/ADConfig.cs
deleted file mode 100644
index 24354da..0000000
--- a/CommonAuth_old/ADConfig.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-namespace CommonApi.Models
-{
- public class ADConfig
- {
- public string LDAPPath = "";
- public string LDAPUser = "";
- public string LDAPPassword = "";
- private TimeSpan _ADTimeOut = TimeSpan.FromSeconds(0);
-
- public TimeSpan ADTimeOut
- {
- get
- {
- return _ADTimeOut;
- }
- }
- public string ADTimeOutStr
- {
- set
- {
- if (!string.IsNullOrEmpty(value))
- _ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(value));
- }
- }
-
- /*
- public static void Init()
- {
- LDAPPath = ConfigurationManager.AppSettings["LDAPPath"];
- LDAPUser = ConfigurationManager.AppSettings["LDAPUser"];
- LDAPPassword = ConfigurationManager.AppSettings["LDAPPassword"];
- ADTimeOut = TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["ADTimeOut"]));
- }
- */
- }
-}
-
-
diff --git a/CommonAuth_old/ADStaffLink.cs b/CommonAuth_old/ADStaffLink.cs
deleted file mode 100644
index 56ec333..0000000
--- a/CommonAuth_old/ADStaffLink.cs
+++ /dev/null
@@ -1,374 +0,0 @@
-using CommonApi.Models;
-using CommonAuth.Models;
-using System;
-using System.Collections.Generic;
-using System.DirectoryServices;
-using System.Reflection.PortableExecutable;
-
-namespace CommonAuth
-{
- public class ADStaffLink
- {
- private ADConfig _adConfig;
- public ADStaffLink (ADConfig adConfig)
- {
- _adConfig = adConfig;
- }
- public MyADObject SearchStaff(string FirstName = "", string LastName = "")
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(givenname={0})(sn={1}))", FirstName, LastName);
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- //LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject SearchStaff(string StaffLinkNo)
- {
-
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword))
- {
- try
- {
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.Filter = "(SAMAccountName=" + StaffLinkNo + ")";
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.result = true;
- // LoginResult.Login = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "SAMAccountName", 0);
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.JobTitle = GetUserPropertyValue(sr, "title", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
- ADObj.ReportsTo = GetUserPropertyValue(sr, "directReports", 0);
- ADObj.StaffList = GetUserPropertyValue(sr, "staffList", 0);
- }
- }
- catch (Exception ex)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- ADObj.result = false;
- }
- }
- catch
- {
- ADObj.result = false;
- }
- }
-
- //LoginResult.Success = res;
- //string token = "";
- //long tickTock = DateTime.Now.Ticks;
- //if (res)
- //{
- // string tokenPT = app + "|" + user + "|" + "|" + tickTock + "|" + "NBM";
- // token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- // token = CommonEncoding.Base64Encode(token);
- //}
- //LoginResult.Login = user;
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
- return ADObj;
-
-
- }
- public MyADObject CheckADCredentials(string user, string pass)
- {
- //dynamic LoginResult = new JObject() as dynamic;
- bool res = true;
- MyADObject ADObj = new MyADObject();
-
- using (var DE = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, user, pass))
- {
- try
- {
- //DE.RefreshCache(); // This will force credentials validation
- DirectorySearcher adsSearcher = new DirectorySearcher(DE);
- adsSearcher.ClientTimeout = _adConfig.ADTimeOut;
- adsSearcher.ServerTimeLimit = _adConfig.ADTimeOut;
- adsSearcher.ServerPageTimeLimit = _adConfig.ADTimeOut;
- //adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
- adsSearcher.Filter = "(sAMAccountName=" + user + ")";
-
- try
- {
- SearchResult sr = adsSearcher.FindOne();
- if (sr != null)
- {
- ADObj.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0); ;
- ADObj.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- ADObj.LastName = GetUserPropertyValue(sr, "sn", 0);
- ADObj.Email = GetUserPropertyValue(sr, "mail", 0);
- ADObj.Company = GetUserPropertyValue(sr, "company", 0);
- ADObj.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- ADObj.Department = GetUserPropertyValue(sr, "department", 0);
- ADObj.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- ADObj.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- ADObj.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- ADObj.Manager = GetUserPropertyValue(sr, "manager", 0);
-
- // we will retrieve the count of staff in DirectReports as a flag to determine if this user is a manager
- // we will assume if no staff then requests lodged by this user will need signoff by their manager
- //LoginResult.StaffListCount = sr.Properties["DirectReports"].Count;
- //LoginResult.PWD = ADConfig.LDAPPassword;
- //LoginResult.User = ADConfig.LDAPUser;
-
-
- /* // we do not think we need actual staff IDs at this point - a count of staff will be enough for this application
- // but leave here in case we need to re-use this in another app.
- List StaffList = new List();
- foreach (string objProperty in sr.Properties["DirectReports"])
- {
-
-
- string emp = objProperty.ToString().Split(',')[0];
- emp = emp.Replace("CN=", "");
- StaffList.Add(emp);
- //emps.Add(emp);
- //user.StaffList += '|';
- //user.StaffList += emp;
- //
- }
- LoginResult.StaffList = JsonConvert.SerializeObject(StaffList);
- */
-
- try
- {
- if (ADObj.Manager != String.Empty)
- {
- String managerInfo = Convert.ToString(ADObj.Manager);
- String managerID = managerInfo.Split(',')[0].Split('=')[1];
- String managerOU = managerInfo.Split(',')[1].Split('=')[1];
- List managerDetails = Search(managerID, managerOU);
- // JToken managerDetails = Search(managerID);
- ADObj.ManagerDetails = managerDetails[0].ToString();
- }
- }
- catch (Exception ex)
- {
- ADObj.ManagerDetails = "Not available: " + ex.Message;
- }
-
- }
- }
- catch (Exception ex2)
- {
- // Failed to authenticate. Most likely it is caused by unknown user
- // id or bad strPassword.
- res = false;
- }
- }
- catch
- {
- res = false;
- }
- }
-
- ADObj.result = res;
- // string token = "";
- // long tickTock = DateTime.Now.Ticks;
- // if (res)
- // {
- //string tokenPT = app + "|" + user + "|" + pass + "|" + tickTock + "|" + "NBM";
- //token = CommonCrypt.EncryptString(tokenPT, "bagmas2011+", "a1b2c3d4");
- //token = CommonEncoding.Base64Encode(token);
- //}
-
- //LoginResult.Token = token;
- //LoginResult.Time = tickTock;
-
-
- //return LoginResult;
- return ADObj;
-
- }
- public List Search(string q, string ou)
- {
- //ou = "Nepean Blue Mountains";
- MyADObject ADObj = new Models.MyADObject();
- //ADConfig.Init();
-
- List lstLDAPUser = new List();
-
- if (string.IsNullOrEmpty(q))
- q = "______"; //defualt not found
- System.DirectoryServices.DirectoryEntry dirEntry = new System.DirectoryServices.DirectoryEntry(_adConfig.LDAPPath, _adConfig.LDAPUser, _adConfig.LDAPPassword);
- DirectorySearcher dirSearch = new DirectorySearcher(dirEntry);
- dirSearch.ClientTimeout = _adConfig.ADTimeOut;
- dirSearch.ServerTimeLimit = _adConfig.ADTimeOut;
- dirSearch.ServerPageTimeLimit = _adConfig.ADTimeOut;
- dirSearch.Filter = "(&(objectClass=user)(|(cn=" + q + "*)))";
- dirSearch.SearchRoot = dirEntry;
- dirSearch.SearchScope = SearchScope.Subtree;
- dirSearch.PageSize = 100;
- dirSearch.Sort = new SortOption("displayName", SortDirection.Ascending);
-
-
- using (SearchResultCollection src = dirSearch.FindAll())
- {
- int i = 0;
- foreach (SearchResult sr in src)
- {
- i++;
- if (i > 100)
- break;
- bool bLogindisabled = true;
-
- string sTmp = GetUserPropertyValue(sr, "logindisabled", 0);
- bLogindisabled = (sTmp == string.Empty ? false : Convert.ToBoolean(sTmp));
-
- if (!bLogindisabled)
- {
- sTmp = GetUserPropertyValue(sr, "passwordexpirationtime", 0);
- if (sTmp != "")
- {
- try
- {
- if (DateTime.Now > Convert.ToDateTime(sTmp))
- {
- bLogindisabled = true;
- }
- }
- catch { }
- }
- }
-
- if (!bLogindisabled)
- {
- MyADObject user = new MyADObject();
- // user.Login = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.StafflinkNo = GetUserPropertyValue(sr, "sAMAccountName", 0);
- user.FirstName = GetUserPropertyValue(sr, "givenname", 0);
- user.LastName = GetUserPropertyValue(sr, "sn", 0);
- user.Email = GetUserPropertyValue(sr, "mail", 0);
- user.Company = GetUserPropertyValue(sr, "company", 0);
- user.Location = GetUserPropertyValue(sr, "physicalDeliveryOfficeName", 0);
- user.Department = GetUserPropertyValue(sr, "department", 0);
- user.BadPwdCount = GetUserPropertyValue(sr, "badPwdCount", 0);
- //user.company = GetUserPropertyValue(sr, "company", 0);
- user.Phone = GetUserPropertyValue(sr, "telephonenumber", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
- //user.distinguishedName = GetUserPropertyValue(sr, "distinguishedName", 0);
- user.DisplayName = GetUserPropertyValue(sr, "displayName", 0);
-
- lstLDAPUser.Add(user);
- }
-
- }
-
- }
- if (dirSearch != null)
- dirSearch.Dispose();
- if (dirEntry != null)
- dirEntry.Dispose();
- return lstLDAPUser;
-
- }//end method
- private string GetUserPropertyValue(SearchResult res, string sPropertyName, int lIndex)
- {
- try
- {
- if (res.Properties[sPropertyName].Count > lIndex)
- {
- string s;
- object v = res.Properties[sPropertyName][lIndex];
-
- if (v.GetType() == typeof(byte[]))
- {
- s = System.Text.ASCIIEncoding.ASCII.GetString((byte[])v);
- }
- else if (v.GetType() == typeof(DateTime))
- {
- s = ((DateTime)v).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
- }
- else
- {
- s = v.ToString();
- }
- return (s);
- }
- else
- {
- return ("");
- }
- }
- catch
- {
- return ("");
- }
- }
- }
-}
diff --git a/CommonAuth_old/CommonAuth.csproj b/CommonAuth_old/CommonAuth.csproj
deleted file mode 100644
index 8008d62..0000000
--- a/CommonAuth_old/CommonAuth.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- net5.0
-
-
-
-
-
-
-
diff --git a/CommonAuth_old/MyADObject.cs b/CommonAuth_old/MyADObject.cs
deleted file mode 100644
index 040b45d..0000000
--- a/CommonAuth_old/MyADObject.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Configuration;
-
-
-namespace CommonAuth.Models
-{
- public class MyADObject
- {
- public string StafflinkNo { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public string Company { get; set; }
- public string Location { get; set; }
- public string Department { get; set; }
- public string JobTitle { get; set; }
- public string BadPwdCount { get; set; }
- public string Phone { get; set; }
- public string DisplayName { get; set; }
- public string Manager { get; set; }
- public string ReportsTo { get; set; }
- public string StaffList { get; set; }
- public string ManagerDetails { get; set; }
- public bool result { get; set; }
-
-
- }
-
-
-}