Example #1
0
        /// <summary>
        /// 获取客户端实例
        /// </summary>
        /// <returns></returns>
        public virtual ClientEntity GetClient(string clientUrl)
        {
            IEnumerable <ClientEntity> clientList = DataBaseUtils.getAllClient();

            foreach (ClientEntity client in clientList)
            {
                if (client.AppSvcUrl.Equals(clientUrl))
                {
                    return(client);
                }
            }
            throw new Exception("无效客户端");
        }
Example #2
0
        /// <summary>
        /// 获取所有客户端
        /// </summary>
        /// <returns></returns>
        public virtual bool ValideClient(string clientUrl)
        {
            IEnumerable <ClientEntity> clientList = DataBaseUtils.getAllClient();

            foreach (ClientEntity client in clientList)
            {
                if (client.AppSvcUrl.Equals(clientUrl))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
        /// <summary>
        /// 账号密码登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public virtual UserModel CheckLogin(string account, string password)
        {
            BaseUserEntity _entity = DataBaseUtils.GetUserEntity(account, password);
            CasLogEntity   log     = DataBaseUtils.casLoginLog(_entity);
            UserModel      user    = new UserModel();

            user.UserId   = _entity.UserId;
            user.Account  = _entity.Account;
            user.Password = _entity.Password;
            user.UserName = _entity.RealName;
            user.Code     = _entity.EnCode;
            user.LogTime  = DateTime.Now;
            user.CasLogId = log == null ? "" : log.CasLogId;
            return(user);
        }
Example #4
0
        /// <summary>
        /// 退出所有的客户端
        /// </summary>
        /// <param name="user">redis中存的用户</param>
        /// <param name="clients">用户的权限客户端</param>
        /// <param name="UnClearSessionId">不清理的sessionid,防止用户DoLogout登出本用户</param>
        public virtual void LogoutAllAction(UserModel user, List <ClientEntity> clients, string UnClearSessionId)
        {
            DataBaseUtils.casLogoutLog(user);

            if (clients != null && user.Clients != null)
            {
                foreach (ClientEntity _client in clients)
                {
                    ClientModel clientModel = user.Clients.Find(t => t.ClientId == _client.AppId && t.SessionIdValue != UnClearSessionId);
                    if (clientModel != null)
                    {
                        postLogout(clientModel, _client.LogoutUrl);
                    }
                }
            }
        }
Example #5
0
 /// <summary>
 /// 退出客户端post
 /// </summary>
 /// <param name="client"></param>
 /// <param name="logoutUrl"></param>
 private void postLogout(ClientModel client, string logoutUrl)
 {
     try
     {
         //数据库日志
         DataBaseUtils.clientLogoutLog(client);
         //清除客户端与cas的绑定
         if (GrobalConfig.IsApiCheck)
         {
             RedisDelClient(client.SessionIdValue);
         }
         //请求客户端的退出 客户端根据session退出
         CookieContainer container = new CookieContainer();
         Cookie          cookie    = new Cookie(client.SessionIdKey, client.SessionIdValue);
         cookie.Domain = GetDomain(client.ClientUrl);
         container.Add(cookie);
         HttpUtils.HttpPost(logoutUrl, "", container);
     }
     catch (Exception ex)
     {
         LogUtils.myError(log, ex);
     }
 }
Example #6
0
 /// <summary>
 /// 根据账号获取用户
 /// </summary>
 /// <param name="account"></param>
 /// <returns></returns>
 public virtual BaseUserEntity GetUserEntity(string account)
 {
     return(DataBaseUtils.GetUserEntity(account, null));
 }
Example #7
0
 /// <summary>
 /// 获取用户有权限的客户端
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public virtual IEnumerable <ClientEntity> getAllAuthClient(string userId)
 {
     return(DataBaseUtils.getAuthClient(userId));
 }
Example #8
0
 /// <summary>
 /// 获取所有客户端
 /// </summary>
 /// <returns></returns>
 public virtual IEnumerable <ClientEntity> getAllClient()
 {
     return(DataBaseUtils.getAllClient());
 }
Example #9
0
        /// <summary>
        /// 验证ST
        /// todo:ticket 应该与浏览器,ip绑定
        /// </summary>
        /// <param name="ticket">验证ST</param>
        /// <param name="service">应用地址</param>
        /// <param name="code">客户端防伪标识</param>
        /// <param name="sessionIdKey">客户端 sessionIdKey</param>
        /// <param name="sessionIdValue">客户端 sessionIdValue</param>
        public virtual UserModel VerifyTicket(string ticket, string service, string code, string sessionIdKey, string sessionIdValue)
        {
            try
            {
                string userId = RedisGetTicket(ticket);

                if (userId == null)
                {
                    throw new Exception("无效票据!");
                }

                string sessionId = UserUtils.Provider.UserSession(userId);

                if (sessionId == null)
                {
                    throw new Exception("用户未登录!");
                }

                UserModel user = UserUtils.Provider.GetUser(sessionId);

                if (user == null)
                {
                    throw new Exception("用户未登录!");
                }

                if (user.Clients == null)
                {
                    throw new Exception("用户未登录客户端!");
                }

                ClientModel clientModel = user.Clients.Find(t => t.ClientUrl == service);

                if (clientModel == null)
                {
                    throw new Exception("客户端未登录!");
                }
                else
                {
                    RedisDelTicket(ticket);
                    if (clientModel.TicketValidated == -1)
                    {
                        user.Clients.Remove(clientModel);//移除旧的

                        clientModel.TicketValidateTime = DateTime.Now;
                        clientModel.SessionIdKey       = sessionIdKey;
                        clientModel.TicketValidated    = 1;
                        clientModel.SessionIdValue     = sessionIdValue;
                        string description = "";
                        if (!doDecryptTicket(service, ticket))
                        {
                            clientModel.TicketValidated = 0;
                            description = "无效票据!";
                        }
                        if (!clientModel.ClientUrl.Equals(service) || !clientModel.Code.Equals(code))
                        {
                            clientModel.TicketValidated = 0;
                            description = "客户端不一致!";
                        }

                        ClientLogEntity log = DataBaseUtils.clientLoginLog(sessionId, clientModel, description);
                        clientModel.ClientLogId = log.AppLogId;
                        user.Clients.Add(clientModel);
                        UserUtils.Provider.UpdateUser(sessionId, user);//添加编辑后的

                        if (clientModel.TicketValidated == 1)
                        {
                            if (GrobalConfig.IsApiCheck)
                            {
                                user.Clients.ForEach(t =>
                                {
                                    RedisAddClient(t.SessionIdValue, sessionId);
                                });
                            }
                            return(user);
                        }
                        else
                        {
                            throw new Exception(description);
                        }
                    }
                    else
                    {
                        throw new Exception("客户端已登录校验!");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }