public UserEntity(TokenEntity tokenEntity, IReadAuthRepository readAuthRepository, IOnlineUserMgr onlineUserMgr) { this.UserInfo = tokenEntity.UserInfo; this.readAuthRepository = readAuthRepository; this.onlineUserMgr = onlineUserMgr; this.Option = new UserAuthOption(); this.ClientInfo = tokenEntity.ClientInfo; this.LoginTime = tokenEntity.LoginTime; this.ExpiredTime = tokenEntity.ExpiredTime; this.Token = tokenEntity.Token; }
public override void OnActionExecuting(HttpActionContext actionContext) { var actionAttrs = actionContext.ActionDescriptor.GetCustomAttributes <Attribute>(); var controllerAttrs = actionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <Attribute>(); // 如果为允许匿名访问,则返回 if (actionAttrs.Any(m => m is AllowAnonymousAttribute) || controllerAttrs.Any(m => m is AllowAnonymousAttribute)) { return; } string code = this.resouceCode; if (string.IsNullOrEmpty(code)) { code = $"{actionContext.ActionDescriptor.ControllerDescriptor.ControllerName}-{actionContext.ActionDescriptor.ActionName}"; } IOnlineUserMgr authAggregate = Framework.IocContainer.IOCContainer.Resolve <IOnlineUserMgr>(); string token = Utils.Common.GetToken(); if (string.IsNullOrEmpty(token)) { actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } var profile = authAggregate.Get(token); if (profile == null) { actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } if (!profile.Verify(code)) { actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } base.OnActionExecuting(actionContext); }
public UserEntity(int userId, IReadAuthRepository readAuthRepository, RequestClientInfo clientInfo, IOnlineUserMgr onlineUserMgr) { this.readAuthRepository = readAuthRepository; this.onlineUserMgr = onlineUserMgr; this.UserInfo = this.readAuthRepository.GetUserInfo(userId); if (this.UserInfo == null) { this.UserInfo = new UserInfo() { Id = userId }; } this.ClientInfo = clientInfo; this.Option = new UserAuthOption(); this.LoginTime = DateTime.Now; this.ExpiredTime = this.LoginTime.AddSeconds(this.Option.UserLoginExpireIn); //to do generate token string tokenstr = $"token_{UserInfo.Id}_{UserInfo.UserName}_{clientInfo.IP}_{clientInfo.OS}_{this.LoginTime.Ticks}"; this.Token = this.GetMd5(tokenstr); }
public AuthAppService(IOnlineUserMgr onlineUserMgr, IReadAuthRepository readAuthRepository, BAccurateContext context) { this.readAuthRepository = readAuthRepository; this.onlineUserMgr = onlineUserMgr; this.context = context; }