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