/// <summary> /// Crea un Log valido /// </summary> public LogTransazione(AzioneUtente azioneUtente, Computer computer, IpAddress clientIp, Utente utente, ComputerVersion version) { AzioneUtente = azioneUtente; Computer = computer; ClientIp = clientIp; Version = version; Utente = utente; Data = DateTime.Now; }
public LogTransazione AddLog(Utente utente, ComputerDTO computerDto, IpAddress clientIp, AzioneUtente azioneUtente) { try { var azienda = _daoFactory.GetAziendaDao().GetById(utente.AziendaID.GetValueOrDefault(), false); var version = new ComputerVersion { FrameworkVersion = computerDto.FrameworkVersion, FrameworkServicePack = computerDto.FrameworkServicePack, OsBits = computerDto.OsBits, OsEdition = computerDto.OsEdition, OsName = computerDto.OsName, OsServicePack = computerDto.OsServicePack, OsVersionString = computerDto.OsVersionString, ProcessorBits = computerDto.ProcessorBits }; var computer = _daoFactory.GetComputerDao().GetByNomeAzienda(computerDto.ComputerName, azienda.ID); if (computer != null) { computer.Version = version; computer.UltimoLogin = DateTime.Now; _daoFactory.GetComputerDao().SaveOrUpdate(computer); } else { computer = new Computer(computerDto.ComputerName, version, azienda); _daoFactory.GetComputerDao().SaveOrUpdate(computer); } var logTransazione = new LogTransazione(azioneUtente, computer, clientIp, utente, version); _daoFactory.GetLogTransazioneDao().SaveOrUpdate(logTransazione); return logTransazione; } catch (Exception ex) { _log.ErrorFormat("Errore inaspettato durante log della transazione - {0} - azione:{1}", ex, Library.Utility.GetMethodDescription() ,azioneUtente); return null; } }
public UtenteVerificaDTO VerifyUser(string codiceAzienda, string username, string password, ComputerDTO computerInfo, out IWindsorContainer container) { try { IDaoFactory daoFactory = null; container = null; var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Login.Instance.Key, Login.Instance.IV); username = sc.Decrypt(username); password = sc.Decrypt(password); var windsorConfigRepository = new WindsorConfigRepository(); Azienda azienda = null; if (!string.IsNullOrEmpty(codiceAzienda)) { try { codiceAzienda = sc.Decrypt(codiceAzienda); container = windsorConfigRepository.GetContainer(codiceAzienda); daoFactory = windsorConfigRepository.GetDaoFactory(codiceAzienda); if(daoFactory != null) azienda = daoFactory.GetAziendaDao().GetByCodice(codiceAzienda); else return null; } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - {0} - codiceAzienda:{1} - user:{2} - pwd:{3}", ex, Utility.GetMethodDescription(), codiceAzienda, username, password); throw; } } else { var userAzienda = username.Split('&'); if (userAzienda.Length == 2) { codiceAzienda = userAzienda[1]; container = windsorConfigRepository.GetContainer(codiceAzienda); username = userAzienda[0]; daoFactory = windsorConfigRepository.GetDaoFactory(codiceAzienda); azienda = daoFactory.GetAziendaDao().GetByCodice(codiceAzienda); } } if (azienda != null || string.IsNullOrEmpty(codiceAzienda)) { IList<Utente> users = new List<Utente>(); if (azienda != null) { container = windsorConfigRepository.GetContainer(azienda.ID); users = daoFactory.GetUtenteDao().GetByAzienda(username, password, azienda); } else { // Mi trovo nel caso di validare la password principale, l'utente principale si trova sempre nell'azienda principale "ZETH" try { daoFactory = windsorConfigRepository.GetDaoFactory("ZETH"); container = windsorConfigRepository.GetContainer("ZETH"); var utente = daoFactory.GetUtenteDao().GetByUsername(username, codiceAzienda); if (utente.Password == password) users.Add(utente); } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - ZETH - {0} - user:{1} - pwd:{2} - codiceAzienda:{3}", ex, Utility.GetMethodDescription(), username, password, codiceAzienda); throw; } } if (users.Count > 0) { if (users.Count > 1) _log.ErrorFormat("Trovati più di un utente con stesso username e stessa password - {0} - user:{1} - pwd:{2}", Utility.GetMethodDescription(), username, password); int? idAzienda = null; if (azienda != null) idAzienda = azienda.ID; // Memorizzo log di login if (azienda != null && computerInfo != null) { try { if (container != null) { var context = OperationContext.Current; var messageProperties = context.IncomingMessageProperties; var endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; IpAddress clientIp = null; if (endpointProperty != null) clientIp = new IpAddress { IpNumber = endpointProperty.Address, IpPort = endpointProperty.Port }; var logService = container.Resolve<ILogTransazioneService>(); logService.AddLog(users[0], computerInfo, clientIp, AzioneUtente.Login); } } catch (Exception ex) { _log.ErrorFormat("Errore nella memorizzazione di informazioni sul computer di collegamento - {0} - user:{1} - password:{2} - nomeComputer:{3} - versioneSO:{4} - versioneFramework:{5}", ex, Utility.GetMethodDescription(), username, password, computerInfo.ComputerName, computerInfo.OsVersionString, computerInfo.FrameworkVersion); } } var utenteVerificaDTO = new UtenteVerificaDTO { Id = users[0].ID, Username = users[0].Username, Password = users[0].Password, IdAzienda = idAzienda }; if (users[0].Referente != null) { utenteVerificaDTO.Cognome = users[0].Referente.PersonaRiferimento.Cognome; utenteVerificaDTO.Nome = users[0].Referente.PersonaRiferimento.Nome; } else { utenteVerificaDTO.Cognome = users[0].Cognome; utenteVerificaDTO.Nome = users[0].Nome; } return utenteVerificaDTO; } return null; } return null; } catch (Exception ex) { _log.ErrorFormat("Errore nel riconoscimento dell'utente - {0} - codiceAzienda:{1} - user:{2} - pwd:{3}", ex, Utility.GetMethodDescription(), codiceAzienda, username, password); throw; } }