Exemplo n.º 1
0
 public CarByName(IMapper mapper, CurrentUserProvider currentUserProvider,
                  IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.mapper = mapper;
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
 public PermissionService(ISecurityObjectRepository SecObjectRepository, CurrentUserProvider CurrentUser,
                          ILogger <PermissionService> _logger)
 {
     this.secObjectRepository = SecObjectRepository;
     this.CurrentUser         = CurrentUser;
     this._logger             = _logger;
 }
Exemplo n.º 3
0
        internal CurrentUserScope(CurrentUserProvider currentUserProvider, CurrentUserContext scopedContext)
        {
            _currentUserProvider = currentUserProvider;

            _previousContext             = currentUserProvider.Context;
            _currentUserProvider.Context = scopedContext;
        }
Exemplo n.º 4
0
 public UserController(UserRepository userRepository, IPasswordHasher passwordHasher, IOptions <JwtAuthentication> jwtAuthentication, CurrentUserProvider currentUserProvider)
 {
     _userRepository      = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
     _passwordHasher      = passwordHasher ?? throw new ArgumentNullException(nameof(passwordHasher));
     _jwtAuthentication   = jwtAuthentication ?? throw new ArgumentNullException(nameof(jwtAuthentication));
     _currentUserProvider = currentUserProvider ?? throw new ArgumentNullException(nameof(currentUserProvider));
 }
 public PermissionService(SecurityIdentityRepository RlsIdentityRepo, CurrentUserProvider CurrentUser,
                          ILogger <PermissionService> _logger)
 {
     this.RlsIdentityRepo = RlsIdentityRepo;
     this.CurrentUser     = CurrentUser;
     this._logger         = _logger;
 }
Exemplo n.º 6
0
 public ChargesForUserByLocationAndCar(IMapper mapper, CurrentUserProvider currentUserProvider,
                                       IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.mapper = mapper;
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
Exemplo n.º 7
0
 public InvitationByRecipient(IMapper mapper, CurrentUserProvider currentUserProvider,
                              IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.mapper = mapper;
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
Exemplo n.º 8
0
 private void SetLastChangeProperties(T entity, DateTime?now = null)
 {
     if (entity is ILastChangeTrackable lct)
     {
         lct.ModifiedUserId   = CurrentUserProvider.GetUserId();
         lct.ModifiedDateTime = now ?? DateTime.UtcNow;
     }
 }
Exemplo n.º 9
0
 public FavoritesController(
     DefaultContext dbContext,
     CurrentUserProvider currentUserProvider
     )
 {
     this.dbContext           = dbContext;
     this.currentUserProvider = currentUserProvider;
 }
 public PlaceholderSecureController(IPlaceholderSecureRepository placeholderSecureRepository, IPlaceholderACLRepository placeholderACLRepository,
                                    CurrentUserProvider currentUserProvider, IMapper mapper)
 {
     PlaceholderSecureRepository = placeholderSecureRepository;
     PlaceholderACLRepository    = placeholderACLRepository;
     CurrentUserProvider         = currentUserProvider;
     Mapper = mapper;
 }
Exemplo n.º 11
0
 private void SetCreationProperties(T entity, DateTime?now = null)
 {
     if (entity is ICreationTrackable ct)
     {
         ct.CreatedUserId   = CurrentUserProvider.GetUserId();
         ct.CreatedDateTime = now ?? DateTime.UtcNow;
     }
 }
Exemplo n.º 12
0
 public CommentsController(
     AppConfiguration configuration,
     DefaultContext dbContext,
     CurrentUserProvider currentUserProvider
     )
 {
     this.configuration       = configuration;
     this.dbContext           = dbContext;
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 13
0
 public OwnerController(
     IPaymentServices paymentServices,
     DefaultContext dbContext,
     CurrentUserProvider currentUserProvider
     )
 {
     this.paymentServices     = paymentServices;
     this.dbContext           = dbContext;
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 14
0
        public static void UseMicroservice(this IApplicationBuilder app, IHostingEnvironment env,
                                           MicroserviceOptions microserviceOptions)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseAuthentication();
            CultureInfo[] supportedCultures = new[]
            {
                "de-DE",
                "en-US"
            }.Select(code => new CultureInfo(code)).ToArray();
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-US"),
                // Formatting numbers, dates, etc.
                SupportedCultures = supportedCultures,
                // UI strings that we have localized.
                SupportedUICultures = supportedCultures
            });
            app.UseCors(options => options
                        .AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .WithExposedHeaders("X-Authentication-Hash")
                        .AllowCredentials());
            app.UseResponseCompression();
            JsonExceptionMiddleware jsonExceptionMiddleware =
                new JsonExceptionMiddleware(app.ApplicationServices.GetRequiredService <IHostingEnvironment>());

            app.UseExceptionHandler(new ExceptionHandlerOptions {
                ExceptionHandler = jsonExceptionMiddleware.Invoke
            });
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/1.0/swagger.json", microserviceOptions.Swagger.Title);
                options.DocExpansion(DocExpansion.List);
            });

            app.Use(async(context, next) =>
            {
                CurrentUserProvider currentUserProvider = app.ApplicationServices.GetService <CurrentUserProvider>();

                if (currentUserProvider != null)
                {
                    context.Response.Headers.Add("X-Authentication-Hash", currentUserProvider.User.Name.ToSha256());
                }

                await next();
            });
            app.UseMvcWithDefaultRoute();
        }
Exemplo n.º 15
0
 public FlowOneController(IStateManagger stateManagger, StateChangeFactory stateChangeFactory,
                          ITestEntityRepository testEntityRepository, IBasicTaskSecureRepository basicTaskRepository,
                          CurrentUserProvider currentUserProvider, IUserSecurityObjectsHandler userSecurityObjectsHandler)
 {
     StateManagger                  = stateManagger;
     StateChangeFactory             = stateChangeFactory;
     TestEntityRepository           = testEntityRepository;
     this.secureBasicTaskRepository = basicTaskRepository;
     CurrentUserProvider            = currentUserProvider;
     UserSecurityObjectsHandler     = userSecurityObjectsHandler;
 }
        public void GetCurrentUserOid_ShouldReturnOid_WhenOidExists()
        {
            var okOid = new Guid("7DFC890F-F82B-4E2D-B81B-41D6C103F83B");
            var dut   = new CurrentUserProvider();

            dut.SetCurrentUserOid(okOid);

            var oid = dut.GetCurrentUserOid();

            Assert.AreEqual(okOid, oid);
        }
Exemplo n.º 17
0
 public ContactController(
     ISiteContactFormMail mailer,
     AppConfiguration configuration,
     CurrentUserProvider currentUserProvider,
     DefaultContext dbContext
     )
 {
     this.mailer              = mailer;
     this.configuration       = configuration;
     this.currentUserProvider = currentUserProvider;
     this.dbContext           = dbContext;
 }
Exemplo n.º 18
0
        //
        // GET: /Object/

        public ObjectController(
            IUniqueViewCounter viewCounter,
            IPaymentServices paymentServices,
            DefaultContext dbContext,
            ObjectsActivator objectsActivator,
            CurrentUserProvider currentUserProvider
            )
        {
            this.viewCounter         = viewCounter;
            this.paymentServices     = paymentServices;
            this.dbContext           = dbContext;
            this.objectsActivator    = objectsActivator;
            this.currentUserProvider = currentUserProvider;
        }
        // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.0&tabs=aspnetcore2x#per-request-dependencies
        public async Task Invoke(HttpContext context, CurrentUserProvider currentUser,
                                 SecurityIdentityRepository rlsRepo, PermissionService permissionService)
        {
            RlsIdentityRepo   = rlsRepo;
            PermissionService = permissionService;

            CurrentUser = currentUser;
            var userName = context.User.Identity.Name;

            _logger.LogInformation($"Invoke - {userName}");

            RegisterUser(userName);

            await _next(context);
        }
Exemplo n.º 20
0
        public async Task AddVideoJobApplicationAsync(CreateVideoJobApplicationModel createVideoJobApplicationModel, CancellationToken cancellationToken)
        {
            var loggedInUserAzureObjectId = CurrentUserProvider.GetObjectId();
            var userEntity = FairplaytubeDatabaseContext.ApplicationUser
                             .Single(p => p.AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId);
            var videoJobApplicationEntity = await FairplaytubeDatabaseContext.VideoJobApplication
                                            .Include(p => p.ApplicantApplicationUser)
                                            .Include(p => p.VideoJob)
                                            .ThenInclude(p => p.VideoInfo)
                                            .ThenInclude(p => p.ApplicationUser)
                                            .SingleOrDefaultAsync(p => p.VideoJobId == createVideoJobApplicationModel.VideoJobId &&
                                                                  p.ApplicantApplicationUser.AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId,
                                                                  cancellationToken: cancellationToken);

            if (videoJobApplicationEntity is not null)
            {
                throw new CustomValidationException(Localizer[UserApplicationAlreadyExistsTextKey]);
            }
            var videoJobEntity = await FairplaytubeDatabaseContext.VideoJob
                                 .Include(p => p.VideoInfo).ThenInclude(p => p.ApplicationUser)
                                 .SingleAsync(p => p.VideoJobId == createVideoJobApplicationModel.VideoJobId,
                                              cancellationToken: cancellationToken);

            if (videoJobEntity.VideoInfo.ApplicationUser
                .AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId)
            {
                throw new CustomValidationException(Localizer[CannotApplyToOwnedVideosJobsTextKey]);
            }
            videoJobApplicationEntity = new VideoJobApplication()
            {
                ApplicantApplicationUserId = userEntity.ApplicationUserId,
                ApplicantCoverLetter       = createVideoJobApplicationModel.ApplicantCoverLetter,
                VideoJobId = createVideoJobApplicationModel.VideoJobId.Value,
                VideoJobApplicationStatusId = (short)Common.Global.Enums.VideoJobApplicationStatus.New
            };
            await FairplaytubeDatabaseContext.VideoJobApplication.AddAsync(videoJobApplicationEntity, cancellationToken);

            await FairplaytubeDatabaseContext.SaveChangesAsync(cancellationToken);

            string message = String.Format(Localizer[UserHasAppliedToJobTextKey],
                                           videoJobEntity.VideoInfo.ApplicationUser.FullName, videoJobEntity.Title);
            await HubContext.Clients.User(videoJobEntity.VideoInfo
                                          .ApplicationUser.AzureAdB2cobjectId.ToString())
            .ReceiveMessage(new Models.Notifications.NotificationModel()
            {
                Message = message
            });
        }
        // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.0&tabs=aspnetcore2x#per-request-dependencies
        public async Task Invoke(HttpContext context, CurrentUserProvider currentUser,
                                 PermissionService permissionService)
        {
            var userName = context.User.Identity.Name;

            _logger.LogInformation($"Invoke - {userName}");

            currentUser.SetIdentifier(userName);
            SecurityIdentity identity;

            lock (lockObj)
            {
                identity = permissionService.RegisterUserIfNotExists(userName ?? "Anonymous");
            }
            currentUser.SetUser(identity);

            await _next(context);
        }
Exemplo n.º 22
0
 public EditCar(CurrentUserProvider currentUserProvider)
 {
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 23
0
 public EditLocation(CurrentUserProvider currentUserProvider)
 {
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 24
0
 public UserIsLocationOwner(CurrentUserProvider currentUserProvider,
                            IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
Exemplo n.º 25
0
 public RejectInvitation(CurrentUserProvider currentUserProvider)
 {
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 26
0
 public AddCar(CurrentUserProvider currentUserProvider)
 {
     this.currentUserProvider = currentUserProvider;
 }
Exemplo n.º 27
0
 public InvitationForEmailDoesNotExist(CurrentUserProvider currentUserProvider,
                                       IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
Exemplo n.º 28
0
 public DeleteLocation(CurrentUserProvider currentUserProvider)
 {
     this.currentUserProvider = currentUserProvider;
 }
 public LocationWithNameDoesNotExist(CurrentUserProvider currentUserProvider,
                                     IDbContextProvider <ApplicationContext> databaseContextProvider)
 {
     this.currentUserProvider     = currentUserProvider;
     this.databaseContextProvider = databaseContextProvider;
 }
        public void GetCurrentUserOid_ThrowsException_WhenOidDoesNotExist()
        {
            var dut = new CurrentUserProvider();

            Assert.ThrowsException <Exception>(() => dut.GetCurrentUserOid());
        }