コード例 #1
0
        public object Get(string id)
        {
            BasicAuthId basicAuthId = new BasicAuthId(id);

            Site site = basicAuthId.SiteId == null ? null : SiteHelper.GetSite(basicAuthId.SiteId.Value);

            return(BasicAuthenticationHelper.ToJsonModel(site, basicAuthId.Path));
        }
コード例 #2
0
        private void ConfigureBasicAuthentication()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.BasicAuthResource.Guid, $"{Defines.BASIC_AUTH_PATH}/{{id?}}", new { controller = "BasicAuth" });

            hal.ProvideLink(Defines.BasicAuthResource.Guid, "self", basicAuth => new { href = $"/{Defines.BASIC_AUTH_PATH}/{basicAuth.id}" });

            hal.ProvideLink(Defines.AuthenticationResource.Guid, Defines.BasicAuthResource.Name, auth => {
                var authId      = new AuthenticationId((string)auth.id);
                Site site       = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);
                var basicAuthId = new BasicAuthId(authId.SiteId, authId.Path, BasicAuthenticationHelper.IsSectionLocal(site, authId.Path));
                return(new { href = $"/{Defines.BASIC_AUTH_PATH}/{basicAuthId.Uuid}" });
            });
        }
コード例 #3
0
        public void Delete(string id)
        {
            BasicAuthId basicAuthId = new BasicAuthId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (basicAuthId.SiteId != null) ? SiteHelper.GetSite(basicAuthId.SiteId.Value) : null;

            if (site == null)
            {
                return;
            }

            BasicAuthenticationHelper.GetSection(site, basicAuthId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();

            ManagementUnit.Current.Commit();
        }
コード例 #4
0
        public static object ToJsonModel(Site site, string path)
        {
            var section = GetSection(site, path);

            // Construct id passing possible site and application associated
            BasicAuthId id = new BasicAuthId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                id                   = id.Uuid,
                enabled              = section.Enabled,
                scope                = site == null ? string.Empty : site.Name + path,
                metadata             = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                default_logon_domain = section.DefaultLogonDomain,
                realm                = section.Realm,
                website              = site == null ? null : SiteHelper.ToJsonModelRef(site),
            };

            return(Environment.Hal.Apply(Defines.BasicAuthResource.Guid, obj));
        }
コード例 #5
0
        public async Task Delete(string id)
        {
            BasicAuthId basicAuthId = new BasicAuthId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (basicAuthId.SiteId != null) ? SiteHelper.GetSite(basicAuthId.SiteId.Value) : null;

            if (site != null)
            {
                BasicAuthenticationHelper.GetSection(site, basicAuthId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();
                ManagementUnit.Current.Commit();
            }

            if (basicAuthId.SiteId == null && BasicAuthenticationHelper.IsFeatureEnabled())
            {
                await BasicAuthenticationHelper.SetFeatureEnabled(false);
            }
        }
コード例 #6
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            BasicAuthId basicAuthId = new BasicAuthId(id);

            Site site = basicAuthId.SiteId == null ? null : SiteHelper.GetSite(basicAuthId.SiteId.Value);

            // Targetting section for a site, but unable to find that site
            if (basicAuthId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            BasicAuthenticationHelper.UpdateSettings(model, site, basicAuthId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(BasicAuthenticationHelper.ToJsonModel(site, basicAuthId.Path));
        }