Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        public UtenteDTO VerifyUser(string codiceAzienda, string username, string password)
        {
            try
            {
                var sc = new SymmetricCryptography<TripleDESCryptoServiceProvider>(Gipasoft.Security.Login.Instance.Key, Gipasoft.Security.Login.Instance.IV);

                var frameworkVersion = string.Empty;
                var frameworkServicePack = string.Empty;

                try
                {
                    var fx40ClientInstalled = FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx40C);
                    var fx40FullInstalled = FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx40F);
                    if (fx40ClientInstalled)
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; ";
                        frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx40C) + "C";
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx40C);
                        if (sp > -1)
                            frameworkServicePack += sp + "C";
                    }
                    if (fx40FullInstalled)
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx40F) + "F";
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx40F);
                        if (sp > -1)
                            frameworkServicePack += sp + "F";

                    }
                    else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx35))
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx35).ToString();
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx35);
                        if (sp > -1)
                            frameworkServicePack += sp.ToString();

                    }
                    else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx30))
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx30).ToString();
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx30);
                        if (sp > -1)
                            frameworkServicePack += sp.ToString();

                    }
                    else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx20))
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx20).ToString();
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx20);
                        if (sp > -1)
                            frameworkServicePack += sp.ToString();

                    }
                    else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx11))
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx11).ToString();
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx11);
                        if (sp > -1)
                            frameworkServicePack += sp.ToString();

                    }
                    else if (FrameworkVersionDetection.IsInstalled(FrameworkVersion.Fx10))
                    {
                        if (!string.IsNullOrEmpty(frameworkVersion))
                            frameworkVersion += "; ";
                        if (!string.IsNullOrEmpty(frameworkServicePack))
                            frameworkServicePack += "; "; frameworkVersion += FrameworkVersionDetection.GetExactVersion(FrameworkVersion.Fx10).ToString();
                        var sp = FrameworkVersionDetection.GetServicePackLevel(FrameworkVersion.Fx10);
                        if (sp > -1)
                            frameworkServicePack += sp.ToString();

                    }
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Errore nella lettura del framework corrente - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda);
                }

                var computerName = Environment.MachineName;
                var computer = new ComputerDTO();
                try
                {
                    computer.ComputerName = computerName;
                    computer.FrameworkVersion = frameworkVersion;
                    computer.FrameworkServicePack = frameworkServicePack;
                    computer.OsBits = OSVersionInfo.OSBits.ToString();
                    computer.OsEdition = OSVersionInfo.Edition;
                    computer.OsName = OSVersionInfo.Name;
                    computer.OsServicePack = OSVersionInfo.ServicePack;
                    computer.OsVersionString = OSVersionInfo.VersionString;
                    computer.ProcessorBits = OSVersionInfo.ProcessorBits.ToString();
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Errore nella lettura della versione del SO corrente - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda);
                }

                var utente = getServiceClient().VerificaUtente(sc.Encrypt(codiceAzienda), sc.Encrypt(username), sc.Encrypt(password), computer);
                getServiceClient().Close();
                return utente;
            }
            catch (EndpointNotFoundException ex)
            {
                _log.FatalFormat("Errore nella lettura del framework corrente - ENDPOINNOTFOUND - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Gipasoft.Security.Login.Instance.CurrentLogin().Azienda);
                throw;
            }
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
		public UtenteDTO VerificaUtente(string codiceAzienda, string username, string password, ComputerDTO computerInfo)
		{
            var windsorRep = new WindsorConfigRepository();
			try
			{
                var repo = new AziendaRepository();
				IWindsorContainer container;
                var utenteVerifica = repo.VerifyUser(codiceAzienda, username, password, computerInfo, out container);
				UtenteDTO utente = null;

				if (utenteVerifica != null)
				{
					utente = repo.GetUtenteById(utenteVerifica.Id, container);
					utente.IdAzienda = utenteVerifica.IdAzienda.GetValueOrDefault();
                    _log.InfoFormat("L'utente: {0} si è collegato.", utente.Username);
                    windsorRep.Commit();
                }
				else
				{
                    _log.InfoFormat("L'utente: {0} ha tentato il collegamento con la password: {1}", username, password);
				}

				return utente;
			}
			catch (Exception ex)
			{
				_log.ErrorFormat("Errore nel riconoscimento dell'utente - {0}", ex, Utility.GetMethodDescription());
				throw;
			}
		}