235 lines
8.5 KiB
C#
235 lines
8.5 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Web.UI;
|
|
|
|
/// <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()
|
|
{
|
|
logger.lg.scriviLog(string.Format("Inizio procedura login..."), tipoLog.INFO);
|
|
lblMessage.Text = traduci("UserNotAuth");
|
|
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);
|
|
// passo al controllo di verifica ADuserOk...
|
|
user_std _utente = new user_std();
|
|
if (_utente.ADuserOk(dom_user[0], dom_user[1]))
|
|
{
|
|
bool fatto = _utente.startUpUtente(dom_user[0], dom_user[1]);
|
|
if (fatto)
|
|
{
|
|
logger.lg.scriviLog(string.Format("L'utente {0} ({1}) ha effettuato il login correttamente", _utente.CognomeNome, _utente.userNameAD), tipoLog.INFO);
|
|
if (Login_ok != null)
|
|
{
|
|
Login_ok(this, new EventArgs());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = String.Format("{0}<br>There are some problems instatiating user: {1}/{2}", user_std.UtSn.Traduci("AccessFail"), dom_user[0], dom_user[1]);
|
|
logger.lg.scriviLog(String.Format("Accesso fallito, problemi ad istanziare l'utente {0}/{1}", dom_user[0], dom_user[1]), tipoLog.ERROR);
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (memLayer.ML.confReadBool("autoEnrollEnabled"))
|
|
{
|
|
// rimando al modulo di auto enroll...
|
|
Response.Redirect("autoEnroll.aspx");
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = String.Format("{0}<br>user not allowed: {1}/{2}", user_std.UtSn.Traduci("AccessFail"), dom_user[0], dom_user[1]);
|
|
logger.lg.scriviLog(String.Format("Utente non autorizzato: {0}/{1}", dom_user[0], dom_user[1]), tipoLog.WARNING);
|
|
if (Login_Error != null)
|
|
{
|
|
Login_Error(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblMessage.Text = user_std.UtSn.Traduci("AccessFail") + user_std.UtSn.Traduci("UsrNotAuth");
|
|
logger.lg.scriviLog(String.Format("Accesso fallito, utente non autenticato"), 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 == "triplete") // 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, 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, 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, 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, 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)
|
|
{
|
|
base.Page_Load(sender, e);
|
|
//carico da web.config i default values
|
|
loadDefaultsWebConfig();
|
|
// procedo...
|
|
setLoginMode();
|
|
Session.RemoveAll();
|
|
if (_isForceUser == SteamWare.loginMode.normale)
|
|
{
|
|
AdLogin();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|