Ejemplo n.º 1
0
        AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string chalenge)
        {
            IDataManager dm = EntityManager.FromDataBaseService(ServiceName.MyDataService);

            IEntityManager em = dm as IEntityManager;

            List <User> users = dm.GetEntities <User>(new QueryCriteria(User.Fields.Email, ComparisonOperator.Equal, userName.ToLower().Trim()));

            if (users.Count > 0)
            {
                User user = users[0];

                bool match = PasswordHasher.CheckResponse(user.Password, chalenge, algorithm, secret);

                if (match && user.Status != EnumUserStatus.Blocked)
                {
                    Dictionary <string, object> dicoProfiles = new Dictionary <string, object>();

                    List <string> roles = new List <string>();

                    roles.Add("Registered");

                    return(AspectizeUser.GetAuthenticatedUser(user.Id.ToString("N"), null, roles.ToArray(), dicoProfiles));
                }
            }

            return(AspectizeUser.GetUnAuthenticatedUser());
        }
Ejemplo n.º 2
0
        AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string challenge)
        {
            IDataManager dm = EntityManager.FromDataBaseService(DataBaseService);

            List <User> users = dm.GetEntities <User>(new QueryCriteria(User.Fields.UserName, ComparisonOperator.Equal, userName.ToLower().Trim()));

            if (users.Count > 0)
            {
                User user = users[0];

                bool match = PasswordHasher.CheckResponse(user.Password, challenge, algorithm, secret);

                if (match)
                {
                    Dictionary <string, object> dicoProperties = new Dictionary <string, object>();

                    dicoProperties.Add("UserName", user.UserName);

                    List <string> roles = new List <string>();

                    roles.Add("Registered");

                    user.DateLastLogin = DateTime.Now;

                    dm.SaveTransactional();

                    return(AspectizeUser.GetAuthenticatedUser(user.Id.ToString(), null, roles.ToArray(), dicoProperties));
                }
            }

            return(AspectizeUser.GetUnAuthenticatedUser());
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
0
 AspectizeUser IAuthentication.Authenticate(string userName, string secret, AuthenticationProtocol protocol, HashHelper.Algorithm algorithm, string challenge)
 {
     return(AspectizeUser.GetUnAuthenticatedUser());
 }