コード例 #1
0
        private IBedrockUser GetUser(ActionExecutingContext context)
        {
            var returnValue      = default(IBedrockUser);
            var bedrockPrincipal = context.HttpContext.User as BedrockPrincipal;

            if (bedrockPrincipal != null)
            {
                returnValue = bedrockPrincipal.BedrockUser;
            }
            else
            {
                returnValue = new BedrockUser
                {
                    UserId      = BedrockUser.Default.UserId,
                    DisplayName = context.HttpContext.GetUsername(),
                    UserType    = BedrockUser.Default.UserType
                };
            }

            return(returnValue);
        }
コード例 #2
0
        private void SetUser(HttpContext context)
        {
            var displayName = context.GetUsername();

            var user = new BedrockUser
            {
                UserId      = BedrockUser.Default.UserId,
                DisplayName = displayName,
                UserType    = BedrockUser.Default.UserType
            };

            context.User = new BedrockPrincipal(user, new BedrockIdentity(user));
            context.User.AddIdentity((ClaimsIdentity)context.User.Identity);

            var type     = StringHelper.Current.Lookup(StringClaimType.Role);
            var userName = StringHelper.Current.Lookup(StringClaimType.PreferredUserName);
            var subject  = StringHelper.Current.Lookup(StringClaimType.Subject);

            context.User.Identities.First().AddClaim(new Claim(userName, context.User.Identity.Name));
            context.User.Identities.First().AddClaim(new Claim(subject, context.User.Identity.Name));

            _options.Applications.Each(a => context.User.Identities.First().AddClaim(new Claim(type, a.ToString())));
        }