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));
        }
Exemple #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}" });
            });
        }
        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();
        }
        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));
        }
Exemple #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);
            }
        }
        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));
        }