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));
        }
        public object Get()
        {
            // Check if the scope of the request is for site or application
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

            return(BasicAuthenticationHelper.ToJsonModel(site, path));
        }
Ejemplo n.º 3
0
        public async Task <object> Post()
        {
            if (BasicAuthenticationHelper.IsFeatureEnabled())
            {
                throw new AlreadyExistsException(BasicAuthenticationHelper.FEATURE_NAME);
            }

            await BasicAuthenticationHelper.SetFeatureEnabled(true);

            dynamic auth = BasicAuthenticationHelper.ToJsonModel(null, null);

            return(Created(BasicAuthenticationHelper.GetLocation(auth.id), auth));
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 6
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));
        }