当前位置: 首页>>代码示例>>C#>>正文


C# IServiceBase.GetSession方法代码示例

本文整理汇总了C#中IServiceBase.GetSession方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceBase.GetSession方法的具体用法?C# IServiceBase.GetSession怎么用?C# IServiceBase.GetSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceBase的用法示例。


在下文中一共展示了IServiceBase.GetSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var user = authService.Request.GetUser();
            var userName = user.GetUserName();
            if (!LoginMatchesSession(session, userName))
            {
                authService.RemoveSession();
                session = authService.GetSession();
            }

            if (IsAuthorized(user))
            {
                session.IsAuthenticated = true;
                if (session.UserAuthName == null)
                {
                    session.UserAuthName = userName;
                }

                var aspReq = (HttpRequestBase)authService.Request.OriginalRequest;

                var loginUser = aspReq.ServerVariables["LOGON_USER"].ToNullIfEmpty();
                var remoteUser = aspReq.ServerVariables["REMOTE_USER"].ToNullIfEmpty();
                var identityName = aspReq.LogonUserIdentity != null ? aspReq.LogonUserIdentity.Name : null;
                session.DisplayName = loginUser
                    ?? remoteUser
                    ?? identityName;

                var tokens = new AuthTokens {
                    Provider = Name,
                    UserName = userName,
                    DisplayName = session.DisplayName,
                    Items = new Dictionary<string, string> {
                        {"LOGON_USER", loginUser},
                        {"REMOTE_USER", remoteUser},
                        {"LogonUserIdentityName", identityName},
                    }
                };

                if (session.Roles == null)
                    session.Roles = new List<string>();

                foreach (var role in AllRoles.Safe())
                {
                    if (user.IsInRole(role))
                        session.Roles.AddIfNotExists(role);
                }

                OnAuthenticated(authService, session, tokens, new Dictionary<string, string>());

                return new AuthenticateResponse
                {
                    UserName = userName,
                    SessionId = session.Id,
                    DisplayName = session.DisplayName,
                    ReferrerUrl = request.Continue
                };
            }

            throw HttpError.Unauthorized("Windows Auth failed");
        }
开发者ID:halukmy,项目名称:ServiceStack,代码行数:60,代码来源:AspNetWindowsAuthProvider.cs

示例2: AuthenticateImpl

        private object AuthenticateImpl(IServiceBase authService, IAuthSession session, string userName, string password, string referrerUrl)
        {
            if (!LoginMatchesSession(session, userName))
            {
                authService.RemoveSession();
                session = authService.GetSession();
            }
            if (TryAuthenticate(authService, userName, password))
            {
                session.IsAuthenticated = true;

                if (session.UserAuthName == null)
                {
                    session.UserAuthName = userName;
                }
                var response = OnAuthenticated(authService, session, null, null);
                if (response != null)
                    return response;

                var bytes = Encoding.UTF8.GetBytes(userName + ":" + password);

                return new CustomAuthenticateResponse
                {
                    UserId = session.UserAuthId,
                    UserName = userName,
                    SessionId = session.Id,
                    ReferrerUrl = referrerUrl,
                    AccessToken = Convert.ToBase64String(bytes)
                };
            }

            throw HttpError.Unauthorized(ErrorMessages.InvalidUsernameOrPassword);
        }
开发者ID:CodeRevver,项目名称:notekeeper-api,代码行数:33,代码来源:CustomAuthProvider.cs

示例3: Logout

        /// <summary>
        /// Remove the Users Session
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual object Logout(IServiceBase service, Authenticate request)
        {
            var feature = HostContext.GetPlugin<AuthFeature>();

            var session = service.GetSession();
            var referrerUrl = (request != null ? request.Continue : null)
                ?? (feature.HtmlLogoutRedirect != null ? service.Request.ResolveAbsoluteUrl(feature.HtmlLogoutRedirect) : null)
                ?? session.ReferrerUrl
                ?? service.Request.GetHeader("Referer")
                ?? this.CallbackUrl;

            session.OnLogout(service);
            AuthEvents.OnLogout(service.Request, session, service);

            service.RemoveSession();

            if (feature != null && feature.DeleteSessionCookiesOnLogout)
            {
                service.Request.Response.DeleteSessionCookies();
            }

            if (service.Request.ResponseContentType == MimeTypes.Html && !string.IsNullOrEmpty(referrerUrl))
                return service.Redirect(LogoutUrlFilter(this, referrerUrl.SetParam("s", "-1")));

            return new AuthenticateResponse();
        }
开发者ID:AndreGleichner,项目名称:ServiceStack,代码行数:32,代码来源:AuthProvider.cs

示例4: Authenticate

        protected object Authenticate(IServiceBase authService, IAuthSession session, string userName, string password)
        {
            if (!LoginMatchesSession(session, userName)) {
                authService.RemoveSession();
                session = authService.GetSession();
            }

            if (TryAuthenticate(authService, userName, password))
            {
                session.IsAuthenticated = true;

                if (session.UserAuthName == null) 
                    session.UserAuthName = userName;

                var response = OnAuthenticated(authService, session, null, null);
                if (response != null)
                    return response;

                return new AuthenticateResponse {
                    UserId = session.UserAuthId,
                    UserName = userName,
                    SessionId = session.Id,
                };
            }

            throw HttpError.Unauthorized(ErrorMessages.InvalidUsernameOrPassword);
        }
开发者ID:jango2015,项目名称:ServiceStack,代码行数:27,代码来源:DigestAuthProvider.cs

示例5: TryAuthenticate

        public virtual bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = authService.TryResolve<IAuthRepository>();
            if (authRepo == null) {
                Log.WarnFormat("Tried to authenticate without a registered IUserAuthRepository");
                return false;
            }

            var session = authService.GetSession();
            var digestInfo = authService.Request.GetDigestAuth();
            IUserAuth userAuth;
            if (authRepo.TryAuthenticate(digestInfo, PrivateKey, NonceTimeOut, session.Sequence, out userAuth)) {

                var holdSessionId = session.Id;
                session.PopulateWith(userAuth); //overwrites session.Id
                session.Id = holdSessionId;
                session.IsAuthenticated = true;
                session.Sequence = digestInfo["nc"];
                session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                    .ConvertAll(x => (IAuthTokens) x);

                return true;
            }
            return false;
        }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:26,代码来源:DigestAuthProvider.cs

示例6: TryAuthenticate

        public virtual bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = HostContext.AppHost.GetAuthRepository(authService.Request);
            using (authRepo as IDisposable)
            {
                var session = authService.GetSession();
                var digestInfo = authService.Request.GetDigestAuth();
                IUserAuth userAuth;
                if (authRepo.TryAuthenticate(digestInfo, PrivateKey, NonceTimeOut, session.Sequence, out userAuth))
                {

                    var holdSessionId = session.Id;
                    session.PopulateWith(userAuth); //overwrites session.Id
                    session.Id = holdSessionId;
                    session.IsAuthenticated = true;
                    session.Sequence = digestInfo["nc"];
                    session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                    session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                        .ConvertAll(x => (IAuthTokens)x);

                    return true;
                }
                return false;
            }
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:25,代码来源:DigestAuthProvider.cs

示例7: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var authRepo = authService.TryResolve<IAuthRepository>().AsUserAuthRepository(authService.GetResolver());

            var session = authService.GetSession();
            IUserAuth userAuth;
            if (authRepo.TryAuthenticate(userName, password, out userAuth))
            {
                if (IsAccountLocked(authRepo, userAuth))
                    return false;
                // throw new AuthenticationException("This account has been locked");

                var holdSessionId = session.Id;
                session.PopulateWith(userAuth); //overwrites session.Id
                session.Id = holdSessionId;
                session.IsAuthenticated = true;
                session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
                session.ProviderOAuthAccess = authRepo.GetUserAuthDetails(session.UserAuthId)
                    .ConvertAll(x => (IAuthTokens)x);

                return true;
            }

            return false;
        }
开发者ID:aaronzoe,项目名称:Klkl,代码行数:25,代码来源:CustomCredentialsAuthProvider.cs

示例8: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            Log.Debug("Authenticating {0}...".F(userName));

            User user;
            if (!AuthenticateUser(userName, password, out user)) return false;

            if (user == null) return false;

            Log.Debug("Obtaining team for {0}".F(userName));
            var team = TeamDbProvider.Instance[user];

            if (team == null) return false;

            Log.Debug("Obtaining game for {0}".F(userName));
            var game = GameDbProvider.Instance[team];

            if (game == null) return false;

            var session = authService.GetSession();
            // PopulateWith() is really great, but it replaces the default
            // session ID with the user ID from the database, so save it here
            var sessionId = session.Id;
            session.PopulateWith(user);
            session.Id = sessionId;
            session.IsAuthenticated = true;
            // These roles will be used later to check what team the user is on, etc.
            session.Roles = new List<string> {
                User.F(user.Id),
                Team.F(team.Id),
                Game.F(game.Id)
            };

            session.UserAuthName = userName;
            session.UserAuthId = user.Id.ToString(CultureInfo.InvariantCulture);

            var userKey = "User {0}".F(user.Id);
            var gameKey = "Game {0}".F(game.Id);

            // Cache the user and game objects so they will be easier to
            // obtain again later in other service classes (i.e., check-in)
            if (Global.Cache.Get<User>(userKey) == null) {
                // This cache entry will remain cached for one day
                // OR until the user logs out, whichever comes first
                Global.Cache.Add(userKey, user, TimeSpan.FromDays(1));
            }

            if (Global.Cache.Get<Game>(gameKey) == null) {
                // This cache entry will stay cached until the
                // game ends OR if it is invalidated elsewhere
                Global.Cache.Add(gameKey, game, game.Finish);
            }

            return true;
        }
开发者ID:pawluk,项目名称:MOSHApp-WS,代码行数:55,代码来源:MoshAppAuthProvider.cs

示例9: Authenticate

 public override object Authenticate(IServiceBase authService, IAuthSession session, ServiceStack.ServiceInterface.Auth.Auth request)
 {
     var response = (AuthResponse)base.Authenticate(authService, session, request);
     session = authService.GetSession(true);
     return new AuthResponseEx
     {
         ReferrerUrl = response.ReferrerUrl,
         ResponseStatus = response.ResponseStatus,
         SessionId = response.SessionId,
         UserId = session.UserName,
         UserName = session.UserAuthName,
     };
 }
开发者ID:eteeselink,项目名称:sioux_tech_radar,代码行数:13,代码来源:SiouxAuthProvider.cs

示例10: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            long userId;
            if (!AuthenticateUser(userName, password, out userId)) return false;

            var user = Users.Get(userId);
            var session = authService.GetSession();
            session.IsAuthenticated = true;
            session.UserAuthId = Convert.ToString(userId);
            session.UserAuthName = userName;
            session.UserName = "{0} {1}".Fmt(user.FirstName, user.LastName);
            session.FirstName = user.FirstName;
            session.LastName = user.LastName;
            session.Email = user.Email;
            session.Roles = new List<string>();
            switch (user.Type) {
                case UserType.Administrator:
                    session.Roles.Add(UserType.Administrator.ToString());
                    goto case UserType.BasicEmployee; // Administrator is also an Employee
                case UserType.Shipping:
                    session.Roles.Add(UserType.Shipping.ToString());
                    break;
                case UserType.BasicEmployee:
                    session.Roles.Add(UserType.BasicEmployee.ToString());
                    goto case UserType.User; // BasicEmployees are also regular Users
                case UserType.User:
                    session.Roles.Add(UserType.User.ToString());
                    break;
            }
            var perms = new List<string>();
            switch (user.Type) {
                case UserType.User:
                    // Users can view products, but so can everyone else, so they don't get a specific permission
                    break;
                case UserType.BasicEmployee:
                    perms.Add(Permissions.CanCreateOrders);
                    perms.Add(Permissions.CanManageProducts);
                    break;
                case UserType.Shipping:
                    break;
                case UserType.Administrator:
                    // Administrators GET ALL THE PERMISSIONS
                    perms.AddRange(typeof(Permissions).GetFields()
                                                      .Where(x => x.FieldType == typeof(string) && x.IsLiteral)
                                                      .ToList().Select(x => x.Name));
                    break;
            }
            session.Permissions = perms;

            return true;
        }
开发者ID:jaysan1292,项目名称:COMP-3073-Group-Project,代码行数:51,代码来源:GateAuthProvider.cs

示例11: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            var session = authService.GetSession();
            var userAuth = this.FindByPasswordCredential(userName, password);
            if (userAuth != null)
            {
                session.UserName = userAuth.UserName;
                session.Email = userAuth.Email;
                session.DisplayName = userAuth.DisplayName;
                session.Permissions = userAuth.Permissions;
                session.Roles = userAuth.Roles;
                session.IsAuthenticated = true;
                session.UserAuthId = userAuth.RefIdStr;
            }

            return userAuth != null;
        }
开发者ID:rconnelly,项目名称:ach.fulfillment,代码行数:17,代码来源:ServiceStackCredentialsAuthAdapter.cs

示例12: Logout

        /// <summary>
        /// Remove the Users Session
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual object Logout(IServiceBase service, Auth request)
        {
            var session = service.GetSession();
            var referrerUrl = (request != null ? request.Continue : null)
                ?? session.ReferrerUrl
                ?? service.RequestContext.GetHeader("Referer")
                ?? this.CallbackUrl;

            session.OnLogout(service);

            service.RemoveSession();

            if (service.RequestContext.ResponseContentType == ContentType.Html && !String.IsNullOrEmpty(referrerUrl))
                return service.Redirect(referrerUrl.AddHashParam("s", "-1"));

            return new AuthResponse();
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:23,代码来源:AuthProvider.cs

示例13: Authenticate

        protected object Authenticate(IServiceBase authService, IAuthSession session, string userName, string password)
        {
            if (!LoginMatchesSession(session, userName)) {
                authService.RemoveSession();
                session = authService.GetSession();
            }

            if (TryAuthenticate(authService, userName, password)) {
                if (session.UserAuthName == null) {
                    session.UserAuthName = userName;
                }

                OnAuthenticated(authService, session, null, null);

                return new AuthenticateResponse {
                    UserName = userName,
                    SessionId = session.Id,
                };
            }

            throw HttpError.Unauthorized("Invalid UserName or Password");
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:22,代码来源:DigestAuthProvider.cs

示例14: TryAuthenticate

        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
                return false;
            using (var db = GetDB(authService))
            {
                var user = db.FirstOrDefault<Account>(c => c.UserName == userName && c.Password == password);
                if (user!=null)
                {
                    var session = (CustomUserSession)authService.GetSession(false);
                    session.UserName = user.UserName;
                    session.DisplayName = user.DisplayName;
                    session.IsAuthenticated = true;

                  //  session.Roles = new List<string>();
                //    if (session.DisplayName == "admin") session.Roles.Add(RoleNames.Admin);
                 //   session.Roles.Add("User");

                    return true;
                }
                return false;
            }
        }
开发者ID:koolay,项目名称:MVCAppStart,代码行数:23,代码来源:CustomCredentialsAuthProvider.cs

示例15: TryAuthenticate

 public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
 {
     var user = UserService.GetUser(userName);
     authService.GetSession().FillSession(user);
     return user.Authenticate(password);
 }
开发者ID:HyveMynd,项目名称:BlueprintCS,代码行数:6,代码来源:BlueprintBasicAuth.cs


注:本文中的IServiceBase.GetSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。