public List <OperationDto> GetAllUserOperations(int securityUserId, long securityResourceId)
        {
            List <OperationDto>   operations = new List <OperationDto>();
            SecurityUserBussiness userBs     = new SecurityUserBussiness();
            ResourceBussiness     resourceBa = new ResourceBussiness();
            GroupBussiness        groupBa    = new GroupBussiness();
            var resource = resourceBa.GetSingle(it => it.SecurityResourceId == securityResourceId);
            var user     = userBs.GetUserById(securityUserId);
            var userOps  = UserOperations(user, resource);

            operations.AddRange(userOps.OperationDtoList);
            foreach (var role in user.Roles)
            {
                var roleOps = RoleOperations(role, resource);
                foreach (var roleOp in roleOps.OperationDtoList)
                {
                    if (!operations.Exists(it => it.OperationId == roleOp.OperationId))
                    {
                        operations.Add(roleOp);
                    }
                }
            }
            foreach (var group in user.Groups)
            {
                var roles = groupBa.AssignedRoles(group.SecurityGroupId);
                foreach (var role in roles.RoleDtoList)
                {
                    var roleOps = RoleOperations(role, resource);
                    foreach (var roleOp in roleOps.OperationDtoList)
                    {
                        if (!operations.Exists(it => it.OperationId == roleOp.OperationId))
                        {
                            operations.Add(roleOp);
                        }
                    }
                }
            }
            return(operations);
        }
        public Common.Message.AuthenticationResult Authenticate(Common.Message.SignInMessage message)
        {
            Common.Message.AuthenticationResult result = new Common.Message.AuthenticationResult();
            SecurityUserBussiness userBs = new SecurityUserBussiness();

            var userAccount = ((AccountTDataAccess)this.dataAccess).CheckAccount(message.UserName, int.Parse(message.ClientId));

            if (userAccount != null)
            {
                var user = userBs.GetSingle(it => it.UserId == userAccount.UserId);
                if (user == null || user.IsLocked)
                {
                    result.ErrorMessage = " کاربر بطور موقت قفل است!";
                    UserLogGenerator.GenerateUserLog("-1", "-1", "", message.ClientId, "Authenticate", message.UserName, "faild login.user not exist");
                    return(result);
                }
                if (userAccount.IsEnabled)
                {
                    if (userAccount.IsActiveDirectory > 0)
                    {
                        //TODO: Active directory check
                    }
                    else
                    {
                        if (userAccount.ExpiredDate == null || userAccount.ExpiredDate > DateTime.Now)
                        {
                            string hashed = ISE.Framework.Server.Common.Security.EncryptionAlgorithm.CreateHMACMD5(message.PlainPassword, message.UserName);
                            if (userAccount.Password.Equals(hashed))
                            {
                                IdentityTokenGenerator generator = new IdentityTokenGenerator();
                                var token = generator.GenerateToken(userAccount, message);
                                result.IdentityToken = token;
                                UserLogGenerator.GenerateUserLog(token.SessionId, token.SubjectId, userAccount.AccountId.ToString(), message.ClientId, "Authenticate", message.UserName, "success login");
                            }
                            else
                            {
                                result.ErrorMessage = "رمز عبور اشتباه است";
                                UserLogGenerator.GenerateUserLog("-1", userAccount.UserId.ToString(), userAccount.AccountId.ToString(), message.ClientId, "Authenticate", message.UserName, "failed login.incorrect password.");
                            }
                        }
                        else
                        {
                            result.ErrorMessage = "کاربر منقضی شده است!";
                            UserLogGenerator.GenerateUserLog("-1", userAccount.UserId.ToString(), userAccount.AccountId.ToString(), message.ClientId, "Authenticate", message.UserName, "failed login.expired account.");
                        }
                    }
                }
                else
                {
                    result.ErrorMessage = " حساب کاربری غیرفعال است!";
                    UserLogGenerator.GenerateUserLog("-1", "-1", "", message.ClientId, "Authenticate", message.UserName, "faild login.user not exist");
                }
            }
            else
            {
                result.ErrorMessage = "اطلاعات حساب کاربری اشتباه است!";
                UserLogGenerator.GenerateUserLog("-1", "-1", "", message.ClientId, "Authenticate", message.UserName, "faild login.user not exist");
            }

            return(result);
        }