diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj
index 84c839b9..40858213 100644
--- a/Logic/Logic.csproj
+++ b/Logic/Logic.csproj
@@ -185,7 +185,9 @@
+
+
diff --git a/Logic/Security/Authority.cs b/Logic/Security/Authority.cs
index b60b55e0..2dcdfc9f 100644
--- a/Logic/Security/Authority.cs
+++ b/Logic/Security/Authority.cs
@@ -87,6 +87,10 @@ namespace Swarmops.Logic.Security
get { return Organization.FromIdentity (_data.OrganizationId); }
}
+ public Impersonation Impersonation { get; set; }
+
+ public bool ImpersonationActive { get { return Impersonation != null; } }
+
public void SetOrganization (Organization organization)
{
// This changes the active organization. There may be a Primary Position in this
@@ -514,6 +518,8 @@ namespace Swarmops.Logic.Security
public int PositionAssignmentId { get; set; }
public DateTime LoginDateTimeUtc { get; set; }
public Basic.Types.Common.SerializableDictionary CustomData { get; set; }
+ public Impersonation ActiveImpersonation { get; set; }
+
internal string ToXml()
{
diff --git a/Logic/Security/Impersonation.cs b/Logic/Security/Impersonation.cs
new file mode 100644
index 00000000..03e9c713
--- /dev/null
+++ b/Logic/Security/Impersonation.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Swarmops.Logic.Security
+{
+ [Serializable]
+ public class Impersonation
+ {
+ public int ImpersonatedByPersonId;
+ public DateTime ImpersonationStarted;
+ }
+}
diff --git a/Logic/Support/LogEntries/ImpersonationLogEntry.cs b/Logic/Support/LogEntries/ImpersonationLogEntry.cs
new file mode 100644
index 00000000..ada31049
--- /dev/null
+++ b/Logic/Support/LogEntries/ImpersonationLogEntry.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Swarmops.Logic.Support.LogEntries
+{
+ [Serializable]
+ public class ImpersonationLogEntry: LogEntryBase
+ {
+ public int ImpersonatorPersonId;
+ public bool Started; // false means it ended at this mark
+ }
+}
diff --git a/Site/App_GlobalResources/Pages.Admin.designer.cs b/Site/App_GlobalResources/Pages.Admin.designer.cs
index fc3d2c3d..411908ca 100644
--- a/Site/App_GlobalResources/Pages.Admin.designer.cs
+++ b/Site/App_GlobalResources/Pages.Admin.designer.cs
@@ -132,6 +132,42 @@ namespace Resources.Pages {
}
}
+ ///
+ /// Looks up a localized string similar to Impersonation Active.
+ ///
+ internal static string CommenceImpersonation_Active_Header {
+ get {
+ return ResourceManager.GetString("CommenceImpersonation_Active_Header", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to You have an active impersonation session as {0}. <a href="javascript:terminateImpersonation();">End impersonation.</a>.
+ ///
+ internal static string CommenceImpersonation_Active_Text {
+ get {
+ return ResourceManager.GetString("CommenceImpersonation_Active_Text", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to <strong>IMPERSONATION TERMINATED</strong><br/><br/>Impersonation terminated at {0:HH:mm} UTC. You are acting as yourself again..
+ ///
+ internal static string CommenceImpersonation_Ended {
+ get {
+ return ResourceManager.GetString("CommenceImpersonation_Ended", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to <strong>IMPERSONATION DENIED</strong><br/><br/>You do not seem to have sufficient privileges to impersonate somebody else..
+ ///
+ internal static string CommenceImpersonation_Failed {
+ get {
+ return ResourceManager.GetString("CommenceImpersonation_Failed", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Impersonate another user.
///
@@ -159,6 +195,15 @@ namespace Resources.Pages {
}
}
+ ///
+ /// Looks up a localized string similar to <strong>IMPERSONATION ACTIVE</strong><br/><br/>Impersonation started at {0:HH:mm} UTC. This is the Dashboard as the impersonated person sees it. .
+ ///
+ internal static string CommenceImpersonation_Success {
+ get {
+ return ResourceManager.GetString("CommenceImpersonation_Success", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to <p>This debugging tool allows you to impersonate another user to see and experience Swarmops as they do when logged in.</p>
///<p><strong>WARNING:</strong> This is a highly intrusive tool that should only be used for technical development and for requested support. Using this should not be taken lightly.</p>
diff --git a/Site/App_GlobalResources/Pages.Admin.resx b/Site/App_GlobalResources/Pages.Admin.resx
index ae59864c..4017b129 100644
--- a/Site/App_GlobalResources/Pages.Admin.resx
+++ b/Site/App_GlobalResources/Pages.Admin.resx
@@ -314,6 +314,21 @@
WebSocket Port (Backend)
+
+ Impersonation Active
+ Visible on Dashboard
+
+
+ You have an active impersonation session as {0}. <a href="javascript:terminateImpersonation();">End impersonation.</a>
+ Visible on Dashboard. {0} is the impersonated name.
+
+
+ <strong>IMPERSONATION TERMINATED</strong><br/><br/>Impersonation terminated at {0:HH:mm} UTC. You are acting as yourself again.
+ {0} will be fed with a DateTime. The colon is rewritten automatically into the current DateTimeFormatInfo.TimeSeparator.
+
+
+ <strong>IMPERSONATION DENIED</strong><br/><br/>You do not seem to have sufficient privileges to impersonate somebody else.
+
Impersonate another user
@@ -323,6 +338,10 @@
Person to impersonate
+
+ <strong>IMPERSONATION ACTIVE</strong><br/><br/>Impersonation started at {0:HH:mm} UTC. This is the Dashboard as the impersonated person sees it.
+ {0} will be fed with a DateTime. The colon is rewritten automatically into the current DateTimeFormatInfo.TimeSeparator.
+
<p>This debugging tool allows you to impersonate another user to see and experience Swarmops as they do when logged in.</p>
<p><strong>WARNING:</strong> This is a highly intrusive tool that should only be used for technical development and for requested support. Using this should not be taken lightly.</p>
diff --git a/Site/Automation/SwarmFunctions.aspx.cs b/Site/Automation/SwarmFunctions.aspx.cs
index 236afc97..cc37b888 100644
--- a/Site/Automation/SwarmFunctions.aspx.cs
+++ b/Site/Automation/SwarmFunctions.aspx.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
+using System.Web.Security;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
@@ -568,5 +569,44 @@ namespace Swarmops.Frontend.Automation
}
+
+ [WebMethod]
+ public static AjaxCallResult TerminateImpersonation()
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ if (!authData.Authority.ImpersonationActive)
+ {
+ return new AjaxCallResult {Success = false}; // no impersonation active. Race condition?
+ }
+
+ int realUserPersonId = authData.Authority.Impersonation.ImpersonatedByPersonId;
+ Person impersonator = Person.FromIdentity(realUserPersonId);
+
+ // Terminate impersonation and set new authority cookie from the impersonator data.
+ // VERY SECURITY SENSITIVE: The identity as impersonator will be the new user.
+
+ // TODO: LOG LOG LOG LOG
+
+ SwarmopsLogEntry logEntry = SwarmopsLog.CreateEntry(authData.CurrentUser,
+ new ImpersonationLogEntry
+ {
+ ImpersonatorPersonId = impersonator.Identity,
+ Started = false
+ });
+ logEntry.CreateAffectedObject(impersonator); // link impersonator to log entry for searchability
+
+ DateTime utcNow = DateTime.UtcNow;
+
+ Authority authority =
+ Authority.FromLogin(impersonator, authData.CurrentOrganization);
+ FormsAuthentication.SetAuthCookie(authority.ToEncryptedXml(), false);
+ HttpContext.Current.Response.AppendCookie(new HttpCookie("DashboardMessage", String.Format(Resources.Pages.Admin.CommenceImpersonation_Ended, utcNow)));
+
+ // returning Success will force a reload, resetting dashboard to original user
+
+ return new AjaxCallResult {Success = true};
+ }
+
}
}
\ No newline at end of file
diff --git a/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx
new file mode 100644
index 00000000..21af83d2
--- /dev/null
+++ b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx
@@ -0,0 +1,48 @@
+<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImpersonationWarningBox.ascx.cs" Inherits="Swarmops.Frontend.Controls.Swarm.ImpersonationWarningBox" %>
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.cs b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.cs
new file mode 100644
index 00000000..20359234
--- /dev/null
+++ b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+namespace Swarmops.Frontend.Controls.Swarm
+{
+ public partial class ImpersonationWarningBox : ControlV5Base
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ this.PanelImpersonationWarning.Visible = CurrentAuthority.ImpersonationActive;
+ Localize();
+ }
+
+ private void Localize()
+ {
+ this.LabelImpersonationWarningHeader.Text = Resources.Pages.Admin.CommenceImpersonation_Active_Header;
+ this.LiteralImpersonationWarningText.Text = String.Format(Resources.Pages.Admin.CommenceImpersonation_Active_Text, CurrentUser.Canonical);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.designer.cs b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.designer.cs
new file mode 100644
index 00000000..1d4e5bd6
--- /dev/null
+++ b/Site/Controls/v5/Swarm/ImpersonationWarningBox.ascx.designer.cs
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Swarmops.Frontend.Controls.Swarm {
+
+
+ public partial class ImpersonationWarningBox {
+
+ ///
+ /// PanelImpersonationWarning control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Panel PanelImpersonationWarning;
+
+ ///
+ /// LabelImpersonationWarningHeader control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelImpersonationWarningHeader;
+
+ ///
+ /// LiteralImpersonationWarningText control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Literal LiteralImpersonationWarningText;
+ }
+}
diff --git a/Site/Master-v5.master.cs b/Site/Master-v5.master.cs
index b4f24bc5..ce1cc6d1 100644
--- a/Site/Master-v5.master.cs
+++ b/Site/Master-v5.master.cs
@@ -152,7 +152,7 @@ namespace Swarmops.Frontend
if (dashMessage != null && dashMessage.Value.Length > 0)
{
this.LiteralDocumentReadyHook.Text +=
- string.Format ("alertify.alert(decodeURIComponent('{0}'));", dashMessage.Value);
+ string.Format ("alertify.alert(SwarmopsJS.unescape('{0}'));", dashMessage.Value);
DashboardMessage.Reset();
}
else
diff --git a/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs b/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
index 9cf16e23..da1adb96 100644
--- a/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
+++ b/Site/Pages/v5/Admin/CommenceImpersonation.aspx.cs
@@ -3,11 +3,14 @@ using System.Collections.Generic;
using System.Globalization;
using System.Resources;
using System.Web;
+using System.Web.Security;
using System.Web.Services;
using Swarmops.Interface.Support;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
+using Swarmops.Logic.Support.LogEntries;
+using Swarmops.Logic.Swarm;
namespace Swarmops.Frontend.Pages.v5.Admin
{
@@ -36,7 +39,42 @@ namespace Swarmops.Frontend.Pages.v5.Admin
[WebMethod]
public static AjaxCallResult BeginImpersonation (int personId)
{
- throw new NotImplementedException();
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ if (!authData.Authority.HasSystemAccess())
+ {
+ // Restrict impersonation to system-level access for now: it's a debugging tool
+
+ return new AjaxCallResult
+ {
+ Success = false,
+ DisplayMessage = CommonV5.JavascriptEscape(Resources.Pages.Admin.CommenceImpersonation_Failed)
+ };
+ }
+
+ // BEGIN IMPERSONATION
+
+ Person impersonatedPerson = Person.FromIdentity(personId);
+
+ SwarmopsLogEntry newEntry = SwarmopsLog.CreateEntry(impersonatedPerson,
+ new ImpersonationLogEntry {ImpersonatorPersonId = authData.CurrentUser.PersonId, Started = true});
+ newEntry.CreateAffectedObject(authData.CurrentUser); // link impersonator to log entry for searchability
+
+ // Someone who has system level access can always impersonate => no further access control at this time
+
+ // SECURITY CONSIDERATIONS: If somebody replaces/fires a superior? Trivially undoable at the database level
+
+ DateTime utcNow = DateTime.UtcNow;
+ Authority impersonatingAuthority = Authority.FromLogin(impersonatedPerson, authData.CurrentOrganization);
+ impersonatingAuthority.Impersonation = new Impersonation
+ {
+ ImpersonatedByPersonId = authData.CurrentUser.PersonId,
+ ImpersonationStarted = utcNow
+ };
+
+ FormsAuthentication.SetAuthCookie(impersonatingAuthority.ToEncryptedXml(), false);
+ HttpContext.Current.Response.AppendCookie(new HttpCookie("DashboardMessage", CommonV5.JavascriptEscape(String.Format(Resources.Pages.Admin.CommenceImpersonation_Success, utcNow))));
+ return new AjaxCallResult {Success = true};
}
diff --git a/Site/Site.csproj b/Site/Site.csproj
index 671d7d67..d231617c 100644
--- a/Site/Site.csproj
+++ b/Site/Site.csproj
@@ -92,6 +92,13 @@
AjaxToggleSlider.ascx
+
+ ImpersonationWarningBox.ascx
+ ASPXCodeBehind
+
+
+ ImpersonationWarningBox.ascx
+
BitcoinEchoTest.aspx
ASPXCodeBehind
@@ -653,6 +660,7 @@
+
diff --git a/Site/Style/style-v5.css b/Site/Style/style-v5.css
index c6b1883f..1e89883b 100644
--- a/Site/Style/style-v5.css
+++ b/Site/Style/style-v5.css
@@ -1052,6 +1052,28 @@ body.rtl .sidebar h2 {
border-color: #C78B15;
}
+
+.sidebar h2.orangeDark
+{
+ background-color: #C78B15;
+ background: -ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#CC9221', endColorstr='#BA800D'); /* MSIE */
+ background: -moz-linear-gradient(top, #CC9221, #BA800D); /* Mozilla */
+ background: -webkit-gradient(linear, left top, left bottom, from(#CC9221), to(#BA800D)); /* Chrome, Safari */
+ text-shadow: #7F5500 0px 0px 3px, #7F5500 0px 0px 3px;
+
+ border-color: #7F5500;
+}
+
+
+/* COLOR SCHEME
+
+ #A2BEFF #476EC7 #1C397E #C8D9FF #E4ECFF -- blue (hue 240)
+ #FFBC37 #C78B15 #7F5500 #FFD580 #FFEDC8 -- orange (hue 60)
+
+ base dark xdark light xlight
+*/
+
+
.sidebar h2 span.arrow
{
border-style: solid;