Restored organization switching

This commit is contained in:
Rick Falkvinge
2015-04-18 14:25:19 +02:00
parent 86b5bab6d5
commit 9a3f70f321
2 changed files with 42 additions and 17 deletions
+32
View File
@@ -86,6 +86,38 @@ namespace Swarmops.Logic.Security
get { return Organization.FromIdentity (_data.OrganizationId); }
}
public void SetOrganization (Organization organization)
{
// This changes the active organization. There may be a Primary Position in this
// organization; if so, activate that too. Otherwise, just null out the Position.
// The reason this isn't an ordinary setter for the field is to minimize risk for
// miscoding in the security framework.
PositionAssignment primaryAssignment = Person.GetPrimaryAssignment (organization);
_data.OrganizationId = organization.Identity;
_data.PositionAssignmentId = (primaryAssignment == null ? 0 : primaryAssignment.Identity);
}
public void SetPosition (PositionAssignment assignment)
{
// This changes to a Position. The Organization will change along with it, but only
// if it's not a system-level Position.
// The reason this isn't an ordinary setter for the field is to minimize risk for
// miscoding in the security framework.
_data.PositionAssignmentId = (assignment == null ? 0 : assignment.Identity);
if (assignment != null)
{
if (assignment.Position.PositionLevel != PositionLevel.Systemwide)
{
_data.OrganizationId = assignment.Position.OrganizationId;
}
}
}
public PositionAssignment Assignment
{
get
@@ -36,36 +36,29 @@ namespace Swarmops.Frontend.Pages.v5.Security
// Some work here on PPSE pilot - we want everybody to be able to switch to Sandbox, which is #1
// except for in PPSE installation, where it is... #3 or something
// TODO: Allow logon to organization if there is a Position active
throw new UnauthorizedAccessException();
}
// this MUST be replaced with CommonV5 function
throw new NotImplementedException();
// when we get here, we are authorized to log on to the suggested organization.
// The reason we're modifying the existing Authority object instead of creating a new one
// is to minimize the risk for impersonation exploits: The only way to assign a Person identity
// to an Authority object is on login.
string logonFlags = string.Empty;
string[] currentIdentityParts = HttpContext.Current.User.Identity.Name.Split (',');
if (currentIdentityParts.Length > 2)
{
logonFlags = currentIdentityParts[3];
}
string userIdentityString = CurrentUser.Identity.ToString (CultureInfo.InvariantCulture) + "," +
suggestedOrganization.Identity.ToString (CultureInfo.InvariantCulture) + ",," +
logonFlags;
Authority newAuthority = CurrentAuthority;
newAuthority.SetOrganization (suggestedOrganization); // will/can also modify Position
CurrentUser.LastLogonOrganizationId = suggestedOrganization.Identity;
if (!string.IsNullOrEmpty (returnUrlString))
{
FormsAuthentication.SetAuthCookie (userIdentityString, true);
FormsAuthentication.SetAuthCookie (newAuthority.ToEncryptedXml(), true);
Response.Redirect (returnUrlString);
}
else
{
FormsAuthentication.RedirectFromLoginPage (userIdentityString, true);
FormsAuthentication.RedirectFromLoginPage (newAuthority.ToEncryptedXml(), true);
}
}
}