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

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

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

            router.MapWebApiRoute(Defines.AnonAuthResource.Guid, $"{Defines.ANON_AUTH_PATH}/{{id?}}", new { controller = "anonauth" });

            hal.ProvideLink(Defines.AnonAuthResource.Guid, "self", anonAuth => new { href = $"/{Defines.ANON_AUTH_PATH}/{anonAuth.id}" });

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

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

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

            if (site == null)
            {
                return;
            }

            AnonymousAuthenticationHelper.GetSection(site, authId.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
            AnonAuthId id = new AnonAuthId(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),
                user     = section.UserName,
                website  = site == null ? null : SiteHelper.ToJsonModelRef(site),
            };

            return(Core.Environment.Hal.Apply(Defines.AnonAuthResource.Guid, obj));
        }
コード例 #5
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            AnonAuthId authId = new AnonAuthId(id);

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

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

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

            AnonymousAuthenticationHelper.UpdateSettings(model, site, authId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(AnonymousAuthenticationHelper.ToJsonModel(site, authId.Path));
        }