Example #1
0
        public object Get(string id)
        {
            DigestAuthId digestAuthId = new DigestAuthId(id);

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

            return(DigestAuthenticationHelper.ToJsonModel(site, digestAuthId.Path));
        }
Example #2
0
        private void ConfigureDigestAuthentication()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.DigestAuthResource.Guid, $"{Defines.DIGEST_AUTH_PATH}/{{id?}}", new { controller = "DigestAuth" });

            hal.ProvideLink(Defines.DigestAuthResource.Guid, "self", digestAuth => new { href = $"/{Defines.DIGEST_AUTH_PATH}/{digestAuth.id}" });

            hal.ProvideLink(Defines.AuthenticationResource.Guid, Defines.DigestAuthResource.Name, auth => {
                var authId       = new AuthenticationId((string)auth.id);
                Site site        = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);
                var digestAuthId = new DigestAuthId(authId.SiteId, authId.Path, DigestAuthenticationHelper.IsSectionLocal(site, authId.Path));
                return(new { href = $"/{Defines.DIGEST_AUTH_PATH}/{digestAuthId.Uuid}" });
            });
        }
Example #3
0
        public void Delete(string id)
        {
            DigestAuthId digestAuthId = new DigestAuthId(id);

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

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

            if (site == null)
            {
                return;
            }

            DigestAuthenticationHelper.GetSection(site, digestAuthId.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
            DigestAuthId id = new DigestAuthId(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),
                realm    = section.Realm,
                website  = site == null ? null : SiteHelper.ToJsonModelRef(site),
            };

            return(Environment.Hal.Apply(Defines.DigestAuthResource.Guid, obj));
        }
Example #5
0
        public async Task Delete(string id)
        {
            DigestAuthId digestAuthId = new DigestAuthId(id);

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

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

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

            if (digestAuthId.SiteId == null && DigestAuthenticationHelper.IsFeatureEnabled())
            {
                await DigestAuthenticationHelper.SetFeatureEnabled(false);
            }
        }
Example #6
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            DigestAuthId digestAuthId = new DigestAuthId(id);

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

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

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

            DigestAuthenticationHelper.UpdateSettings(model, site, digestAuthId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(DigestAuthenticationHelper.ToJsonModel(site, digestAuthId.Path));
        }