Ejemplo n.º 1
0
        public string Authenticate(UserEntity user, string identityProvider, bool isPersistent = false)
        {
            // Set thread identity
            SetPrincipal(user, identityProvider);

            return _authenticationProvider.SetCookie(user.Id, user.Roles.ToArray(), isPersistent);
        }
Ejemplo n.º 2
0
        public void SetPrincipal(UserEntity user, string identityProvider)
        {
            IEnumerable<Claim> newClaims = CreateClaims(user.Email, user.Name, identityProvider);
            var userIdentity = new SocialIdentity(user.Id) { Memberships = user.Memberships };
            userIdentity.AddClaims(newClaims);

            // check if principal is already has claims and preserve them
            var claimsPrincipal = HttpContext.Current.User as ClaimsPrincipal;
            if (claimsPrincipal != null && claimsPrincipal.Identity.AuthenticationType == FederationAuthenticationType)
            {
                userIdentity.SocialClaims = new List<Claim>(claimsPrincipal.Claims);
            }

            var userPrincipal = new GenericPrincipal(userIdentity, user.Roles.ToArray());

            HttpContext.Current.User = userPrincipal;
        }
Ejemplo n.º 3
0
        private async Task<DomainUserForAdmin> GetUserDataAsync(UserEntity user)
        {
            Task<List<FileEntity>> storageSpacesTask = _fileRepository.ToListAsync(p => p.UserId == user.Id && !p.IsArtifact);
            Task<List<ProjectEntity>> projectsTask = _projectRepository.GetUserProjectsAsync(user.Id);

            await Task.WhenAll(new Task[]
            {
                storageSpacesTask,
                projectsTask
            });

            return new DomainUserForAdmin
            {
                AppName = user.AppName,
                Created = user.Created,
                MaximumStorageSpace = user.MaximumStorageSpace,
                UserId = user.Id,
                UserName = user.Name ?? user.Id,
                UsedStorageSpace = storageSpacesTask.Result.Sum(p => p.Length),
                VideosCount = projectsTask.Result.Count,
                Memberships = user.Memberships.Select(
                    p => new DomainUserMembershipForAdmin
                    {
                        Identity = p.UserIdentifier,
                        Provider = p.IdentityProvider
                    }).ToList(),
                ProductType = (ProductType)user.ProductId,
                ProductName = _productWriterForAdmin.WriteProduct(user.ProductId),
                Email = user.Email
            };
        }
Ejemplo n.º 4
0
        private DomainComment CreateDomainComment(CommentEntity commentEntity, string ownerId)
        {
            var userEntity = new UserEntity
            {
                Id = commentEntity.UserId,
                Name = _authenticator.GetUserName(),
                Email = _authenticator.GetUserEmail()
            };

            DomainComment comment = _mapper.Map<Tuple<CommentEntity, UserEntity>, DomainComment>(
                new Tuple<CommentEntity, UserEntity>(commentEntity, userEntity));

            comment.OwnerId = ownerId;

            return comment;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Checks whether user state is valid.
        /// </summary>
        /// <param name="user">User.</param>
        private void CheckUserState(UserEntity user)
        {
            var state = (ResourceState)user.State;
            switch (state)
            {
                case ResourceState.Blocked:
                    throw new ForbiddenException();

                case ResourceState.Deleted:
                    throw new NotFoundException();
            }
        }