Exemplo n.º 1
0
 public UserService(
     IAppConfiguration config,
     IEntityRepository <User> userRepository,
     IEntityRepository <Credential> credentialRepository,
     IEntityRepository <Organization> organizationRepository,
     IAuditingService auditing,
     IEntitiesContext entitiesContext,
     IContentObjectService contentObjectService,
     ISecurityPolicyService securityPolicyService,
     IDateTimeProvider dateTimeProvider,
     ICredentialBuilder credentialBuilder,
     ITelemetryService telemetryService,
     IDiagnosticsService diagnosticsService)
     : this()
 {
     Config                 = config;
     UserRepository         = userRepository;
     CredentialRepository   = credentialRepository;
     OrganizationRepository = organizationRepository;
     Auditing               = auditing;
     EntitiesContext        = entitiesContext;
     ContentObjectService   = contentObjectService;
     SecurityPolicyService  = securityPolicyService;
     DateTimeProvider       = dateTimeProvider;
     TelemetryService       = telemetryService;
     DiagnosticsSource      = diagnosticsService.SafeGetSource(nameof(UserService));
 }
Exemplo n.º 2
0
        public AccountsController(
            AuthenticationService authenticationService,
            IPackageService packageService,
            IMessageService messageService,
            IUserService userService,
            ITelemetryService telemetryService,
            ISecurityPolicyService securityPolicyService,
            ICertificateService certificateService,
            IContentObjectService contentObjectService,
            IMessageServiceConfiguration messageServiceConfiguration,
            IDeleteAccountService deleteAccountService,
            IIconUrlProvider iconUrlProvider,
            IGravatarProxyService gravatarProxy)
        {
            AuthenticationService       = authenticationService ?? throw new ArgumentNullException(nameof(authenticationService));
            PackageService              = packageService ?? throw new ArgumentNullException(nameof(packageService));
            MessageService              = messageService ?? throw new ArgumentNullException(nameof(messageService));
            UserService                 = userService ?? throw new ArgumentNullException(nameof(userService));
            TelemetryService            = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
            SecurityPolicyService       = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
            CertificateService          = certificateService ?? throw new ArgumentNullException(nameof(certificateService));
            ContentObjectService        = contentObjectService ?? throw new ArgumentNullException(nameof(contentObjectService));
            MessageServiceConfiguration = messageServiceConfiguration ?? throw new ArgumentNullException(nameof(messageServiceConfiguration));
            DeleteAccountService        = deleteAccountService ?? throw new ArgumentNullException(nameof(deleteAccountService));
            IconUrlProvider             = iconUrlProvider ?? throw new ArgumentNullException(nameof(iconUrlProvider));
            GravatarProxy               = gravatarProxy ?? throw new ArgumentNullException(nameof(gravatarProxy));

            _deleteAccountListPackageItemViewModelFactory = new DeleteAccountListPackageItemViewModelFactory(PackageService, IconUrlProvider);
        }
Exemplo n.º 3
0
 public UsersController(
     ICuratedFeedService feedsQuery,
     IUserService userService,
     IPackageService packageService,
     IPackageOwnerRequestService packageOwnerRequestService,
     IMessageService messageService,
     IAppConfiguration config,
     AuthenticationService authService,
     ICredentialBuilder credentialBuilder,
     IDeleteAccountService deleteAccountService,
     ISupportRequestService supportRequestService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService,
     IContentObjectService contentObjectService)
     : base(
         authService,
         feedsQuery,
         packageService,
         messageService,
         userService,
         telemetryService,
         securityPolicyService,
         certificateService,
         contentObjectService)
 {
     _packageOwnerRequestService = packageOwnerRequestService ?? throw new ArgumentNullException(nameof(packageOwnerRequestService));
     _config                = config ?? throw new ArgumentNullException(nameof(config));
     _credentialBuilder     = credentialBuilder ?? throw new ArgumentNullException(nameof(credentialBuilder));
     _deleteAccountService  = deleteAccountService ?? throw new ArgumentNullException(nameof(deleteAccountService));
     _supportRequestService = supportRequestService ?? throw new ArgumentNullException(nameof(supportRequestService));
 }
Exemplo n.º 4
0
 public DeleteAccountService(IEntityRepository <AccountDelete> accountDeleteRepository,
                             IEntityRepository <User> userRepository,
                             IEntityRepository <Scope> scopeRepository,
                             IEntitiesContext entitiesContext,
                             IPackageService packageService,
                             IPackageOwnershipManagementService packageOwnershipManagementService,
                             IReservedNamespaceService reservedNamespaceService,
                             ISecurityPolicyService securityPolicyService,
                             AuthenticationService authService,
                             ISupportRequestService supportRequestService,
                             IAuditingService auditingService,
                             ITelemetryService telemetryService
                             )
 {
     _accountDeleteRepository           = accountDeleteRepository ?? throw new ArgumentNullException(nameof(accountDeleteRepository));
     _userRepository                    = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
     _scopeRepository                   = scopeRepository ?? throw new ArgumentNullException(nameof(scopeRepository));
     _entitiesContext                   = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext));
     _packageService                    = packageService ?? throw new ArgumentNullException(nameof(packageService));
     _packageOwnershipManagementService = packageOwnershipManagementService ?? throw new ArgumentNullException(nameof(packageOwnershipManagementService));
     _reservedNamespaceService          = reservedNamespaceService ?? throw new ArgumentNullException(nameof(reservedNamespaceService));
     _securityPolicyService             = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
     _authService           = authService ?? throw new ArgumentNullException(nameof(authService));
     _supportRequestService = supportRequestService ?? throw new ArgumentNullException(nameof(supportRequestService));
     _auditingService       = auditingService ?? throw new ArgumentNullException(nameof(auditingService));
     _telemetryService      = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
 }
Exemplo n.º 5
0
 public OrganizationsController(
     AuthenticationService authService,
     IMessageService messageService,
     IUserService userService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService,
     IPackageService packageService,
     IDeleteAccountService deleteAccountService,
     IContentObjectService contentObjectService,
     IMessageServiceConfiguration messageServiceConfiguration,
     IIconUrlProvider iconUrlProvider)
     : base(
         authService,
         packageService,
         messageService,
         userService,
         telemetryService,
         securityPolicyService,
         certificateService,
         contentObjectService,
         messageServiceConfiguration,
         deleteAccountService,
         iconUrlProvider)
 {
 }
Exemplo n.º 6
0
 public OrganizationsController(
     AuthenticationService authService,
     IMessageService messageService,
     IUserService userService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService,
     IPackageService packageService,
     IDeleteAccountService deleteAccountService,
     IContentObjectService contentObjectService,
     IMessageServiceConfiguration messageServiceConfiguration,
     IIconUrlProvider iconUrlProvider,
     IFeatureFlagService features,
     IGravatarProxyService gravatarProxy)
     : base(
         authService,
         packageService,
         messageService,
         userService,
         telemetryService,
         securityPolicyService,
         certificateService,
         contentObjectService,
         messageServiceConfiguration,
         deleteAccountService,
         iconUrlProvider,
         gravatarProxy)
 {
     _features = features ?? throw new ArgumentNullException(nameof(features));
 }
Exemplo n.º 7
0
 public ApiController(
     IApiScopeEvaluator apiScopeEvaluator,
     IEntitiesContext entitiesContext,
     IPackageService packageService,
     IPackageFileService packageFileService,
     IUserService userService,
     INuGetExeDownloaderService nugetExeDownloaderService,
     IContentService contentService,
     IIndexingService indexingService,
     ISearchService searchService,
     IAutomaticallyCuratePackageCommand autoCuratePackage,
     IStatusService statusService,
     IStatisticsService statisticsService,
     IMessageService messageService,
     IAuditingService auditingService,
     IGalleryConfigurationService configurationService,
     ITelemetryService telemetryService,
     AuthenticationService authenticationService,
     ICredentialBuilder credentialBuilder,
     ISecurityPolicyService securityPolicies,
     IReservedNamespaceService reservedNamespaceService,
     IPackageUploadService packageUploadService)
     : this(apiScopeEvaluator, entitiesContext, packageService, packageFileService, userService, nugetExeDownloaderService, contentService,
            indexingService, searchService, autoCuratePackage, statusService, messageService, auditingService,
            configurationService, telemetryService, authenticationService, credentialBuilder, securityPolicies,
            reservedNamespaceService, packageUploadService)
 {
     StatisticsService = statisticsService;
 }
 public ListPackageItemRequiredSignerViewModelFactory(
     ISecurityPolicyService securityPolicyService,
     IIconUrlProvider iconUrlProvider,
     IPackageVulnerabilitiesService packageVulnerabilitiesService)
 {
     _listPackageItemViewModelFactory = new ListPackageItemViewModelFactory(iconUrlProvider);
     _securityPolicyService           = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
     _packageVulnerabilitiesService   = packageVulnerabilitiesService ?? throw new ArgumentNullException(nameof(packageVulnerabilitiesService));
 }
Exemplo n.º 9
0
 public PackageService(
     IEntityRepository <PackageRegistration> packageRegistrationRepository,
     IEntityRepository <Package> packageRepository,
     IEntityRepository <Certificate> certificateRepository,
     IAuditingService auditingService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService)
     : base(packageRepository, packageRegistrationRepository, certificateRepository)
 {
     _auditingService       = auditingService ?? throw new ArgumentNullException(nameof(auditingService));
     _telemetryService      = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     _securityPolicyService = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
 }
Exemplo n.º 10
0
 public JsonApiController(
     IPackageService packageService,
     IUserService userService,
     IMessageService messageService,
     IAppConfiguration appConfiguration,
     ISecurityPolicyService policyService,
     IPackageOwnershipManagementService packageOwnershipManagementService)
 {
     _packageService   = packageService;
     _userService      = userService;
     _messageService   = messageService;
     _appConfiguration = appConfiguration;
     _policyService    = policyService;
     _packageOwnershipManagementService = packageOwnershipManagementService;
 }
Exemplo n.º 11
0
 public JsonApiController(
     IPackageService packageService,
     IUserService userService,
     IEntityRepository <PackageOwnerRequest> packageOwnerRequestRepository,
     IMessageService messageService,
     IAppConfiguration appConfiguration,
     ISecurityPolicyService policyService)
 {
     _packageService = packageService;
     _userService    = userService;
     _packageOwnerRequestRepository = packageOwnerRequestRepository;
     _messageService   = messageService;
     _appConfiguration = appConfiguration;
     _policyService    = policyService;
 }
Exemplo n.º 12
0
 public UserService(
     IAppConfiguration config,
     IEntityRepository <User> userRepository,
     IEntityRepository <Credential> credentialRepository,
     IAuditingService auditing,
     IEntitiesContext entitiesContext,
     IContentObjectService contentObjectService,
     ISecurityPolicyService securityPolicyService)
     : this()
 {
     Config                = config;
     UserRepository        = userRepository;
     CredentialRepository  = credentialRepository;
     Auditing              = auditing;
     EntitiesContext       = entitiesContext;
     ContentObjectService  = contentObjectService;
     SecurityPolicyService = securityPolicyService;
 }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            // Add a warning header if the API key is about to expire (or has expired)
            var identity   = filterContext.HttpContext.User.Identity as ClaimsIdentity;
            var controller = filterContext.Controller as AppController;

            if (identity != null && identity.IsAuthenticated && identity.AuthenticationType == AuthenticationTypes.ApiKey && controller != null)
            {
                var apiKey = identity.GetClaimOrDefault(NuGetClaims.ApiKey);

                var user = controller.GetCurrentUser();

                var apiKeyCredential = user.Credentials.FirstOrDefault(c => c.Value == apiKey);
                if (apiKeyCredential != null && apiKeyCredential.Expires.HasValue)
                {
                    var accountUrl = controller.NuGetContext.Config.GetSiteRoot(
                        controller.NuGetContext.Config.Current.RequireSSL).TrimEnd('/') + "/account";

                    var expirationPeriod = apiKeyCredential.Expires.Value - DateTime.UtcNow;
                    if (apiKeyCredential.HasExpired)
                    {
                        // expired warning
                        filterContext.HttpContext.Response.Headers.Add(
                            Constants.WarningHeaderName,
                            string.Format(CultureInfo.InvariantCulture, Strings.WarningApiKeyExpired, accountUrl));
                    }
                    else if (expirationPeriod.TotalDays <= controller.NuGetContext.Config.Current.WarnAboutExpirationInDaysForApiKeyV1)
                    {
                        // about to expire warning
                        filterContext.HttpContext.Response.Headers.Add(
                            Constants.WarningHeaderName,
                            string.Format(CultureInfo.InvariantCulture, Strings.WarningApiKeyAboutToExpire, expirationPeriod.TotalDays, accountUrl));
                    }
                }
            }

            // Resolve the policy service if security policy checks are required.
            if (SecurityPolicyAction.HasValue)
            {
                SecurityPolicyService = ((AppController)filterContext.Controller)?.GetService <ISecurityPolicyService>();
            }

            base.OnAuthorization(filterContext);
        }
Exemplo n.º 14
0
 public ApiController(
     IApiScopeEvaluator apiScopeEvaluator,
     IEntitiesContext entitiesContext,
     IPackageService packageService,
     IPackageFileService packageFileService,
     IUserService userService,
     INuGetExeDownloaderService nugetExeDownloaderService,
     IContentService contentService,
     IIndexingService indexingService,
     ISearchService searchService,
     IAutomaticallyCuratePackageCommand autoCuratePackage,
     IStatusService statusService,
     IMessageService messageService,
     IAuditingService auditingService,
     IGalleryConfigurationService configurationService,
     ITelemetryService telemetryService,
     AuthenticationService authenticationService,
     ICredentialBuilder credentialBuilder,
     ISecurityPolicyService securityPolicies,
     IReservedNamespaceService reservedNamespaceService,
     IPackageUploadService packageUploadService)
 {
     ApiScopeEvaluator         = apiScopeEvaluator;
     EntitiesContext           = entitiesContext;
     PackageService            = packageService;
     PackageFileService        = packageFileService;
     UserService               = userService;
     NugetExeDownloaderService = nugetExeDownloaderService;
     ContentService            = contentService;
     IndexingService           = indexingService;
     SearchService             = searchService;
     AutoCuratePackage         = autoCuratePackage;
     StatusService             = statusService;
     MessageService            = messageService;
     AuditingService           = auditingService;
     ConfigurationService      = configurationService;
     TelemetryService          = telemetryService;
     AuthenticationService     = authenticationService;
     CredentialBuilder         = credentialBuilder;
     SecurityPolicyService     = securityPolicies;
     ReservedNamespaceService  = reservedNamespaceService;
     PackageUploadService      = packageUploadService;
     StatisticsService         = null;
 }
Exemplo n.º 15
0
 public AccountsController(
     AuthenticationService authenticationService,
     ICuratedFeedService curatedFeedService,
     IPackageService packageService,
     IMessageService messageService,
     IUserService userService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService)
 {
     AuthenticationService = authenticationService ?? throw new ArgumentNullException(nameof(authenticationService));
     CuratedFeedService    = curatedFeedService ?? throw new ArgumentNullException(nameof(curatedFeedService));
     PackageService        = packageService ?? throw new ArgumentNullException(nameof(packageService));
     MessageService        = messageService ?? throw new ArgumentNullException(nameof(messageService));
     UserService           = userService ?? throw new ArgumentNullException(nameof(userService));
     TelemetryService      = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     SecurityPolicyService = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
     CertificateService    = certificateService ?? throw new ArgumentNullException(nameof(certificateService));
 }
 public PackageService(
     IEntityRepository <PackageRegistration> packageRegistrationRepository,
     IEntityRepository <Package> packageRepository,
     IEntityRepository <Certificate> certificateRepository,
     IAuditingService auditingService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     IEntitiesContext entitiesContext,
     IContentObjectService contentObjectService,
     IFeatureFlagService featureFlagService)
     : base(packageRepository, packageRegistrationRepository, certificateRepository)
 {
     _auditingService       = auditingService ?? throw new ArgumentNullException(nameof(auditingService));
     _telemetryService      = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     _securityPolicyService = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
     _entitiesContext       = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext));
     _contentObjectService  = contentObjectService ?? throw new ArgumentNullException(nameof(contentObjectService));
     _featureFlagService    = featureFlagService ?? throw new ArgumentNullException(nameof(featureFlagService));
 }
 public OrganizationsController(
     AuthenticationService authService,
     ICuratedFeedService curatedFeedService,
     IMessageService messageService,
     IUserService userService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService,
     IPackageService packageService,
     IDeleteAccountService deleteAccountService)
     : base(
         authService,
         curatedFeedService,
         packageService,
         messageService,
         userService,
         telemetryService,
         securityPolicyService,
         certificateService)
 {
     DeleteAccountService = deleteAccountService;
 }
Exemplo n.º 18
0
        public UsersController(
            IUserService userService,
            IPackageService packageService,
            IPackageOwnerRequestService packageOwnerRequestService,
            IMessageService messageService,
            IAppConfiguration config,
            AuthenticationService authService,
            ICredentialBuilder credentialBuilder,
            IDeleteAccountService deleteAccountService,
            ISupportRequestService supportRequestService,
            ITelemetryService telemetryService,
            ISecurityPolicyService securityPolicyService,
            ICertificateService certificateService,
            IContentObjectService contentObjectService,
            IFeatureFlagService featureFlagService,
            IMessageServiceConfiguration messageServiceConfiguration,
            IIconUrlProvider iconUrlProvider)
            : base(
                authService,
                packageService,
                messageService,
                userService,
                telemetryService,
                securityPolicyService,
                certificateService,
                contentObjectService,
                messageServiceConfiguration,
                deleteAccountService,
                iconUrlProvider)
        {
            _packageOwnerRequestService = packageOwnerRequestService ?? throw new ArgumentNullException(nameof(packageOwnerRequestService));
            _config                = config ?? throw new ArgumentNullException(nameof(config));
            _credentialBuilder     = credentialBuilder ?? throw new ArgumentNullException(nameof(credentialBuilder));
            _supportRequestService = supportRequestService ?? throw new ArgumentNullException(nameof(supportRequestService));
            _featureFlagService    = featureFlagService ?? throw new ArgumentNullException(nameof(featureFlagService));

            _listPackageItemRequiredSignerViewModelFactory = new ListPackageItemRequiredSignerViewModelFactory(securityPolicyService, iconUrlProvider);
            _listPackageItemViewModelFactory = new ListPackageItemViewModelFactory(iconUrlProvider);
        }
        private static bool CanEditRequiredSigner(Package package, User currentUser, ISecurityPolicyService securityPolicyService, IEnumerable <User> owners)
        {
            var currentUserCanManageRequiredSigner  = false;
            var currentUserHasRequiredSignerControl = false;
            var noOwnerHasRequiredSignerControl     = true;

            foreach (var owner in owners)
            {
                if (!currentUserCanManageRequiredSigner &&
                    ActionsRequiringPermissions.ManagePackageRequiredSigner.CheckPermissions(currentUser, owner, package)
                    == PermissionsCheckResult.Allowed)
                {
                    currentUserCanManageRequiredSigner = true;
                }

                if (!currentUserHasRequiredSignerControl)
                {
                    if (securityPolicyService.IsSubscribed(owner, ControlRequiredSignerPolicy.PolicyName))
                    {
                        noOwnerHasRequiredSignerControl = false;

                        if (owner == currentUser)
                        {
                            currentUserHasRequiredSignerControl = true;
                        }
                        else
                        {
                            currentUserHasRequiredSignerControl = (owner as Organization)?.GetMembershipOfUser(currentUser)?.IsAdmin ?? false;
                        }
                    }
                }
            }

            var canEditRequiredSigned = currentUserCanManageRequiredSigner &&
                                        (currentUserHasRequiredSignerControl || noOwnerHasRequiredSignerControl);

            return(canEditRequiredSigned);
        }
Exemplo n.º 20
0
 public AccountsController(
     AuthenticationService authenticationService,
     IPackageService packageService,
     IMessageService messageService,
     IUserService userService,
     ITelemetryService telemetryService,
     ISecurityPolicyService securityPolicyService,
     ICertificateService certificateService,
     IContentObjectService contentObjectService,
     IMessageServiceConfiguration messageServiceConfiguration,
     IDeleteAccountService deleteAccountService)
 {
     AuthenticationService       = authenticationService ?? throw new ArgumentNullException(nameof(authenticationService));
     PackageService              = packageService ?? throw new ArgumentNullException(nameof(packageService));
     MessageService              = messageService ?? throw new ArgumentNullException(nameof(messageService));
     UserService                 = userService ?? throw new ArgumentNullException(nameof(userService));
     TelemetryService            = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     SecurityPolicyService       = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
     CertificateService          = certificateService ?? throw new ArgumentNullException(nameof(certificateService));
     ContentObjectService        = contentObjectService ?? throw new ArgumentNullException(nameof(contentObjectService));
     MessageServiceConfiguration = messageServiceConfiguration ?? throw new ArgumentNullException(nameof(messageServiceConfiguration));
     DeleteAccountService        = deleteAccountService ?? throw new ArgumentNullException(nameof(deleteAccountService));
 }
Exemplo n.º 21
0
 public UserService(
     IAppConfiguration config,
     IEntityRepository <User> userRepository,
     IEntityRepository <Credential> credentialRepository,
     IEntityRepository <Organization> organizationRepository,
     IAuditingService auditing,
     IEntitiesContext entitiesContext,
     IContentObjectService contentObjectService,
     ISecurityPolicyService securityPolicyService,
     IDateTimeProvider dateTimeProvider,
     ICredentialBuilder credentialBuilder)
     : this()
 {
     Config                 = config;
     UserRepository         = userRepository;
     CredentialRepository   = credentialRepository;
     OrganizationRepository = organizationRepository;
     Auditing               = auditing;
     EntitiesContext        = entitiesContext;
     ContentObjectService   = contentObjectService;
     SecurityPolicyService  = securityPolicyService;
     DateTimeProvider       = dateTimeProvider;
 }
        public ListPackageItemRequiredSignerViewModel(
            Package package,
            User currentUser,
            ISecurityPolicyService securityPolicyService,
            bool wasMultiFactorAuthenticated)
            : base(package, currentUser)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

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

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

            var owners = package.PackageRegistration?.Owners ?? Enumerable.Empty <User>();

            if (owners.Any())
            {
                ShowRequiredSigner = true;

                var currentUserCanManageRequiredSigner  = false;
                var currentUserHasRequiredSignerControl = false;
                var noOwnerHasRequiredSignerControl     = true;

                foreach (var owner in owners)
                {
                    if (!currentUserCanManageRequiredSigner &&
                        ActionsRequiringPermissions.ManagePackageRequiredSigner.CheckPermissions(currentUser, owner, package)
                        == PermissionsCheckResult.Allowed)
                    {
                        currentUserCanManageRequiredSigner = true;
                    }

                    if (!currentUserHasRequiredSignerControl)
                    {
                        if (securityPolicyService.IsSubscribed(owner, ControlRequiredSignerPolicy.PolicyName))
                        {
                            noOwnerHasRequiredSignerControl = false;

                            if (owner == currentUser)
                            {
                                currentUserHasRequiredSignerControl = true;
                            }
                            else
                            {
                                currentUserHasRequiredSignerControl = (owner as Organization)?.GetMembershipOfUser(currentUser)?.IsAdmin ?? false;
                            }
                        }
                    }
                }

                CanEditRequiredSigner = currentUserCanManageRequiredSigner &&
                                        (currentUserHasRequiredSignerControl || noOwnerHasRequiredSignerControl);

                var requiredSigner = package.PackageRegistration?.RequiredSigners.FirstOrDefault();

                if (requiredSigner == null)
                {
                    if (owners.Count() == 1)
                    {
                        RequiredSigner = Convert(owners.Single());
                    }
                    else
                    {
                        RequiredSigner = AnySigner;
                    }
                }
                else
                {
                    RequiredSigner = Convert(requiredSigner);
                }

                if (CanEditRequiredSigner)
                {
                    if (owners.Count() == 1)
                    {
                        if (requiredSigner != null && requiredSigner != currentUser)
                        {
                            // Suppose users A and B own a package and user A is the required signer.
                            // Then suppose user A removes herself as package owner.
                            // User B must be able to change the required signer.
                            AllSigners = new[] { RequiredSigner, Convert(currentUser) };
                        }
                        else
                        {
                            AllSigners            = Enumerable.Empty <SignerViewModel>();
                            CanEditRequiredSigner = false;
                            ShowTextBox           = true;
                        }
                    }
                    else
                    {
                        AllSigners = new[] { AnySigner }.Concat(owners.Select(owner => Convert(owner)));
                    }
                }
                else
                {
                    AllSigners = new[] { RequiredSigner };

                    var ownersWithRequiredSignerControl = owners.Where(
                        owner => securityPolicyService.IsSubscribed(owner, ControlRequiredSignerPolicy.PolicyName));

                    if (owners.Count() == 1)
                    {
                        ShowTextBox = true;
                    }
                    else
                    {
                        RequiredSignerMessage = GetRequiredSignerMessage(ownersWithRequiredSignerControl);
                    }
                }

                CanEditRequiredSigner &= wasMultiFactorAuthenticated;
            }
        }
Exemplo n.º 23
0
 public SecurityPolicyController(IEntitiesContext entitiesContext, ISecurityPolicyService policyService)
 {
     EntitiesContext = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext));
     PolicyService   = policyService ?? throw new ArgumentNullException(nameof(policyService));
 }
Exemplo n.º 24
0
 public UserSecurityPolicySubscriptionContext(ISecurityPolicyService policyService, User user)
 {
     PolicyService = policyService ?? throw new ArgumentNullException(nameof(policyService));
     User          = user ?? throw new ArgumentNullException(nameof(user));
 }