Added impersonation function
This commit is contained in:
@@ -185,7 +185,9 @@
|
||||
<Compile Include="Communications\Payload\ParticipantMailPayload.cs" />
|
||||
<Compile Include="Communications\Payload\PayloadEnvelope.cs" />
|
||||
<Compile Include="Communications\Payload\NotificationPayload.cs" />
|
||||
<Compile Include="Security\Impersonation.cs" />
|
||||
<Compile Include="Support\BlockchainTransaction.cs" />
|
||||
<Compile Include="Support\LogEntries\ImpersonationLogEntry.cs" />
|
||||
<Compile Include="Support\LogEntries\PersonalDataChangedLogEntry.cs" />
|
||||
<Compile Include="Support\PayloadBase.cs" />
|
||||
<Compile Include="Financial\BankDataReaders\SEPaymentsBankgiroReader.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<string,string> CustomData { get; set; }
|
||||
public Impersonation ActiveImpersonation { get; set; }
|
||||
|
||||
|
||||
internal string ToXml()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<ImpersonationLogEntry>
|
||||
{
|
||||
public int ImpersonatorPersonId;
|
||||
public bool Started; // false means it ended at this mark
|
||||
}
|
||||
}
|
||||
+45
@@ -132,6 +132,42 @@ namespace Resources.Pages {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Impersonation Active.
|
||||
/// </summary>
|
||||
internal static string CommenceImpersonation_Active_Header {
|
||||
get {
|
||||
return ResourceManager.GetString("CommenceImpersonation_Active_Header", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have an active impersonation session as {0}. <a href="javascript:terminateImpersonation();">End impersonation.</a>.
|
||||
/// </summary>
|
||||
internal static string CommenceImpersonation_Active_Text {
|
||||
get {
|
||||
return ResourceManager.GetString("CommenceImpersonation_Active_Text", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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..
|
||||
/// </summary>
|
||||
internal static string CommenceImpersonation_Ended {
|
||||
get {
|
||||
return ResourceManager.GetString("CommenceImpersonation_Ended", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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..
|
||||
/// </summary>
|
||||
internal static string CommenceImpersonation_Failed {
|
||||
get {
|
||||
return ResourceManager.GetString("CommenceImpersonation_Failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Impersonate another user.
|
||||
/// </summary>
|
||||
@@ -159,6 +195,15 @@ namespace Resources.Pages {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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. .
|
||||
/// </summary>
|
||||
internal static string CommenceImpersonation_Success {
|
||||
get {
|
||||
return ResourceManager.GetString("CommenceImpersonation_Success", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
|
||||
@@ -314,6 +314,21 @@
|
||||
<data name="SystemSettings_WebsocketPortBackend" xml:space="preserve">
|
||||
<value>WebSocket Port (Backend)</value>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Active_Header" xml:space="preserve">
|
||||
<value>Impersonation Active</value>
|
||||
<comment>Visible on Dashboard</comment>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Active_Text" xml:space="preserve">
|
||||
<value>You have an active impersonation session as {0}. <a href="javascript:terminateImpersonation();">End impersonation.</a></value>
|
||||
<comment>Visible on Dashboard. {0} is the impersonated name.</comment>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Ended" xml:space="preserve">
|
||||
<value><strong>IMPERSONATION TERMINATED</strong><br/><br/>Impersonation terminated at {0:HH:mm} UTC. You are acting as yourself again.</value>
|
||||
<comment>{0} will be fed with a DateTime. The colon is rewritten automatically into the current DateTimeFormatInfo.TimeSeparator.</comment>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Failed" xml:space="preserve">
|
||||
<value><strong>IMPERSONATION DENIED</strong><br/><br/>You do not seem to have sufficient privileges to impersonate somebody else.</value>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Header" xml:space="preserve">
|
||||
<value>Impersonate another user</value>
|
||||
</data>
|
||||
@@ -323,6 +338,10 @@
|
||||
<data name="CommenceImpersonation_Person" xml:space="preserve">
|
||||
<value>Person to impersonate</value>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Success" xml:space="preserve">
|
||||
<value><strong>IMPERSONATION ACTIVE</strong><br/><br/>Impersonation started at {0:HH:mm} UTC. This is the Dashboard as the impersonated person sees it. </value>
|
||||
<comment>{0} will be fed with a DateTime. The colon is rewritten automatically into the current DateTimeFormatInfo.TimeSeparator.</comment>
|
||||
</data>
|
||||
<data name="CommenceImpersonation_Warning" xml:space="preserve">
|
||||
<value><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>
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImpersonationWarningBox.ascx.cs" Inherits="Swarmops.Frontend.Controls.Swarm.ImpersonationWarningBox" %>
|
||||
|
||||
<asp:Panel runat="server" ID="PanelImpersonationWarning">
|
||||
|
||||
<script>
|
||||
// This control will only ever be included once, so it's safe to put global script here
|
||||
|
||||
function terminateImpersonation() {
|
||||
SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/TerminateImpersonation", {}, function(result) {
|
||||
if (result.Success) {
|
||||
// Non-impersonating auth coookie has been set, so reload the page
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function flashOrangeHeader() {
|
||||
if (!_orangeFlashState) {
|
||||
$('h2.flashheader').addClass("orangeDark").removeClass("orange");
|
||||
_orangeFlashState = true;
|
||||
setTimeout("flashOrangeHeader();", 500);
|
||||
} else {
|
||||
$('h2.flashheader').removeClass("orangeDark").addClass("orange");
|
||||
_orangeFlashState = false;
|
||||
setTimeout("flashOrangeHeader();", 1500);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
flashOrangeHeader();
|
||||
});
|
||||
|
||||
|
||||
|
||||
var _orangeFlashState = false;
|
||||
</script>
|
||||
|
||||
<!-- this box is only visible on the Master when impersonation is active -->
|
||||
|
||||
<h2 class="orange flashheader"><asp:Label ID="LabelImpersonationWarningHeader" runat="server" /><span class="arrow"></span></h2>
|
||||
|
||||
<div class="box">
|
||||
<div class="content">
|
||||
<asp:Literal ID="LiteralImpersonationWarningText" runat="server"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</asp:Panel>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Swarmops.Frontend.Controls.Swarm {
|
||||
|
||||
|
||||
public partial class ImpersonationWarningBox {
|
||||
|
||||
/// <summary>
|
||||
/// PanelImpersonationWarning control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Panel PanelImpersonationWarning;
|
||||
|
||||
/// <summary>
|
||||
/// LabelImpersonationWarningHeader control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label LabelImpersonationWarningHeader;
|
||||
|
||||
/// <summary>
|
||||
/// LiteralImpersonationWarningText control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Literal LiteralImpersonationWarningText;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,6 +92,13 @@
|
||||
<Compile Include="Controls\v5\Base\AjaxToggleSlider.ascx.designer.cs">
|
||||
<DependentUpon>AjaxToggleSlider.ascx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\v5\Swarm\ImpersonationWarningBox.ascx.cs">
|
||||
<DependentUpon>ImpersonationWarningBox.ascx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\v5\Swarm\ImpersonationWarningBox.ascx.designer.cs">
|
||||
<DependentUpon>ImpersonationWarningBox.ascx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Admin\BitcoinEchoTest.aspx.cs">
|
||||
<DependentUpon>BitcoinEchoTest.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -653,6 +660,7 @@
|
||||
<Content Include="Controls\v5\Financial\CurrencyTextBox.ascx" />
|
||||
<Content Include="Controls\v5\Swarm\AjaxComboPeople.ascx" />
|
||||
<Content Include="Controls\v5\Swarm\ComboPeople.ascx" />
|
||||
<Content Include="Controls\v5\Swarm\ImpersonationWarningBox.ascx" />
|
||||
<Content Include="Controls\v5\Swarm\PersonDetailPopup.ascx" />
|
||||
<Content Include="Controls\v5\Swarm\TreePositions.ascx" />
|
||||
<Content Include="Controls\v5\UI\ExternalScripts.ascx" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user