Added debug logging for Linux environment - there's a subtle difference between MS.Net and Mono here somewhere
This commit is contained in:
@@ -29,11 +29,15 @@ namespace Swarmops.Logic.Security
|
||||
/// </exception>
|
||||
public static Person Authenticate (string loginToken, string password)
|
||||
{
|
||||
SwarmopsLog.DebugLog(string.Format("Authenticating '{0}' against '{1}'", loginToken, password));
|
||||
|
||||
// Get the list of people that match the login token.
|
||||
|
||||
People candidatePeople = GetPeopleByLoginToken (loginToken);
|
||||
Person authenticatedUser = null;
|
||||
|
||||
SwarmopsLog.DebugLog ("- candidate count: " + candidatePeople.Count);
|
||||
|
||||
// For every person in the list, test the supplied password against the current and legacy hash schemes.
|
||||
|
||||
foreach (Person candidate in candidatePeople)
|
||||
@@ -48,6 +52,8 @@ namespace Swarmops.Logic.Security
|
||||
{
|
||||
if (membership.Active)
|
||||
{
|
||||
SwarmopsLog.DebugLog ("- candidate #" + candidate.Identity + " has a valid participation");
|
||||
|
||||
hasActiveMemberships = true;
|
||||
break;
|
||||
}
|
||||
@@ -57,6 +63,7 @@ namespace Swarmops.Logic.Security
|
||||
|
||||
if (!hasActiveMemberships)
|
||||
{
|
||||
SwarmopsLog.DebugLog("- candidate #" + candidate.Identity + " has NO valid participations");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -157,6 +164,8 @@ namespace Swarmops.Logic.Security
|
||||
// Longer than standard (10) on purpose. Should be good through 2020 or so.
|
||||
string passwordHash = BCrypt.HashPassword (personId.ToString (CultureInfo.InvariantCulture) + password, salt);
|
||||
|
||||
SwarmopsLog.DebugLog ("- storing salted pwd " + passwordHash);
|
||||
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
@@ -168,6 +177,8 @@ namespace Swarmops.Logic.Security
|
||||
return false; // not a BCrypt hash with work factor 12; fall back to legacy or fail. Caller's problem
|
||||
}
|
||||
|
||||
SwarmopsLog.DebugLog ("- password hash is " + person.PasswordHash);
|
||||
|
||||
return BCrypt.CheckPassword (person.Identity.ToString (CultureInfo.InvariantCulture) + password,
|
||||
person.PasswordHash);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Swarmops.Database;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
@@ -19,5 +21,19 @@ namespace Swarmops.Logic.Support
|
||||
|
||||
return SwarmopsLogEntry.FromIdentityAggressive (logEntryId);
|
||||
}
|
||||
|
||||
public static void DebugLog (string logEntry)
|
||||
{
|
||||
if (Path.DirectorySeparatorChar == '\\')
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine (logEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Linux - the reason we made this function to begin with
|
||||
|
||||
File.AppendAllText ("/tmp/swarmops-debug.log", DateTime.UtcNow.ToString("yyyy-MM-dd/HH:mm:ss.fff ") + logEntry + @"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -793,7 +793,12 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
public Participation AddParticipation (Organization organization, DateTime expires)
|
||||
{
|
||||
return AddParticipation (organization.Identity, expires);
|
||||
SwarmopsLog.DebugLog (string.Format("Adding participation in {0} until {1:yyyy-MM-dd HH:mm:ss}", organization.Name, expires));
|
||||
|
||||
Participation participation = AddParticipation (organization.Identity, expires);
|
||||
|
||||
SwarmopsLog.DebugLog ("Created participation #" + (participation != null? participation.Identity.ToString() : "null"));
|
||||
return participation;
|
||||
}
|
||||
|
||||
private Participation AddParticipation (int organizationId, DateTime expires)
|
||||
|
||||
@@ -682,6 +682,8 @@ namespace Swarmops.Frontend.Pages.v5.Public
|
||||
{
|
||||
// Make sure that no first person exists already, as a security measure
|
||||
|
||||
SwarmopsLog.DebugLog (String.Format("Creating first user: '{0}', '{1}', '{2}'", name, mail, password));
|
||||
|
||||
Person personOne = null;
|
||||
bool personOneExists = false;
|
||||
|
||||
@@ -715,11 +717,17 @@ namespace Swarmops.Frontend.Pages.v5.Public
|
||||
throw new InvalidOperationException ("Cannot run initialization processes again when initialized.");
|
||||
}
|
||||
|
||||
SwarmopsLog.DebugLog("Person one did not exist, creating");
|
||||
|
||||
Person newPerson = Person.Create (name, mail, password, string.Empty, string.Empty, string.Empty,
|
||||
string.Empty, string.Empty, DateTime.MinValue, PersonGender.Unknown);
|
||||
|
||||
SwarmopsLog.DebugLog("Adding participation in Sandbox");
|
||||
|
||||
newPerson.AddParticipation (Organization.Sandbox, DateTime.MaxValue); // Add membership in Sandbox
|
||||
|
||||
SwarmopsLog.DebugLog ("Creating positions");
|
||||
|
||||
// Initialize staffing to System and Sandbox with the new user
|
||||
|
||||
Positions.CreateSysadminPositions();
|
||||
@@ -757,9 +765,13 @@ namespace Swarmops.Frontend.Pages.v5.Public
|
||||
|
||||
// Get authenticated person
|
||||
|
||||
SwarmopsLog.DebugLog (" - before calling Authenticate");
|
||||
|
||||
Person expectedPersonOne = Authentication.Authenticate ("1",
|
||||
this.TextFirstUserPassword1.Text);
|
||||
|
||||
SwarmopsLog.DebugLog(" - after calling Authenticate");
|
||||
|
||||
if (expectedPersonOne != null)
|
||||
{
|
||||
Authority firstAuthority = Authority.FromLogin(expectedPersonOne, Organization.Sandbox);
|
||||
|
||||
Reference in New Issue
Block a user