241 lines
9.2 KiB
C#
241 lines
9.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using SteamWare;
|
|
|
|
namespace Equa_Auth.WebUserControls
|
|
{
|
|
/// <summary>
|
|
/// classe gestione login e forzatura login
|
|
/// </summary>
|
|
public partial class mod_login : ApplicationUserControl
|
|
{
|
|
#region area protected/private
|
|
|
|
#region area proprietà
|
|
|
|
private SteamWare.loginMode _isForceUser = SteamWare.loginMode.normale;
|
|
|
|
#endregion
|
|
|
|
#region area metodi
|
|
|
|
/// <summary>
|
|
/// imposta la modalità di login tra normale / forceUser
|
|
/// </summary>
|
|
private void setLoginMode()
|
|
{
|
|
if (_isForceUser == SteamWare.loginMode.forceUser)
|
|
{
|
|
pnlForceUser.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
pnlForceUser.Visible = false;
|
|
}
|
|
}
|
|
|
|
protected override void traduciObj()
|
|
{
|
|
lblPwd.Text = user_std.UtSn.Traduci("lblPwd");
|
|
lblUser.Text = user_std.UtSn.Traduci("lblUser");
|
|
lblDominio.Text = user_std.UtSn.Traduci("lblDominio");
|
|
lblTitolo.Text = user_std.UtSn.Traduci("ForzaUtente");
|
|
btnOk.Text = user_std.UtSn.Traduci("btnCommit");
|
|
}
|
|
|
|
/// <summary>
|
|
/// prova a verificare se l'utente sia ok x AD credentials
|
|
/// </summary>
|
|
private void AdLogin()
|
|
{
|
|
lblMessage.Text = "User not authenticated...";
|
|
if (Page.User.Identity.IsAuthenticated)
|
|
{
|
|
//recupera user windows se c'è...
|
|
string ad_name = Page.User.Identity.Name;
|
|
string delimStr = "\\";
|
|
char[] delimiter = delimStr.ToCharArray();
|
|
string[] dom_user = ad_name.Split(delimiter, 2);
|
|
// salvo cookie!
|
|
string DeviceName = "";
|
|
string IPv4 = "";
|
|
string userAgent = "";
|
|
try
|
|
{
|
|
userAgent = Request.UserAgent;
|
|
DeviceName = Request.UserHostName;
|
|
IPv4 = Request.UserHostName;
|
|
}
|
|
catch
|
|
{ }
|
|
if (memLayer.ML.confReadBool("enableCookie"))
|
|
{
|
|
// elimino eventuali altri cookie x dominio/user/devName
|
|
//DataWrap.DW.taAnagDev.delByDominioUserDeviceName(dom_user[0], dom_user[1], DeviceName);
|
|
// creo nuovo cookie
|
|
authProxy.createNewCookie(dom_user[0], dom_user[1], 0, DeviceName, userAgent, IPv4, Page.Request.QueryString["AuthCookie"].ToString(), DateTime.Now.AddDays(memLayer.ML.confReadInt("cookieDayExp")));
|
|
}
|
|
// loggo
|
|
SteamWare.logger.lg.scriviLog(string.Format("L'utente {0}/{1} ha effettuato il login correttamente", dom_user[0], dom_user[1]), SteamWare.tipoLog.INFO);
|
|
if (Login_ok != null)
|
|
{
|
|
Login_ok(this, new EventArgs());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = user_std.UtSn.Traduci("AccessFail") + user_std.UtSn.Traduci("UsrNotAuth");
|
|
SteamWare.logger.lg.scriviLog(String.Format("Accesso fallito, utente non autenticato"), SteamWare.tipoLog.WARNING);
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua verifiche e se concesso permette di forzare l'accesso utente
|
|
/// </summary>
|
|
private void ForceUserIdentity()
|
|
{
|
|
if (Page.User.Identity.IsAuthenticated)
|
|
{
|
|
bool _allowForceUser = false;
|
|
try
|
|
{
|
|
_allowForceUser = SteamWare.memLayer.ML.confReadBool("_allowForceUser");
|
|
}
|
|
catch
|
|
{
|
|
_allowForceUser = false;
|
|
}
|
|
if (_allowForceUser)
|
|
{
|
|
if (authKey.Text == "forzaInter") // verifica passphrase...
|
|
{
|
|
user_std _utente = new user_std();
|
|
user_std.UtSn.isForcedUser = true;
|
|
bool fatto = _utente.startUpUtente(dominio.Text, user.Text);
|
|
if (fatto)
|
|
{
|
|
string _rigaLog = String.Format("User {0} has forced user identity ok: logged as \t {1}\\{2}", Page.User.Identity.Name, dominio.Text, user.Text);
|
|
SteamWare.logger.lg.scriviLog(_rigaLog, SteamWare.tipoLog.INFO);
|
|
if (Login_ok != null)
|
|
{
|
|
Login_ok(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = String.Format("{0}<br>key not allowed for operation!!! operation logged!!!", user_std.UtSn.Traduci("AccessFail"));
|
|
mandaEmail(_fromEmail, _adminEmail, "Attenzione: tentativo di accesso non autorizzato!", String.Format("Tentativo di forcing user non autorizzato!<br>L'utente {0} ha tentato di accedere a {1} forzando l'utente ma la sua key autorizzativa e' sbagliata...", Page.User.Identity.Name, user_std.UtSn.Traduci(SteamWare.memLayer.ML.confReadString("defaultApp"))));
|
|
string _rigaLog = String.Format("User {0}\t tried to force user - wrong password - he tried to log as \t {1}\\{2}", Page.User.Identity.Name, dominio.Text, user.Text);
|
|
SteamWare.logger.lg.scriviLog(_rigaLog, SteamWare.tipoLog.WARNING);
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mandaEmail(_fromEmail, _adminEmail, "Attenzione: tentativo di accesso non autorizzato!", String.Format("Tentativo di forcing user non autorizzato!<br>L'utente {0} ha tentato di accedere a {1} forzando l'utente ma la funzione e' disabilitata...", Page.User.Identity.Name, user_std.UtSn.Traduci(SteamWare.memLayer.ML.confReadString("defaultApp"))));
|
|
string _rigaLog = String.Format("User {0}\t tried to force user - access disabled - he tried to log as \t {1}\\{2}", Page.User.Identity.Name, dominio.Text, user.Text);
|
|
SteamWare.logger.lg.scriviLog(_rigaLog, SteamWare.tipoLog.WARNING);
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = string.Format("{0}<br>user not authenticated!<br>", user_std.UtSn.Traduci("AccessFail"));
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
string _rigaLog = String.Format("\t Someone tried to force user - real user: \t - not autenticated - \t tried to log as \t {0}\\{1}", dominio.Text, user.Text);
|
|
SteamWare.logger.lg.scriviLog(_rigaLog, SteamWare.tipoLog.WARNING);
|
|
}
|
|
}
|
|
|
|
protected void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
ForceUserIdentity();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region area public
|
|
|
|
#region eventi pubblici esposti
|
|
|
|
public event EventHandler Login_ok;
|
|
public event EventHandler Login_Error;
|
|
|
|
#endregion
|
|
|
|
#region area proprietà
|
|
|
|
/// <summary>
|
|
/// modalità funzionamento controllo tra normale (ActiveDirectory e user auth di default) e forceUser
|
|
/// </summary>
|
|
public SteamWare.loginMode modoLogin
|
|
{
|
|
get
|
|
{
|
|
return _isForceUser;
|
|
}
|
|
set
|
|
{
|
|
_isForceUser = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// avvio pagina
|
|
/// </summary>
|
|
protected override void Page_Load(object sender, EventArgs e)
|
|
{
|
|
//carico da web.config i default values
|
|
loadDefaultsWebConfig();
|
|
// procedo...
|
|
setLoginMode();
|
|
Session.RemoveAll();
|
|
if (_isForceUser == SteamWare.loginMode.normale)
|
|
{
|
|
bool cookieLogin = false;
|
|
if (memLayer.ML.confReadBool("enableCookie"))
|
|
{
|
|
string cookieName = Page.Request.QueryString["AuthCookie"].ToString();
|
|
cookieLogin = authProxy.tryAuthByCookie(cookieName);
|
|
}
|
|
if (!cookieLogin)
|
|
{
|
|
AdLogin();
|
|
}
|
|
else
|
|
{
|
|
if (Login_ok != null)
|
|
{
|
|
Login_ok(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |