Beispiel #1
0
        bool IPersistentAuthentication.ValidateUser(AspectizeUser user)
        {
            IDataManager dm = EntityManager.FromDataBaseService(ServiceName.MyDataService);

            Guid userId = new Guid(user.UserId);

            User appliUser = dm.GetEntity <User>(userId);

            if (appliUser != null && appliUser.Status != EnumUserStatus.Blocked)
            {
                appliUser.DateLastLogin = DateTime.Now;

                var roles = new List <string>();

                roles.Add("Registered");

                user.SetRoles(roles);

                return(true);
            }
            return(false);
        }
Beispiel #2
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public DataSet GetListeExportsForCurrentUser()
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

            if (aspectizeUser.IsAuthenticated)
            {
                int    nTimosSessionId = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId];
                string keyUser         = (string)aspectizeUser[CUserTimosWebApp.c_champUserKey];

                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetSession(nTimosSessionId);
                if (!result)
                {
                    throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
                }

                try
                {
                    result = serviceClientAspectize.GetExportsForUser(nTimosSessionId, keyUser);
                    if (!result)
                    {
                        throw new SmartException(1010, "Erreur GetExportsForUser(nTimosSessionId = " + nTimosSessionId + ", keyUser = "******")" +
                                                 Environment.NewLine +
                                                 result.MessageErreur);
                    }

                    if (result && result.Data != null)
                    {
                        DataSet ds = result.Data as DataSet;

                        if (ds != null && ds.Tables.Contains(CExportWeb.c_nomTable))
                        {
                            DataTable dt = ds.Tables[CExportWeb.c_nomTable];

                            foreach (DataRow row in dt.Rows)
                            {
                                var export = em.CreateInstance <Export>();
                                export.Id           = (string)row[CExportWeb.c_champId];
                                export.Libelle      = (string)row[CExportWeb.c_champLibelle];
                                export.Description  = (string)row[CExportWeb.c_champDescription];
                                export.UpdatePeriod = (int)row[CExportWeb.c_champPeriode];

                                var    fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                                string relativePath = export.Id + ".json";
                                string fullPath     = fs.GetFileUrl(relativePath);
                                fullPath = fullPath.Substring(16);
                                if (File.Exists(fullPath))
                                {
                                    export.DataDate = File.GetLastWriteTime(fullPath);
                                }
                                else
                                {
                                    export.DataDate = null;
                                }
                            }
                        }


                        em.Data.AcceptChanges();
                        return(em.Data);
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportsForUser(nTimosSessionId = " + nTimosSessionId + ", keyUser = "******")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(null);
        }
Beispiel #3
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public DataSet GetExportForDisplay(string keyExport, string strLibelle, string strDescription)
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

            if (aspectizeUser.IsAuthenticated)
            {
                int nTimosSessionId = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId];

                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetSession(nTimosSessionId);
                if (!result)
                {
                    throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
                }
                try
                {
                    IFileService fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                    string       relativePath = keyExport + ".json";
                    string       fullPath     = fs.GetFileUrl(relativePath);
                    fullPath = fullPath.Substring(16);
                    if (File.Exists(fullPath))
                    {
                        byte[]  buffer      = fs.ReadBytes(relativePath);
                        string  jsonLecture = Encoding.ASCII.GetString(buffer);
                        DataSet dsExport    = JsonConvert.DeserializeObject <DataSet>(jsonLecture);

                        if (dsExport != null && dsExport.Tables.Count > 0)
                        {
                            Export export = em.CreateInstance <Export>();
                            export.Id          = keyExport;
                            export.Libelle     = strLibelle;
                            export.Description = strDescription;
                            export.DataDate    = File.GetLastWriteTime(fullPath);

                            // Extraction des données du DataSet
                            DataTable tableExport = dsExport.Tables[0]; // On traite uniquement la première table
                            int       nIndexCol   = 1;                  // Les 10 premières colonnes uniquement
                            foreach (DataColumn col in tableExport.Columns)
                            {
                                export.data["COL" + nIndexCol] = col.ColumnName;
                                nIndexCol++;
                                if (nIndexCol > 10)
                                {
                                    break;
                                }
                            }
                            // Traitement des données (lignes)
                            int nIndexRow = 0;
                            foreach (DataRow row in tableExport.Rows)
                            {
                                string      strIdCompose = keyExport + "#" + nIndexRow++;
                                ExportDatas expData      = em.GetInstance <ExportDatas>(strIdCompose);
                                if (expData == null)
                                {
                                    expData    = em.CreateInstance <ExportDatas>();
                                    expData.Id = strIdCompose;
                                    em.AssociateInstance <RelationExportDatas>(export, expData);
                                }
                                for (int i = 0; i < tableExport.Columns.Count && i < 10; i++)
                                {
                                    if (row[i] == DBNull.Value)
                                    {
                                        expData.data[i + 1] = "";
                                    }
                                    else
                                    {
                                        expData.data[i + 1] = row[i];
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportForDisplay(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            em.Data.AcceptChanges();
            return(em.Data);
        }
Beispiel #4
0
        void ILog.WriteLog(TraceInfo traceInfo)
        {
            if (traceInfo.Level < 0)
            {
                if (!ExecutingContext.CurrentHostUrl.ToLower().StartsWith(@"http://localhost"))
                {
                    bool messageTooLong = traceInfo.Message.Length > 32000;

                    IDataManager dm = null;

                    IEntityManager em = null;

                    if (!string.IsNullOrEmpty(DataServiceName))
                    {
                        dm = EntityManager.FromDataBaseService(DataServiceName);

                        em = dm as IEntityManager;
                    }
                    else
                    {
                        em = EntityManager.FromDataSet(DataSetHelper.Create());
                    }

                    LogException logException = em.CreateInstance <LogException>();

                    logException.ApplicationName = traceInfo.ApplicationName;
                    logException.CommandName     = traceInfo.CommandName;
                    logException.InfoTypeName    = traceInfo.InfoTypeName;
                    logException.Message         = (messageTooLong) ? "" : traceInfo.Message;
                    logException.ServiceName     = traceInfo.ServiceName;
                    logException.DateException   = traceInfo.Received;
                    logException.UserAgent       = (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null && (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.UserAgent))) ? System.Web.HttpContext.Current.Request.UserAgent : "";

                    AspectizeUser aspectizeUser = ExecutingContext.CurrentUser;

                    if (aspectizeUser.IsAuthenticated && aspectizeUser["Email"] != null)
                    {
                        logException.UserName = aspectizeUser["Email"].ToString();
                    }
                    else
                    {
                        logException.UserName = "******";
                    }

                    if (messageTooLong && !string.IsNullOrEmpty(FileServiceName))
                    {
                        IFileService fs = ExecutingContext.GetService <IFileService>(FileServiceName);

                        Guid fileId = Guid.NewGuid();

                        string fileName = string.Format("Trace/{0}.txt", fileId);

                        logException.Message = string.Format("Message Exception is too long to be saved in entity, and is saved in file {0}", fileName);

                        MemoryStream stream = new MemoryStream();
                        StreamWriter writer = new StreamWriter(stream);
                        writer.Write(traceInfo.Message);
                        writer.Flush();
                        stream.Position = 0;

                        fs.Write(fileName, stream);
                    }

                    if (!string.IsNullOrEmpty(DataServiceName))
                    {
                        dm.SaveTransactional();
                    }

                    if (!string.IsNullOrEmpty(MailTo) && !string.IsNullOrEmpty(MailServiceName))
                    {
                        IAspectizeSMTPService smtpService = ExecutingContext.GetService <IAspectizeSMTPService>(MailServiceName);

                        string subject = string.Format("Bug : {0} {1}", traceInfo.ApplicationName, logException.UserName);

                        StringBuilder sb = new StringBuilder();

                        sb.AppendLine();
                        sb.AppendFormat("Date: {0}", traceInfo.Received);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Application: {0}", traceInfo.ApplicationName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Host: {0}", ExecutingContext.CurrentHostUrl);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null)
                        {
                            sb.AppendFormat("Url: {0}", System.Web.HttpContext.Current.Request.Url.AbsoluteUri);
                            sb.AppendLine("<br />");
                            sb.AppendLine();
                        }
                        sb.AppendFormat("UserAgent: {0}", logException.UserAgent);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Service: {0}", traceInfo.ServiceName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Command: {0}", traceInfo.CommandName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Message: {0}", (messageTooLong) ? logException.Message : traceInfo.Message.Replace("\r\n", "<br />"));
                        sb.AppendLine("<br />");

                        string emailContent = sb.ToString();

                        smtpService.SendMail(false, MailTo.Split(','), subject, emailContent, null);
                    }
                }
            }
        }
Beispiel #5
0
        //-------------------------------------------------------------------------------------------------------------------------
        // Authenticate user, using Security Service Configuration
        AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string challenge)
        {
            var parts = secret.Split('#');

            string otp = parts[0];
            //string password = string.Join("#", parts, 1, parts.Length - 1);
            string password = parts[1];
            string state    = parts[2];

            string messageLog =
                "== Authenticate Radius Step 2 ==============" + Environment.NewLine +
                "Timos user name : " + userName + Environment.NewLine +
                "Radius Host : " + m_strRadiusHost + Environment.NewLine +
                "Radius Port : " + m_nRadiusPort + Environment.NewLine +
                "Shared Key : " + m_strRadiusSharedKey + Environment.NewLine +
                "OTP : " + otp + Environment.NewLine +
                "STATE : " + state + Environment.NewLine;

            string reponseRadius = "Request not sent";

            if (userName != "youcef")
            {
                try
                {
                    reponseRadius = AdministrationService.AuthenticateRadius(m_strRadiusHost, m_nRadiusPort, m_strRadiusSharedKey, userName, otp, state);
                    messageLog   += "Radius response : " + reponseRadius + Environment.NewLine;
                }
                catch (Exception ex)
                {
                    messageLog += "Radius response : " + ex.Message + Environment.NewLine;
                }
                Context.Log(InfoType.Information, messageLog);

                var parts2 = reponseRadius.Split('#');
                if (parts2[0] != "2")
                {
                    return(AspectizeUser.GetUnAuthenticatedUser()); // L'authentification OTP a échoué
                }
            }
            else
            {
                messageLog += "Radius response : " + reponseRadius + Environment.NewLine;
                Context.Log(InfoType.Information, messageLog);
            }

            // Authentification TIMOS

            ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
            CResultAErreur            result = serviceClientAspectize.OpenSession(userName, password);

            if (result && result.Data is Dictionary <string, object> )
            {
                string strUserKey = "";

                // Build Key-Value attached to User
                Dictionary <string, object> dicoProperties = (Dictionary <string, object>)result.Data;

                strUserKey = (string)dicoProperties[CUserTimosWebApp.c_champUserKey];

                // Build Role List
                List <string> roles = new List <string>();

                roles.Add("Registered");

                // Build and return authenticated user with Properties and Roles
                return(AspectizeUser.GetAuthenticatedUser(strUserKey, roles.ToArray(), dicoProperties));
            }

            return(AspectizeUser.GetUnAuthenticatedUser());
            // Fin authentification TIMOS
        }
Beispiel #6
0
        //-------------------------------------------------------------------------------------------------------------------------
        // Get Profile (ie initial DataSet) of user, authenticated or not
        DataSet IUserProfile.GetUserProfile()
        {
            // Get current user
            AspectizeUser aspectizeUser = ExecutingContext.CurrentUser;

            if (aspectizeUser.IsAuthenticated)
            {
                IEntityManager em = EntityManager.FromDataSet(DataSetHelper.Create());

                // Initialise l'utilisateur connecté
                var user = em.CreateInstance <User>();
                user.IsAuthentificated = true;
                user.Name            = (string)aspectizeUser[CUserTimosWebApp.c_champUserName];
                user.Login           = (string)aspectizeUser[CUserTimosWebApp.c_champUserLogin];
                user.TimosKey        = (string)aspectizeUser[CUserTimosWebApp.c_champUserKey];
                user.TimosSessionId  = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId];
                user.IsAdministrator = (bool)aspectizeUser[CUserTimosWebApp.c_champIsAdministrator];

                // Instancie les To do de l'utilisateur en cours
                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetTodosForUser(user.TimosSessionId, user.TimosKey);

                if (result && result.Data != null)
                {
                    DataSet ds = result.Data as DataSet;
                    if (ds != null && ds.Tables.Contains(CTodoTimosWebApp.c_nomTable))
                    {
                        DataTable dt = ds.Tables[CTodoTimosWebApp.c_nomTable];

                        foreach (DataRow row in dt.Rows)
                        {
                            var todo = em.CreateInstance <Todos>();
                            todo.TimosId            = (int)row[CTodoTimosWebApp.c_champId];
                            todo.Label              = (string)row[CTodoTimosWebApp.c_champLibelle];
                            todo.StartDate          = (DateTime)row[CTodoTimosWebApp.c_champDateDebut];
                            todo.Instructions       = (string)row[CTodoTimosWebApp.c_champInstructions];
                            todo.ElementType        = (string)row[CTodoTimosWebApp.c_champTypeElementEdite];
                            todo.ElementId          = (int)row[CTodoTimosWebApp.c_champIdElementEdite];
                            todo.ElementDescription = (string)row[CTodoTimosWebApp.c_champElementDescription];
                            todo.DureeStandard      = (int)row[CTodoTimosWebApp.c_champDureeStandard];
                            int nEtat = (int)row[CTodoTimosWebApp.c_champEtatTodo];
                            todo.EtatTodo = (EtatTodo)nEtat;
                            if (row[CTodoTimosWebApp.c_champDateFin] == DBNull.Value)
                            {
                                todo.EndDate = null;
                            }
                            else
                            {
                                todo.EndDate = (DateTime)row[CTodoTimosWebApp.c_champDateFin];
                            }
                        }
                    }
                }

                // Récupère la liste des Actions globales disponibles pour cet utilisateur
                try
                {
                    result = serviceClientAspectize.GetActionsForUser(user.TimosSessionId, user.TimosKey);
                    if (!result)
                    {
                        throw new SmartException(1010, "Erreur GetExportsForUser(nTimosSessionId = " + user.TimosSessionId + ", keyUser = "******")" +
                                                 Environment.NewLine +
                                                 result.MessageErreur);
                    }

                    if (result && result.Data != null)
                    {
                        DataSet ds = result.Data as DataSet;

                        if (ds != null && ds.Tables.Contains(CActionWeb.c_nomTable))
                        {
                            DataTable dt = ds.Tables[CActionWeb.c_nomTable];

                            foreach (DataRow row in dt.Rows)
                            {
                                var action = em.CreateInstance <Action>();
                                action.Id           = (int)row[CActionWeb.c_champId];
                                action.Libelle      = (string)row[CActionWeb.c_champLibelle];
                                action.Instructions = (string)row[CActionWeb.c_champInstructions];
                                action.IsGlobale    = (bool)row[CActionWeb.c_champIsGlobale];
                                action.HasForm      = (bool)row[CActionWeb.c_champHasForm];

                                // Variables Texte
                                action.IDT1 = (string)row[CActionWeb.c_champIdVarText1];
                                action.IDT2 = (string)row[CActionWeb.c_champIdVarText2];
                                action.IDT3 = (string)row[CActionWeb.c_champIdVarText3];
                                action.IDT4 = (string)row[CActionWeb.c_champIdVarText4];
                                action.IDT5 = (string)row[CActionWeb.c_champIdVarText5];
                                action.IDT6 = (string)row[CActionWeb.c_champIdVarText6];
                                action.IDT7 = (string)row[CActionWeb.c_champIdVarText7];
                                action.IDT8 = (string)row[CActionWeb.c_champIdVarText8];
                                action.IDT9 = (string)row[CActionWeb.c_champIdVarText9];

                                action.LBLT1 = (string)row[CActionWeb.c_champLabelVarText1];
                                action.LBLT2 = (string)row[CActionWeb.c_champLabelVarText2];
                                action.LBLT3 = (string)row[CActionWeb.c_champLabelVarText3];
                                action.LBLT4 = (string)row[CActionWeb.c_champLabelVarText4];
                                action.LBLT5 = (string)row[CActionWeb.c_champLabelVarText5];
                                action.LBLT6 = (string)row[CActionWeb.c_champLabelVarText6];
                                action.LBLT7 = (string)row[CActionWeb.c_champLabelVarText7];
                                action.LBLT8 = (string)row[CActionWeb.c_champLabelVarText8];
                                action.LBLT9 = (string)row[CActionWeb.c_champLabelVarText9];

                                string strValeursVarText1 = (string)row[CActionWeb.c_champValeursVarText1];
                                string strValeursVarText2 = (string)row[CActionWeb.c_champValeursVarText2];
                                string strValeursVarText3 = (string)row[CActionWeb.c_champValeursVarText3];
                                string strValeursVarText4 = (string)row[CActionWeb.c_champValeursVarText4];
                                string strValeursVarText5 = (string)row[CActionWeb.c_champValeursVarText5];
                                string strValeursVarText6 = (string)row[CActionWeb.c_champValeursVarText6];
                                string strValeursVarText7 = (string)row[CActionWeb.c_champValeursVarText7];
                                string strValeursVarText8 = (string)row[CActionWeb.c_champValeursVarText8];
                                string strValeursVarText9 = (string)row[CActionWeb.c_champValeursVarText9];

                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText1, "T1");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText2, "T2");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText3, "T3");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText4, "T4");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText5, "T5");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText6, "T6");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText7, "T7");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText8, "T8");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarText9, "T9");

                                // Variables Int
                                action.IDN1  = (string)row[CActionWeb.c_champIdVarInt1];
                                action.IDN2  = (string)row[CActionWeb.c_champIdVarInt2];
                                action.IDN3  = (string)row[CActionWeb.c_champIdVarInt3];
                                action.LBLN1 = (string)row[CActionWeb.c_champLabelVarInt1];
                                action.LBLN2 = (string)row[CActionWeb.c_champLabelVarInt2];
                                action.LBLN3 = (string)row[CActionWeb.c_champLabelVarInt3];

                                string strValeursVarInt1 = (string)row[CActionWeb.c_champValeursVarInt1];
                                string strValeursVarInt2 = (string)row[CActionWeb.c_champValeursVarInt2];
                                string strValeursVarInt3 = (string)row[CActionWeb.c_champValeursVarInt3];
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarInt1, "N1");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarInt2, "N2");
                                TodosService.FillValeursVariableForAction(em, action, strValeursVarInt3, "N3");

                                // Variables Date
                                action.IDD1  = (string)row[CActionWeb.c_champIdVarDate1];
                                action.IDD2  = (string)row[CActionWeb.c_champIdVarDate2];
                                action.IDD3  = (string)row[CActionWeb.c_champIdVarDate3];
                                action.LBLD1 = (string)row[CActionWeb.c_champLabelVarDate1];
                                action.LBLD2 = (string)row[CActionWeb.c_champLabelVarDate2];
                                action.LBLD3 = (string)row[CActionWeb.c_champLabelVarDate3];
                                // Variables Bool
                                action.IDB1  = (string)row[CActionWeb.c_champIdVarBool1];
                                action.IDB2  = (string)row[CActionWeb.c_champIdVarBool2];
                                action.IDB3  = (string)row[CActionWeb.c_champIdVarBool3];
                                action.LBLB1 = (string)row[CActionWeb.c_champLabelVarBool1];
                                action.LBLB2 = (string)row[CActionWeb.c_champLabelVarBool2];
                                action.LBLB3 = (string)row[CActionWeb.c_champLabelVarBool3];
                            }
                        }

                        em.Data.AcceptChanges();
                        return(em.Data);
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010, "Erreur GetExportsForUser(nTimosSessionId = " + user.TimosSessionId + ", keyUser = "******")" +
                                             Environment.NewLine +
                                             result.MessageErreur);
                }

                em.Data.AcceptChanges();
                return(em.Data);
            }
            // No profile for unanthenticated user
            return(null);
        }
Beispiel #7
0
 bool IPersistentAuthentication.ValidateUser(AspectizeUser user)
 {
     return(false);
 }
Beispiel #8
0
 AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string challenge)
 {
     return(AspectizeUser.GetUnAuthenticatedUser());
 }