public Page Post([FromBody] Page page) { if (ModelState.IsValid) { string permissions; if (page.ParentId != null) { permissions = _pages.GetPage(page.ParentId.Value).Permissions; } else { permissions = _permissionRepository.EncodePermissions(new List <Permission> { new Permission(PermissionNames.Edit, Constants.AdminRole, true) }); } if (_userPermissions.IsAuthorized(User, PermissionNames.Edit, permissions)) { page = _pages.AddPage(page); _syncManager.AddSyncEvent(EntityNames.Site, page.SiteId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page); } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Page {Page}", page); HttpContext.Response.StatusCode = 401; page = null; } } return(page); }
public UserRole Post([FromBody] UserRole userRole) { var role = _roles.GetRole(userRole.RoleId); if (ModelState.IsValid && role != null && role.SiteId == _alias.SiteId && (User.IsInRole(RoleNames.Host) || role.Name != RoleNames.Host)) { if (role.Name == RoleNames.Host) { // host roles can only exist at global level - remove all site specific user roles _userRoles.DeleteUserRoles(userRole.UserId); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Roles Deleted For UserId {UserId}", userRole.UserId); } userRole = _userRoles.AddUserRole(userRole); _logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, userRole.UserId); } else { _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized UserRole Post Attempt {UserRole}", userRole); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; userRole = null; } return(userRole); }
public UserRole Post([FromBody] UserRole userRole) { if (ModelState.IsValid) { userRole = _userRoles.AddUserRole(userRole); _syncManager.AddSyncEvent(EntityNames.User, userRole.UserId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole); } return(userRole); }
public Page Post([FromBody] Page page) { if (ModelState.IsValid && page.SiteId == _alias.SiteId) { string permissions; if (page.ParentId != null) { permissions = _pages.GetPage(page.ParentId.Value).Permissions; } else { permissions = new List <Permission> { new Permission(PermissionNames.Edit, RoleNames.Admin, true) }.EncodePermissions(); } if (_userPermissions.IsAuthorized(User, PermissionNames.Edit, permissions)) { page = _pages.AddPage(page); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page); if (!page.Path.StartsWith("admin/")) { var modules = _modules.GetModules(page.SiteId).Where(item => item.AllPages).ToList(); foreach (Module module in modules) { var pageModule = _pageModules.GetPageModules(page.SiteId).FirstOrDefault(item => item.ModuleId == module.ModuleId); _pageModules.AddPageModule(new PageModule { PageId = page.PageId, ModuleId = pageModule.ModuleId, Title = pageModule.Title, Pane = pageModule.Pane, Order = pageModule.Order, ContainerType = pageModule.ContainerType }); } } } else { _logger.Log(LogLevel.Warning, this, LogFunction.Create, "User Not Authorized To Add Page {Page}", page); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; page = null; } } else { _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Page Post Attempt {Page}", page); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; page = null; } return(page); }
public async Task <User> Put(int id, [FromBody] User user) { if (ModelState.IsValid) { if (User.IsInRole(RoleNames.Admin) || User.Identity.Name == user.Username) { if (user.Password != "") { IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); if (identityuser != null) { identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, user.Password); await _identityUserManager.UpdateAsync(identityuser); } } user = _users.UpdateUser(user); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, user.UserId); user.Password = ""; // remove sensitive information _logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", user); } else { _logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", user); HttpContext.Response.StatusCode = 401; user = null; } } return(user); }
public PageModule Post([FromBody] PageModule pageModule) { if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, pageModule.PageId, PermissionNames.Edit)) { pageModule = _pageModules.AddPageModule(pageModule); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Page, pageModule.PageId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", pageModule); } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add PageModule {PageModule}", pageModule); HttpContext.Response.StatusCode = 401; pageModule = null; } return(pageModule); }
public Module Post([FromBody] Module module) { if (ModelState.IsValid && module.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, EntityNames.Page, module.PageId, PermissionNames.Edit)) { module = _modules.AddModule(module); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", module); } else { _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Module Post Attempt {Module}", module); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; module = null; } return(module); }
public async Task <User> Put(int id, [FromBody] User user) { if (ModelState.IsValid && user.SiteId == _alias.SiteId && _users.GetUser(user.UserId, false) != null && (User.IsInRole(RoleNames.Admin) || User.Identity.Name == user.Username)) { if (user.Password != "") { IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); if (identityuser != null) { identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, user.Password); await _identityUserManager.UpdateAsync(identityuser); } } user = _users.UpdateUser(user); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, user.UserId); user.Password = ""; // remove sensitive information _logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", user); } else { user.Password = ""; // remove sensitive information _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Post Attempt {User}", user); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; user = null; } return(user); }
public PageModule Post([FromBody] PageModule pageModule) { var page = _pages.GetPage(pageModule.PageId); if (ModelState.IsValid && page != null && page.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, EntityNames.Page, pageModule.PageId, PermissionNames.Edit)) { pageModule = _pageModules.AddPageModule(pageModule); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", pageModule); } else { _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized PageModule Post Attempt {PageModule}", pageModule); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; pageModule = null; } return(pageModule); }
public Setting Post([FromBody] Setting setting) { if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit)) { setting = _settings.AddSetting(setting); if (setting.EntityName == EntityNames.Module) { _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId); } _logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting); } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", setting); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; setting = null; } return(setting); }
public Site Put(int id, [FromBody] Site site) { if (ModelState.IsValid) { site = _sites.UpdateSite(site); _syncManager.AddSyncEvent(EntityNames.Site, site.SiteId); _logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", site); } return(site); }
public UserRole Post([FromBody] UserRole userRole) { var role = _roles.GetRole(userRole.RoleId); if (ModelState.IsValid && (User.IsInRole(RoleNames.Host) || role.Name != RoleNames.Host)) { if (role.Name == RoleNames.Host) { // host roles can only exist at global level - remove all site specific user roles _userRoles.DeleteUserRoles(userRole.UserId); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Roles Deleted For UserId {UserId}", userRole.UserId); } userRole = _userRoles.AddUserRole(userRole); _logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, userRole.UserId); } return(userRole); }
private void AddSyncEvent(string EntityName) { switch (EntityName) { case EntityNames.Module: case EntityNames.Page: case EntityNames.Site: _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId); break; } }
public Site Put(int id, [FromBody] Site site) { if (ModelState.IsValid && site.SiteId == _alias.SiteId && site.TenantId == _alias.TenantId && _sites.GetSite(site.SiteId, false) != null) { site = _sites.UpdateSite(site); _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, site.SiteId); _logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", site); } else { _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Put Attempt {Site}", site); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; site = null; } return(site); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISyncManager sync) { ServiceActivator.Configure(app.ApplicationServices); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebAssemblyDebugging(); app.UseForwardedHeaders(); } else { app.UseForwardedHeaders(); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // execute any IServerStartup logic app.ConfigureOqtaneAssemblies(env); // Allow oqtane localization middleware app.UseOqtaneLocalization(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseTenantResolution(); app.UseBlazorFrameworkFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); if (_useSwagger) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/" + Constants.Version + "/swagger.json", Constants.PackageId + " " + Constants.Version); }); } app.UseEndpoints(endpoints => { endpoints.MapBlazorHub(); endpoints.MapControllers(); endpoints.MapFallbackToPage("/_Host"); }); // create a global sync event to identify server application startup sync.AddSyncEvent(-1, "Application", -1, true); }