public void SetParticipant(CurrentParticipantModel currentParticipant) { var hostEnvProvider = this._authenticationStateProvider as IHostEnvironmentAuthenticationStateProvider; if (hostEnvProvider == null) { return; } (int participantId, string?name, bool isFacilitator) = currentParticipant; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim(ParticipantClaimType, participantId.ToString(Culture.Invariant), participantId.GetType().FullName)); identity.AddClaim(new Claim(ParticipantNameClaimType, name, typeof(string).FullName)); if (isFacilitator) { identity.AddClaim(new Claim(FacilitatorClaimType, FacilitatorClaimContent, FacilitatorClaimContent.GetType().FullName)); } hostEnvProvider.SetAuthenticationState( Task.FromResult( new AuthenticationState( new ClaimsPrincipal(identity) ) ) ); }
public static void SetAuthenticationInfo(this IServiceScope serviceScope, CurrentParticipantModel currentParticipant) { var currentParticipantService = (CurrentParticipantService) serviceScope.ServiceProvider.GetRequiredService <ICurrentParticipantService>(); currentParticipantService.SetHttpContext(new DefaultHttpContext { User = new ClaimsPrincipal() }); currentParticipantService.SetParticipant(currentParticipant); }
public async Task <RetrospectiveNote> Handle(AddNoteCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } // Get the required entities using IReturnDbContext returnDbContext = this._returnDbContextFactory.CreateForEditContext(); Retrospective retrospective = await returnDbContext.Retrospectives.FindByRetroId(request.RetroId, cancellationToken); if (retrospective == null) { throw new NotFoundException(nameof(Retrospective), request.RetroId); } NoteLane noteLane = await returnDbContext.NoteLanes.FindAsync((KnownNoteLane)request.LaneId); if (noteLane == null) { throw new NotFoundException(nameof(NoteLane), (KnownNoteLane)request.LaneId); } // Save the note CurrentParticipantModel currentParticipant = await this._currentParticipantService.GetParticipant(); var note = new Note { Retrospective = retrospective, CreationTimestamp = this._systemClock.CurrentTimeOffset, Lane = noteLane, Participant = await returnDbContext.Participants.FindAsync(currentParticipant.Id), ParticipantId = currentParticipant.Id, Text = String.Empty }; await this._securityValidator.EnsureOperation(retrospective, SecurityOperation.AddOrUpdate, note); returnDbContext.Notes.Add(note); await returnDbContext.SaveChangesAsync(cancellationToken); // Return and broadcast var broadcastNote = this._mapper.Map <RetrospectiveNote>(note); var returnNote = this._mapper.Map <RetrospectiveNote>(note); returnNote.IsOwnedByCurrentUser = true; // ... Broadcast await this._mediator.Publish(new NoteAddedNotification(request.RetroId, request.LaneId, broadcastNote), cancellationToken); return(returnNote); }
public static void SetAuthenticationInfo(this IServiceScope serviceScope, CurrentParticipantModel currentParticipant) { TestContext.WriteLine($"[{nameof(TestServiceScopeUtilities)}] {nameof(IServiceScope)} - setting authentication with participant {currentParticipant}"); var currentParticipantService = (CurrentParticipantService) serviceScope.ServiceProvider.GetRequiredService <ICurrentParticipantService>(); currentParticipantService.SetHttpContext(new DefaultHttpContext { User = new ClaimsPrincipal() }); currentParticipantService.SetParticipant(currentParticipant); }
public async ValueTask EnsureOperation(Session session, SecurityOperation operation, object entity) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } CurrentParticipantModel participant = await this.GetAuthenticatedParticipant(operation, entity.GetType()); if (operation == SecurityOperation.AddOrUpdate || operation == SecurityOperation.Delete) { this.EnsureOperationSecurity(operation, entity, participant); } this.InvokeTypeSecurityChecks(operation, session, participant, entity); }
private async ValueTask <CurrentParticipantModel> GetAuthenticatedParticipant(SecurityOperation operation, Type entityType) { CurrentParticipantModel participant = await this._currentParticipantService.GetParticipant();
public void Reset() => this._currentParticipant = default;
public void SetParticipant(CurrentParticipantModel participant) => this._currentParticipant = participant;
public async Task <Unit> Handle(PlayCardCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IPokerTimeDbContext dbContext = this._dbContextFactory.CreateForEditContext(); Session session = await dbContext.Sessions.FindBySessionId(request.SessionId, cancellationToken); if (session == null) { throw new NotFoundException(nameof(Session), request.SessionId); } UserStory userStory = await dbContext.UserStories.FirstOrDefaultAsync(x => x.Session.UrlId.StringId == request.SessionId && x.Id == request.UserStoryId, cancellationToken); if (userStory == null) { throw new NotFoundException(nameof(UserStory), request.UserStoryId); } Symbol desiredSymbol = await dbContext.Symbols.FirstOrDefaultAsync(x => x.Id == request.SymbolId, cancellationToken); if (desiredSymbol == null) { throw new NotFoundException(nameof(Symbol), request.SymbolId); } if (desiredSymbol.SymbolSetId != session.SymbolSetId) { throw new InvalidOperationException($"The chosen symbol #{request.SymbolId} is not part of symbol set #{session.SymbolSetId}"); } CurrentParticipantModel currentParticipantInfo = await this._currentParticipantService.GetParticipant(); // Add or update estimation Estimation estimation = await dbContext.Estimations .Include(x => x.Participant) .Where(x => x.UserStory.Session.UrlId.StringId == session.UrlId.StringId) .FirstOrDefaultAsync(x => x.UserStory.Id == userStory.Id && x.ParticipantId == currentParticipantInfo.Id, cancellationToken); if (estimation == null) { estimation = new Estimation { ParticipantId = currentParticipantInfo.Id, Participant = dbContext.Participants.First(x => x.Id == currentParticipantInfo.Id), UserStory = userStory, Symbol = desiredSymbol }; dbContext.Estimations.Add(estimation); } else { estimation.Symbol = desiredSymbol; } await dbContext.SaveChangesAsync(cancellationToken); var estimationNotification = new EstimationGivenNotification( session.UrlId.StringId, this._mapper.Map <EstimationModel>(estimation) ); await this._mediator.Publish(estimationNotification, cancellationToken); return(Unit.Value); }