Пример #1
0
        public ClaimMember(HandlerProcessorFactory processorFactory)
        {
            var claimIdentity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;

            if (claimIdentity == null)
            {
                throw new AuthenticationException();
            }

            var user = new UserIdentityModel
            {
                Login = CommonExtensions.GetPrincipalNameWithoutDomain(claimIdentity.Name),
                AuthenticationType = claimIdentity.AuthenticationType
            };

            if (string.IsNullOrWhiteSpace(user.Login))
            {
                throw new AuthenticationException();
            }

            var commonNameClaim = claimIdentity.Claims.FirstOrDefault(_ => _.Type == "http://schemas.xmlsoap.org/claims/CommonName");

            user.Name = commonNameClaim?.Value;

            var emailClaim = claimIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);

            user.Email = emailClaim?.Value;

            Model = processorFactory.Get <UserIdentityLoginHandler>().Process(h => h.Handle(user));
            Roles = claimIdentity.Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToArray();
        }
Пример #2
0
        public WindowsMember(HandlerProcessorFactory processorFactory)
        {
            var windowsIdentity = Thread.CurrentPrincipal.Identity as WindowsIdentity;

            if (windowsIdentity == null)
            {
                throw new AuthenticationException();
            }

            var user = new UserIdentityModel
            {
                Login = CommonExtensions.GetPrincipalNameWithoutDomain(windowsIdentity.Name),
                AuthenticationType = windowsIdentity.AuthenticationType
            };

            if (string.IsNullOrWhiteSpace(user.Login))
            {
                throw new AuthenticationException();
            }

#if DEBUG
            using (var ctx = new PrincipalContext(ContextType.Machine))
#else
            using (var ctx = new PrincipalContext(ContextType.Domain))
#endif
            {
                var up = UserPrincipal.FindByIdentity(ctx, windowsIdentity.Name);
                user.Name  = up?.DisplayName;
                user.Email = up?.EmailAddress;
            }

            Model = processorFactory.Get <UserIdentityLoginHandler>().Process(h => h.Handle(user));
            Roles = windowsIdentity.Groups?
                    .Select(g => CommonExtensions.GetPrincipalNameWithoutDomain(g.Translate(typeof(NTAccount)).ToString()))
                    .ToArray() ?? new string[0];
        }
Пример #3
0
 public TestController(HandlerProcessorFactory processorFactory)
 {
     _processorFactory = processorFactory;
 }