public UserPrincipal CheckADUser(string adUserName) { UserPrincipal usr = null; if (adUserName != null) { usr = new ActiveDirectoryManager().GetUserDetails(adUserName); if (usr != null) { var authTicket = new FormsAuthenticationTicket( version: 1, name: adUserName, issueDate: DateTime.Now, expiration: DateTime.Now.AddMinutes(10), isPersistent: false, userData: Convert.ToString(usr) ); return(usr); } else { return(usr); } } else { return(usr); } }
private static string Markdown(this Exception exception, Action <StringBuilder, Exception> appender = null) { string text = ExceptionExtensions.Markdown(exception, (sb, ex) => { if (ex is AdminkaException) { sb.AppendUserContextException((AdminkaException)ex); } #if NETSTANDARD2_1 DashboardCode.AdminkaV1.LoggingDom.WcfClient.WcfClientManager.AppendWcfClientFaultException(sb, ex); DashboardCode.AdminkaV1.LoggingDom.DataAccessEfCore.LoggingDomDataAccessEfCoreManager.Append(sb, ex); #endif #if NETSTANDARD2_1 DashboardCode.Routines.Storage.SqlServer.SqlServerManager.Append(sb, ex); #else DashboardCode.Routines.Storage.SystemSqlServer.SqlServerManager.Append(sb, ex); #endif ActiveDirectoryManager.Append(sb, ex); appender?.Invoke(sb, ex); } ); return(text); }
public AccountController() { using (var context = new AdContext()) { var config = context.DirectorySetups.AsNoTracking().FirstOrDefault(); var domain = config?.DomainName.Split('.'); if (domain != null) { _userManager = new ActiveDirectoryManager(config.IpAddress, $"DC={domain[0]},DC={domain[1]}", config.ServiceUserName, config.ServicePassword); } } }
public AccountController(UsersManager usersManager, TokenManager tokenManager, ActiveDirectoryManager activeDirectoryManager) { this._usersManager = usersManager; this._tokenManager = tokenManager; this._activeDirectoryManager = activeDirectoryManager; }
protected void btnLogin_Click(object sender, EventArgs e) { string hostName = Environment.MachineName + "\\" + Environment.UserName; Boolean isError = false; var errorMessage = ""; string nik; try { // If configuration settings for ActiveDirectoryVerification is set to true then verify user login using Active Directory Username and Password, call respective function and sp_AUTHENTICATION_LOGIN_CTI if (ConfigurationManager.AppSettings["ActiveDirectoryVerification"].ToLower() == "true") { if (ActiveDirectoryManager.ValidateUser(tbUsername.Text, tbPassword.Text)) { //get IP Address dari PC yang melakukan akses pada aplikasi CTI string ipAddress = Request.ServerVariables["REMOTE_ADDR"]; //email dapat digunakan untuk melakukan pengambilan data pada database BIOFARMA terkait info karyawan (in this case get NIK) nik = ActiveDirectoryManager.GetUserNumberByEmail(tbUsername.Text + "@biofarma.co.id"); _objUser = DbUser.SingleSignOnUserAuthentication(nik, hostName, ipAddress); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Username atau Password anda salah');", true); } } else { // else , verified it using stored Procedure sp_AUTHENTICATION_LOGIN, with username = nik and password is value within table USER_PASSWORD _objUser = DbUser.UserAuthentication(tbUsername.Text, tbPassword.Text, hostName, ""); } } catch (Exception ex) { isError = true; errorMessage = ex.Message; } if ((!isError) && (_objUser != null) && (_objUser.UserId != null && _objUser.UserId != "-1")) { Session.Timeout = 60; Session["biofarma_userid"] = _objUser.UserId; Session["biofarma_username"] = _objUser.Nama; Session["biofarma_positionid"] = _objUser.Posid; Session["biofarma_positionname"] = _objUser.PositionName; Session["biofarma_unitcode"] = _objUser.UnitCode; Session["biofarma_unitname"] = _objUser.UnitName; Session["biofarma_roleid"] = _objUser.RoleId; Session["biofarma_rolename"] = _objUser.RoleName; Session["biofarma_grade"] = _objUser.Grade; // store audit trail log for user success login DbUser.SetAuditTrailApplicationLogin(_objUser.UserId, tbUsername.Text, "1"); //Server.Transfer("~/Default.aspx"); Response.Redirect("Pages/Default.aspx", true); } else { // get user nik from its mail address nik = ActiveDirectoryManager.GetUserNumberByEmail(tbUsername.Text + "@biofarma.co.id"); // store audit trail log for user failed login attempt DbUser.SetAuditTrailApplicationLogin(nik ?? "", tbUsername.Text, "2"); if (_objUser != null && (string.IsNullOrEmpty(_objUser.UserId) || _objUser.UserId == "-1")) { ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Username atau Password anda salah');", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('" + errorMessage + "');", true); } } }