public async Task CompleteImpersonationInvite(AppUser currentUser, string securityToken) { AppUser sourceUser = await this._appUserManager.Users.Where(u => u.AvailableImpersonations.Any(x => x.SecurityToken == securityToken && !x.IsActive)).Include(x => x.AvailableImpersonations).FirstOrDefaultAsync(); if (sourceUser == null) { throw new ImpersonationNotAllowedException(); } AppUserTrustedUser item = sourceUser.AvailableImpersonations.FirstOrDefault(x => x.SecurityToken == securityToken && !x.IsActive); if (item == null) { throw new ImpersonationNotAllowedException(); } if (sourceUser == currentUser) { throw new ImpersonationNotAllowedException(); } item.IsActive = true; item.SourceUser = currentUser; item.TargetUser = sourceUser; item.CreationDate = DateTimeOffset.Now; await this._appUserTrustedUserRepository.SaveChangesAsync(); }
private static OutstandingImpersonation CreateOutstandingImpersonationModel(AppUserTrustedUser trustedUser) { return(new OutstandingImpersonation { CreationDate = trustedUser.CreationDate, SecurityToken = trustedUser.SecurityToken }); }
public async Task <OutstandingImpersonation> CreateImpersonationInvite() { AppUser currentUser = await this.GetCurrentUser(); AppUserTrustedUser impersonationToken = await this._appImpersonationTokenService.CreateImpersonationInvite(currentUser); return(CreateOutstandingImpersonationModel(impersonationToken)); }
public async Task <AppOwner> GetImpersonationUserGroup(AppUser currentUser, int impersonationUserId) { AppUser impersonatingUser = await this._appUserManager.Users.Where(x => x.Id == impersonationUserId).FirstOrDefaultAsync(); if (impersonatingUser == null) { throw new ImpersonationNotAllowedException(); } AppUserTrustedUser item = currentUser.AvailableImpersonations.GetForTrustee(impersonatingUser); if (item == null) { throw new ImpersonationNotAllowedException(); } return(item.Group); }
public async Task <AppUserTrustedUser> CreateImpersonationInvite(AppUser user) { AppUserTrustedUser impersonationToken = new AppUserTrustedUser { CreationDate = DateTimeOffset.Now, IsActive = false, SecurityToken = Guid.NewGuid().ToString("N"), SourceUser = user, Group = user.CurrentGroup }; user.AvailableImpersonations.Add(impersonationToken); await this._appUserTrustedUserRepository.SaveChangesAsync(); await this._appUserManager.UpdateAsync(user); return(impersonationToken); }
public void Remove(AppUserTrustedUser availableImpersonation) { this._appDbContext.Set <AppUserTrustedUser>().Remove(availableImpersonation); }