Added minimum security specification requirement to every page

This commit is contained in:
Rick Falkvinge
2015-03-01 02:36:25 +01:00
parent 3ebcc55b53
commit 1ed324e4e4
19 changed files with 98 additions and 6 deletions
+20 -1
View File
@@ -74,8 +74,27 @@ namespace Swarmops.Logic.Security
/// <summary>
/// Access to this Swarmops installation and its operating parameters
/// </summary>
System
System,
/// <summary>
/// Null security: disable security checks entirely, like for Dashboard where each component rolls their own
/// </summary>
Null,
/// <summary>
/// Uniquely identified person (logged on) in a specific org. Write access means they can submit expense reports on their own behalf &c.
/// </summary>
Participant,
/// <summary>
/// Can enter received invoices, paper letters, etc.
/// </summary>
Secretarial,
/// <summary>
/// Access to personalized salary data (implies financial read access)
/// </summary>
Payroll
}
public enum AccessType
+7
View File
@@ -1110,6 +1110,13 @@ namespace Swarmops.Logic.Swarm
string ids = string.Empty;
if (access.Aspect == AccessAspect.Null)
{
// Null security (like Dashboard), so return true
return true;
}
if (access.Type == AccessType.Write)
{
ids = access.Organization.Parameters.TemporaryAccessListWrite;
+9
View File
@@ -1,4 +1,5 @@
using System;
using System.Security;
using System.Web;
using System.Web.UI;
using Swarmops.Common.Enums;
@@ -7,6 +8,7 @@ using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
using PermissionSet = Swarmops.Logic.Security.PermissionSet;
/// <summary>
/// Base class to use for all data generators (JSON, etc). It supplies identification and localization.
@@ -92,6 +94,13 @@ public class PageV5Base : Page
protected override void OnPreRender (EventArgs e)
{
// Check that the page has security defined
if (this.PageAccessRequired == null)
{
throw new SecurityException("Page security is undefined at " + this.GetType().FullName + ". This is not permitted: minimum security must be defined for every page.");
}
// Check security of page against users's credentials
if (!CurrentUser.HasAccess (this.PageAccessRequired))
+2
View File
@@ -1,6 +1,7 @@
using System;
using Resources;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
public partial class Default : PageV5Base
{
@@ -8,6 +9,7 @@ public partial class Default : PageV5Base
{
PageTitle = Global.Dashboard_PageTitle;
PageIcon = "iconshock-steering-wheel";
this.PageAccessRequired = new Access(AccessAspect.Null, AccessType.Read); // dummy security until there's something to show on Dashboard
/*
this.LabelActionListMotions.Text = Resources.Pages.Governance.ListMotions_PageTitle;
+1 -1
View File
@@ -126,7 +126,7 @@
<div class="currentuserinfo">
<div style="background-image:url('/Images/Icons/iconshock-user-16px.png');background-repeat:no-repeat;padding-left:16px;float:left"><asp:Label ID="LabelCurrentUserName" runat="server" /> | </div>
<div style="background-image:url('/Images/Icons/iconshock-workchair-16px.png');background-repeat:no-repeat;padding-left:17px;float:left"><span class="hasTooltip" rel="Logged into <%=this.CurrentOrganization.Name %>" title="Click here to switch to another organization."><a href="/Security/ChangeOrganizations" id="LinkChangeOrganizations"><asp:Label ID="LabelCurrentOrganizationName" runat="server" /></a></span> |&nbsp;</div>
<div style="background-image:url('/Images/Icons/iconshock-gamepad-16px.png');background-repeat:no-repeat;padding-left:20px;float:left"><asp:Label ID="LabelPreferences" runat="server" /> | </div>
<div style="background-image:url('/Images/Icons/iconshock-gamepad-16px.png');background-repeat:no-repeat;padding-left:20px;float:left" id="divUserPreferences"><asp:Label ID="LabelPreferences" runat="server" /> | </div>
<div style="background-image:url('/Images/Icons/iconshock-lock-16px.png');background-repeat:no-repeat;padding-left:16px;float:left"><asp:LinkButton ID="LinkLogout" runat="server" OnClick="LinkLogout_Click" /> |&nbsp;</div>
<a href="/User/SelectLanguage"><asp:Image ID="ImageCultureIndicator" runat="server" ImageUrl="~/Images/Flags/uk-24px.png" /></a>
</div>
+7
View File
@@ -174,6 +174,13 @@ namespace Swarmops
this.LiteralBodyClass.Text = "rtl";
}
// If we're running as an open-something identity, remove the Preferences div
if (CurrentUser.Identity < 0)
{
this.LiteralDocumentReadyHook.Text += @" $('#divUserPreferences').hide();";
}
}
private void SetupDropboxes()
@@ -3,6 +3,7 @@ using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
@@ -16,6 +17,8 @@ namespace Swarmops.Frontend.Pages.Comms
PageTitle = Resources.Pages.Comms.SendMassMessage_Title;
InfoBoxLiteral = Resources.Pages.Comms.SendMassMessage_Info;
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Correspondence, AccessType.Write);
if (!Page.IsPostBack)
{
Localize();
@@ -6,6 +6,7 @@ using System.Web;
using System.Web.Services;
using Resources;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
@@ -26,6 +27,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
PageIcon = "iconshock-stamped-paper";
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Participant, AccessType.Read); // No specific access aspect for owning a budget (yet?)
if (!Page.IsPostBack)
{
Localize();
@@ -4,6 +4,7 @@ using System.Globalization;
using System.Web;
using Resources;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
namespace Swarmops.Frontend.Pages.v5.Financial
@@ -92,6 +93,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
PageIcon = "iconshock-invoice";
InfoBoxLiteral = Resources.Pages.Financial.CreateInboundInvoice_Info;
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Secretarial, AccessType.Write);
if (!Page.IsPostBack)
{
// Prime bank details
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Web;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
namespace Swarmops.Frontend.Pages.v5.Financial
@@ -97,6 +98,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
PageIcon = "iconshock-moneyback";
InfoBoxLiteral = Resources.Pages.Financial.FileExpenseClaim_Info;
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Participant, AccessType.Write);
if (!Page.IsPostBack)
{
// Prime bank details
@@ -19,6 +19,8 @@ namespace Swarmops.Frontend.Pages.Financial
return;
}
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Write);
PageIcon = "iconshock-money-envelope";
if (!Page.IsPostBack)
@@ -2,6 +2,7 @@
using System.Globalization;
using System.Web;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
namespace Swarmops.Frontend.Pages.v5.Financial
{
@@ -19,6 +20,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
PageIcon = "iconshock-walletmoney";
InfoBoxLiteral = Resources.Pages.Financial.RequestCashAdvance_Info;
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Participant, AccessType.Write);
if (!Page.IsPostBack)
{
// Prime bank details
@@ -23,10 +23,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
return;
}
if (!CurrentUser.HasAccess (new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Write)))
{
throw new UnauthorizedAccessException();
}
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Write);
PageIcon = "iconshock-invoice-greentick";
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using Swarmops.Logic.Security;
namespace Swarmops.Frontend.Pages.v5.Ledgers
{
@@ -17,6 +18,18 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
PageTitle = Resources.Pages.Ledgers.BalanceSheet_PageTitle;
InfoBoxLiteral = Resources.Pages.Ledgers.BalanceSheet_Info;
// Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read.
if (!String.IsNullOrEmpty (CurrentOrganization.OpenLedgersDomain))
{
PageAccessRequired = new Access (AccessAspect.Null, AccessType.Read);
}
else
{
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Read);
}
if (!Page.IsPostBack)
{
int year = DateTime.Today.Year;
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using Resources.Pages;
using Swarmops.Logic.Security;
public partial class Pages_v5_Ledgers_ProfitLossStatement : PageV5Base
{
@@ -16,6 +17,18 @@ public partial class Pages_v5_Ledgers_ProfitLossStatement : PageV5Base
PageTitle = Ledgers.ProfitLossStatement_PageTitle;
InfoBoxLiteral = Ledgers.ProfitLossStatement_Info;
// Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read.
if (!String.IsNullOrEmpty(CurrentOrganization.OpenLedgersDomain))
{
PageAccessRequired = new Access(AccessAspect.Null, AccessType.Read);
}
else
{
PageAccessRequired = new Access(CurrentOrganization, AccessAspect.Financials, AccessType.Read);
}
if (!Page.IsPostBack)
{
int year = DateTime.Today.Year;
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Web.UI.WebControls;
using Swarmops.Logic.Security;
namespace Swarmops.Frontend.Pages.v5.Ledgers.TaxForms
{
@@ -18,6 +19,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers.TaxForms
PageTitle = Resources.Pages.Financial.PayrollTaxForms_PageTitle;
InfoBoxLiteral = Resources.Pages.Financial.PayrollTaxForms_Info;
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Payroll, AccessType.Read);
if (!Page.IsPostBack)
{
// TODO: DETERMINE COUNTRIES ON PAYROLL
@@ -2,6 +2,7 @@
using System.Globalization;
using System.Web.UI.WebControls;
using Resources;
using Swarmops.Logic.Security;
namespace Swarmops.Frontend.Pages.v5.Ledgers
{
@@ -16,6 +17,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
PageIcon = "iconshock-cabinet";
PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Read);
if (!Page.IsPostBack)
{
+2
View File
@@ -38,6 +38,8 @@ namespace Swarmops.Frontend.Pages.v5.Swarm
this.TextName.Focus();
}
this.PageAccessRequired = new Access (CurrentOrganization, AccessAspect.PersonalData, AccessType.Write);
}
private void Populate()
@@ -16,6 +16,7 @@ namespace Swarmops.Frontend.Pages.Swarm
protected void Page_Load (object sender, EventArgs e)
{
PageIcon = "iconshock-group-search";
this.PageAccessRequired = new Access (CurrentOrganization, AccessAspect.PersonalData, AccessType.Read);
if (!Page.IsPostBack)
{