コード例 #1
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task <IdentityResult> CreateAsync(AppIdentityUser identityUser, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            var newUser = new UserDTO();

            Map(identityUser, newUser);

            newUser.Id = _userManager.Create(newUser);
            Mapper.Map(newUser, identityUser);

            var claim = new AppIdentityUserClaim(identityUser, RoleConstants.Role.User).ToClaim();

            AddClaimsAsync(identityUser, new[] { claim }, cancellationToken);

            var savedClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value);

            identityUser.UserClaims = Mapper.Map <IList <AppIdentityUserClaim> >(savedClaims);

            UpdateAsync(identityUser, cancellationToken);

            return(Task.FromResult(IdentityResult.Success));
        }
コード例 #2
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task AddClaimsAsync(AppIdentityUser identityUser, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }
            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }

            var user = _userRepository.Get(identityUser.Id);

            if (user == null)
            {
                return(Task.FromResult(IdentityResult.Failed(
                                           new IdentityError {
                    Code = "UserNotFound", Description = $"User with id {user.Id} not found"
                })));
            }

            foreach (var claim in claims)
            {
                var newClaim  = CreateUserClaim(identityUser, claim);
                var userClaim = Mapper.Map <UserClaimDTO>(newClaim);
                userClaim.User = user;
                _userClaimManager.Create(userClaim);
            }

            return(Task.FromResult(IdentityResult.Success));
        }
コード例 #3
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task RemoveClaimsAsync(AppIdentityUser identityUser, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }
            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }

            foreach (var claim in claims)
            {
                var userClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value);
                foreach (var userClaim in userClaims)
                {
                    _userClaimManager.Delete(userClaim);
                }
            }

            return(Task.FromResult(IdentityResult.Success));
        }
コード例 #4
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task ReplaceClaimAsync(AppIdentityUser identityUser, Claim claim, Claim newClaim, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }
            if (newClaim == null)
            {
                throw new ArgumentNullException(nameof(newClaim));
            }

            var matchedClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value);

            foreach (var matchedClaim in matchedClaims)
            {
                matchedClaim.ClaimType  = newClaim.Type;
                matchedClaim.ClaimValue = newClaim.Value;
                _userClaimManager.Save(matchedClaim);
            }

            return(Task.FromResult(IdentityResult.Success));
        }
コード例 #5
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task SetPasswordHashAsync(AppIdentityUser identityUser, string passwordHash, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            return(Task.FromResult(identityUser.PasswordHash = passwordHash));
        }
コード例 #6
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task <bool> HasPasswordAsync(AppIdentityUser identityUser, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            return(Task.FromResult(!string.IsNullOrEmpty(identityUser.PasswordHash) && string.IsNullOrWhiteSpace(identityUser.PasswordHash) && identityUser.PasswordHash.Length > 0));
        }
コード例 #7
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task SetUserNameAsync(AppIdentityUser identityUser, string userName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            return(Task.FromResult(identityUser.UserName = userName));
        }
コード例 #8
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task <string> GetUserIdAsync(AppIdentityUser identityUser, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            return(Task.FromResult(identityUser.Id.ToString()));
        }
コード例 #9
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task <IdentityResult> DeleteAsync(AppIdentityUser identityUser, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            var user = Mapper.Map <UserDTO>(identityUser);

            _userManager.Delete(user);

            return(Task.FromResult(IdentityResult.Success));
        }
コード例 #10
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
        public override Task <IList <Claim> > GetClaimsAsync(AppIdentityUser identityUser, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (identityUser == null)
            {
                throw new ArgumentNullException(nameof(identityUser));
            }

            var claims = _userClaimRepository.GetByUserId(identityUser.Id)
                         .Select(Mapper.Map <AppIdentityUserClaim>)
                         .Select(x => x.ToClaim())
                         .ToList() as IList <Claim>;

            return(Task.FromResult(claims));
        }
コード例 #11
0
 public AppIdentityUserClaim(AppIdentityUser identityUser, RoleConstants.Role role)
 {
     UserId     = identityUser.Id;
     ClaimType  = ClaimTypes.Role;
     ClaimValue = role.ToString();
 }
コード例 #12
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
 protected override Task <IdentityUserToken <int> > FindTokenAsync(AppIdentityUser user, string loginProvider, string name, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
 public override Task <IList <UserLoginInfo> > GetLoginsAsync(AppIdentityUser user, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #14
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
 public override Task RemoveLoginAsync(AppIdentityUser user, string loginProvider, string providerKey, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #15
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
 public override Task AddLoginAsync(AppIdentityUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
コード例 #16
0
ファイル: AppIdentityStore.cs プロジェクト: Sickae/PROJ
 private void Map(AppIdentityUser identityUser, UserDTO user)
 {
     Mapper.Map(identityUser, user);
 }