Ejemplo n.º 1
0
 public ApiKeyAuthenticationHandler(
     IOptionsMonitor <ApiKeyAuthenticationOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     ApiKeysService apiKeyService) : base(options, logger, encoder, clock)
 {
     _apiKeyService = apiKeyService;
 }
        public ControllerService()
        {
            this.scopeProvider = ConnectorContext.ScopeProvider;
            using (var scope = scopeProvider.CreateScope(autoComplete: true))
            {
                this.database = scope.Database;
                ApiKeyCache.UpdateCache(scope.Database);
            }
            this.userGroupService = new UserGroupService(ConnectorContext.UserService, database, ConnectorContext.Logger);
            this.languageService  = new LanguageDictionaryService(ConnectorContext.LocalizationService, ConnectorContext.DomainService, ConnectorContext.Logger);
            this.homeNode         = new HomeContentNode(ConnectorContext.ContentService, ConnectorContext.LocalizationService, ConnectorContext.DomainService, ConnectorContext.ContentTypeService, ConnectorContext.Logger);
            this.apiService       = new ApiKeysService(database);
            this.nodeHelper       = new NodeHelper();

            SaveAndPublish = bool.Parse(TenantGenerationOptions.SaveAndPublish);
            SecureUrls     = bool.Parse(TenantGenerationOptions.SecureUrls);
            SetupLocalUrls = bool.Parse(TenantGenerationOptions.SetupLocalUrls);

#if DEBUG
            SetupLocalUrls = true;
#endif
        }
        public ExtendedTenant EditTenant(TenantData tenant, TenantUser user = null, TenantGroup group = null)
        {
            var mediaService = new HomeMediaNode(ConnectorContext.MediaService, ConnectorContext.Logger, ConnectorContext.ContentTypeBaseService);
            var tenantNode   = nodeHelper.GetTenantRoot(tenant.TenantUId);

            languageService.CreateDictionary(tenant);

            if (user != null)
            {
                userGroupService.UpdateUser(user);
            }

            IUserGroup g = null;

            if (group != null)
            {
                if (!string.IsNullOrWhiteSpace(group.RenameGroupTo))
                {
                    g = userGroupService.EditGroup(group.Name, group);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(tenant.ReadOnlyGroupAlias))
                {
                    g = userGroupService.GetUserGroup(tenant.ReadOnlyGroupAlias);
                }
            }

            var mediaId = mediaService.RenameMediaHome(tenant, user);

            tenant.TenantPreferences.PaymentSettings = tenant.PaymentSettings; //little hack to match total coding system submission to umbraco properties
            tenant.PaymentSettings = null;

            var extended = new ExtendedTenant
            {
                Tenant                = tenant,
                StartContentId        = tenantNode.Id,
                StartMediaId          = mediaId,
                AllowedSectionAliases = g?.AllowedSections,
                Permissions           = g?.Permissions,
            };

            homeNode.EditTenant(tenant);
            nodeHelper.AddLanguageVersionToNode(extended.Tenant);

            extended.Tenant.Username = user?.Username;
            extended.Tenant.Name     = user?.Name;
            extended.Tenant.Email    = user?.Email;
            extended.Tenant.Password = user != null ? "*********" : null;
            extended.Tenant.Group    = group?.Name;
            extended.UserId          = user?.AssignedUmbracoUserId ?? 0;

            if (!string.IsNullOrEmpty(extended.Tenant.AppId) || !string.IsNullOrEmpty(extended.Tenant.ApiKey))
            {
                var apiService = new ApiKeysService(this.database);
                apiService.UpdateApiForTenant(extended);
            }

            if (SaveAndPublish)
            {
                new NodeHelper().TryPublishSite(tenantNode.Id);
            }

            return(extended);
        }
Ejemplo n.º 4
0
 public ApiKeysServiceTests()
 {
     this.context = this.DatabaseInstance;
     this.mockRandomKeyGenerator = new Mock <IRandomKeyGenerator>();
     this.service = new ApiKeysService(new Repository <ApiKey>(context), mockRandomKeyGenerator.Object);
 }