public UserEndpoint(IUserAdapter <TUser> userAdapter, IUserTokenProvider userTokenProvider, IUserClaimsProvider <TUser> userClaimsProvider, IOrderAdapter orderAdapter)
 {
     _userAdapter        = userAdapter;
     _userTokenProvider  = userTokenProvider;
     _userClaimsProvider = userClaimsProvider;
     _orderAdapter       = orderAdapter;
 }
 protected override void EstablishContext()
 {
     wimpProvider = mocks.StrictMock<IWimpProvider>();
     staffInformationProvider = mocks.Stub<IStaffInformationProvider>();
     authenticationProvider = mocks.Stub<IAuthenticationProvider>();
     userClaimsProvider = mocks.Stub<IUserClaimsProvider>();
 }
 public GetImpersonatedClaimsDataProvider(IWimpProvider wimpProvider, IStaffInformationProvider staffInformationProvider,
     IAuthenticationProvider authenticationProvider, IUserClaimsProvider userClaimsProvider)
 {
     this.wimpProvider = wimpProvider;
     this.staffInformationProvider = staffInformationProvider;
     this.authenticationProvider = authenticationProvider;
     this.userClaimsProvider = userClaimsProvider;
 }
 public AzureClaimsAuthenticationManagerProvider(IStaffInformationFromEmailProvider staffInformationFromEmailProvider,
     IClaimsIssuedTrackingEventProvider claimsIssuedTrackingEventProvider, IUserClaimsProvider userClaimsProvider, IGetImpersonatedClaimsDataProvider getImpersonatedClaimsDataProvider)
 {
     this.staffInformationFromEmailProvider = staffInformationFromEmailProvider;
     this.claimsIssuedTrackingEventProvider = claimsIssuedTrackingEventProvider;
     this.userClaimsProvider = userClaimsProvider;
     this.getImpersonatedClaimsDataProvider = getImpersonatedClaimsDataProvider;
 }
Example #5
0
        private async Task <JsonWebToken> CreateToken(string userId, string userName, RequestClientType clientType, RefreshToken refreshToken)
        {
            Check.NotNullOrEmpty(userId, nameof(userId));
            Check.NotNullOrEmpty(userName, nameof(userName));

            // New RefreshToken
            string clientId = refreshToken?.ClientId ?? Guid.NewGuid().ToString();

            Claim[] claims =
            {
                new Claim(ClaimTypes.NameIdentifier, userId),
                new Claim(ClaimTypes.Name,           userName),
                new Claim("clientId",                clientId),
                new Claim("clientType",              clientType.ToString())
            };
            var(token, expires) = CreateToken(claims, _jwtOptions, JwtTokenType.RefreshToken, refreshToken);
            string              refreshTokenStr = token;
            IUnitOfWork         unitOfWork      = _provider.GetUnitOfWork(true);
            UserManager <TUser> userManager     = _provider.GetService <UserManager <TUser> >();

            refreshToken = new RefreshToken()
            {
                ClientId = clientId, Value = refreshTokenStr, EndUtcTime = expires
            };
            IdentityResult result = await userManager.SetRefreshToken(userId, refreshToken);

            if (result.Succeeded)
            {
#if NET5_0_OR_GREATER
                await unitOfWork.CommitAsync();
#else
                unitOfWork.Commit();
#endif
                IEventBus eventBus = _provider.GetRequiredService <IEventBus>();
                OnlineUserCacheRemoveEventData eventData = new OnlineUserCacheRemoveEventData()
                {
                    UserNames = new[] { userName }
                };
                await eventBus.PublishAsync(eventData);
            }

            // New AccessToken
            IUserClaimsProvider claimsProvider = _provider.GetRequiredService <IUserClaimsProvider>();
            claims = await claimsProvider.CreateClaims(userId);

            List <Claim> claimList = claims.ToList();
            claimList.Add(new Claim("clientId", clientId));
            claimList.Add(new Claim("clientType", clientType.ToString()));
            (token, _) = CreateToken(claimList, _jwtOptions, JwtTokenType.AccessToken);

            return(new JsonWebToken()
            {
                AccessToken = token,
                RefreshToken = refreshTokenStr,
                RefreshUctExpires = expires.ToJsGetTime().CastTo <long>(0)
            });
        }
 public DashboardClaimsGetOutputClaimsIdentityProvider(IStaffInformationProvider staffInformationProvider, IAuthenticationProvider authenticationProvider,
     IUserClaimsProvider userClaimsProvider, IClaimsIssuedTrackingEventProvider claimsIssuedTrackingEventProvider, IGetImpersonatedClaimsDataProvider getImpersonatedClaimsDataProvider)
 {
     this.staffInformationProvider = staffInformationProvider;
     this.authenticationProvider = authenticationProvider;
     this.userClaimsProvider = userClaimsProvider;
     this.ClaimsIssuedTrackingEventProvider = claimsIssuedTrackingEventProvider;
     this.getImpersonatedClaimsDataProvider = getImpersonatedClaimsDataProvider;
 }
        /// <summary>
        /// Cookie验证通过时,从OnlineUser缓存或数据库查找用户的最新信息附加到有效的 ClaimIdentity 上
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task ValidatePrincipal(CookieValidatePrincipalContext context)
        {
            ClaimsPrincipal user     = context.Principal;
            ClaimsIdentity  identity = user.Identity as ClaimsIdentity;

            IUserClaimsProvider accessClaimsProvider = context.HttpContext.RequestServices.GetService <IUserClaimsProvider>();

            return(accessClaimsProvider.RefreshIdentity(identity));
        }
        protected override void EstablishContext()
        {
            base.EstablishContext();

            staffInformationFromEmailProvider = mocks.StrictMock<IStaffInformationFromEmailProvider>();
            authenticationProvider = mocks.StrictMock<IAuthenticationProvider>();
            httpContextItemsProvider = mocks.StrictMock<IHttpContextItemsProvider>();
            userClaimsProvider = mocks.StrictMock<IUserClaimsProvider>();
            ClaimsIssuedTrackingEventProvider = mocks.StrictMock<IClaimsIssuedTrackingEventProvider>();
            getImpersonatedClaimsDataProvider = mocks.StrictMock<IGetImpersonatedClaimsDataProvider>();
        }
 public DashboardClaimsAuthenticationManagerProvider(IStaffInformationFromEmailProvider staffInformationFromEmailProvider, IAuthenticationProvider authenticationProvider,
     IUserClaimsProvider userClaimsProvider, IClaimsIssuedTrackingEventProvider claimsIssuedTrackingEventProvider, IHttpContextItemsProvider httpContextItemsProvider,
     IGetImpersonatedClaimsDataProvider getImpersonatedClaimsDataProvider)
 {
     this.staffInformationFromEmailProvider = staffInformationFromEmailProvider;
     this.authenticationProvider = authenticationProvider;
     this.userClaimsProvider = userClaimsProvider;
     this.claimsIssuedTrackingEventProvider = claimsIssuedTrackingEventProvider;
     this.httpContextItemsProvider = httpContextItemsProvider;
     this.getImpersonatedClaimsDataProvider = getImpersonatedClaimsDataProvider;
 }
Example #10
0
        /// <summary>
        /// Token验证通过时,从OnlineUser缓存或数据库查找用户的最新信息附加到有效的 ClaimPrincipal 上
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task TokenValidated(TokenValidatedContext context)
        {
            ClaimsPrincipal user     = context.Principal;
            ClaimsIdentity  identity = user.Identity as ClaimsIdentity;

            IUserClaimsProvider accessClaimsProvider = context.HttpContext.RequestServices.GetService <IUserClaimsProvider>();
            OperationResult <ClaimsIdentity> result  = await accessClaimsProvider.RefreshIdentity(identity);

            if (!result.Succeeded)
            {
                context.Fail(result.Message);
            }
        }
        public AuthorizationManager(
            IUserClaimsProvider claimsProvider, IUserRepository userRepository)
        {
            _userRepository = userRepository;

            if (claimsProvider.WithinWebRequest())
            {
                _executionWithinBackgroundTask = false;
                _claimsUser = new ClaimsUser(claimsProvider.GetUserClaims());
            }
            else
            {
                _executionWithinBackgroundTask = true;
            }
        }
        protected override void EstablishContext()
        {
            base.EstablishContext();
            staffInformationProvider = mocks.Stub<IStaffInformationProvider>();
            authenticationProvider = mocks.Stub<IAuthenticationProvider>();
            userClaimsProvider = mocks.DynamicMock<IUserClaimsProvider>();
            
            identity = mocks.Stub<IClaimsIdentity>();
            principal = mocks.Stub<IClaimsPrincipal>();

            Expect.Call(identity.Name).Return(userName);
            Expect.Call(principal.Identity).Return(identity);
            Expect.Call(staffInformationProvider.ResolveStaffUSI(authenticationProvider, userName)).Return(staffUSI);

            
        }
Example #13
0
        public JwtController(IOptions <JwtIssuerOptions> jwtOptions,
                             IUserClaimsProvider userClaimsProvider,
                             IJwtIssuer jwtIssuer,
                             ILoggerFactory loggerFactory)
        {
            this.jwtIssuer  = jwtIssuer;
            this.jwtOptions = jwtOptions.Value;
            this.jwtIssuer.ThrowIfInvalidOptions(this.jwtOptions);
            this.userClaimsProvider = userClaimsProvider;

            logger = loggerFactory.CreateLogger <JwtController>();

            serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
        }
        public TokensIssuingMiddleware(RequestDelegate next, IUserClaimsProvider userClaimsProvider, IOptions <TokensIssuingOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (userClaimsProvider == null)
            {
                throw new ArgumentNullException(nameof(userClaimsProvider));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrWhiteSpace(options.Value.GetEndpotint))
            {
                throw new ArgumentNullException(nameof(options.Value.GetEndpotint));
            }
            if (string.IsNullOrWhiteSpace(options.Value.SigningAlgorithmName))
            {
                throw new ArgumentNullException(nameof(options.Value.SigningAlgorithmName));
            }
            if (options.Value.SigningKey == null)
            {
                throw new ArgumentNullException(nameof(options.Value.SigningKey));
            }

            _next = next;
            _userClaimsProvider = userClaimsProvider;
            _tokenHandler       = new JwtSecurityTokenHandler();

            _getEndpointPath    = new PathString(options.Value.GetEndpotint);
            _signingCredentials = new SigningCredentials(options.Value.SigningKey, options.Value.SigningAlgorithmName);
            _lifetime           = options.Value.Lifetime;

            _jsonSerializerSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                Converters       = { new IsoDateTimeConverter() },
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
        }
Example #15
0
        public Authorization(
            IUserClaimsProvider claimsProvider, IUserRepository userRepository)
        {
            _userRepository = userRepository;

            if (claimsProvider.WithinWebRequest())
            {
                _executionWithinBackgroundTask = false;

                ClaimsPrincipal claims = claimsProvider.GetUserClaims();

                if (!claims.HasClaims())
                {
                    throw new NoPermissionsException("Web request has no claims");
                }

                _identityUser = new IdentityUser(claims);
            }
            else
            {
                _executionWithinBackgroundTask = true;
            }
        }
        public TokensIssuingMiddleware(RequestDelegate next, IUserClaimsProvider userClaimsProvider, IOptions <TokensIssuingOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (userClaimsProvider == null)
            {
                throw new ArgumentNullException(nameof(userClaimsProvider));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrWhiteSpace(options.Value.GetEndpotint))
            {
                throw new ArgumentNullException(nameof(options.Value.GetEndpotint));
            }
            if (string.IsNullOrWhiteSpace(options.Value.SigningAlgorithmName))
            {
                throw new ArgumentNullException(nameof(options.Value.SigningAlgorithmName));
            }
            if (options.Value.SigningKey == null)
            {
                throw new ArgumentNullException(nameof(options.Value.SigningKey));
            }

            _next = next;
            _userClaimsProvider     = userClaimsProvider;
            _tokenHandler           = new JwtSecurityTokenHandler();
            _tokenIssueEventHandler = options.Value.TokenIssueEventHandler;
            _getEndpointPath        = new PathString(options.Value.GetEndpotint);
            _signingCredentials     = new SigningCredentials(options.Value.SigningKey, options.Value.SigningAlgorithmName);
            _lifetime = options.Value.Lifetime;

            _jsonSerializerSettings = new JsonSerializerSettings().UseDefaultSettings();
        }
Example #17
0
 public UserService(UserManager <ApplicationUser> userManager,
                    IUserClaimsProvider claimsProvider)
 {
     _userManager    = userManager;
     _claimsProvider = claimsProvider;
 }
Example #18
0
 public SecurityTokenHandler(ITokenSerialiser tokenSerialiser, ITokenValidator tokenValidator, IUserClaimsProvider <Tuple <Saml2SecurityToken, HandleTokenContext> > identityProvider)
 {
     this._tokenSerialiser  = tokenSerialiser;
     this._tokenValidator   = tokenValidator;
     this._identityProvider = identityProvider;
 }
Example #19
0
 public SessionCollectionsController(IMediator mediator, IUserClaimsProvider userClaimsProvider)
 {
     _mediator           = mediator;
     _userClaimsProvider = userClaimsProvider;
 }
Example #20
0
 public IdentityProviderService(ApplicationUserManager manager, IUserClaimsProvider <ApplicationUser> claimsProvider)
 {
     this._manager        = manager;
     this._claimsProvider = claimsProvider;
 }