Skip to content

Commit

Permalink
Merge branch 'anurse/253-msftaccount' into dev
Browse files Browse the repository at this point in the history
Conflicts:
	src/NuGetGallery.Cloud/ServiceConfiguration.Local.cscfg
	src/NuGetGallery.Cloud/ServiceDefinition.csdef
	src/NuGetGallery/App_Start/AppActivator.cs
	src/NuGetGallery/Authentication/Providers/ApiKey/ApiKeyAuthenticationHandler.cs
	src/NuGetGallery/Content/Logos/herowithlogo.png
	src/NuGetGallery/Content/Logos/nugetLogoFooter.png
	src/NuGetGallery/Content/Site.css
	src/NuGetGallery/RouteNames.cs
	src/NuGetGallery/T4MVC.cs
	src/NuGetGallery/Views/Authentication/_RegisterForm.cshtml
	src/NuGetGallery/Views/Packages/Edit.cshtml
	src/NuGetGallery/Web.config
	tests/NuGetGallery.Facts/Authentication/Providers/ApiKey/ApiKeyAuthenticationHandlerFacts.cs
  • Loading branch information
analogrelay committed Nov 21, 2013
2 parents 0cc3853 + 069d89d commit d402768
Show file tree
Hide file tree
Showing 165 changed files with 10,914 additions and 2,905 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>2.1</ProductVersion>
<ProductVersion>2.2</ProductVersion>
<ProjectGuid>1d0164b6-92d4-455a-ac68-c30b61733748</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand Down Expand Up @@ -56,7 +56,7 @@
<!-- Import the target files for this project template -->
<PropertyGroup>
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.1\</CloudExtensionsDir>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.2\</CloudExtensionsDir>
</PropertyGroup>
<Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
<Import Project="$(MSBuildProjectDirectory)\..\..\build\NuGetGallery.Cloud.targets" />
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery.Cloud/NuGetGallery.Cloud.ccproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>2.1</ProductVersion>
<ProductVersion>2.2</ProductVersion>
<ProjectGuid>0041aca0-30ec-4554-8c7c-0af810f3086f</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand Down Expand Up @@ -63,7 +63,7 @@
<!-- Import the target files for this project template -->
<PropertyGroup>
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.1\</CloudExtensionsDir>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.2\</CloudExtensionsDir>
</PropertyGroup>
<Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
<Import Project="$(MSBuildProjectDirectory)\..\..\build\NuGetGallery.Cloud.targets" />
Expand Down
10 changes: 4 additions & 6 deletions src/NuGetGallery.Cloud/ServiceConfiguration.Local.cscfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
<Setting name="Gallery.GoogleAnalyticsPropertyId" value="" />
<Setting name="Gallery.AzureCdnHost" value="" />
<Setting name="Gallery.SiteRoot" value="nuget.localtest.me" />

<!-- **************** -->
<!-- FEATURE SETTINGS -->
<!-- **************** -->
<Setting name="Feature.FriendlyLicenses" value="true" />
<Setting name="Auth.MicrosoftAccount.Enabled" value="false" />
<Setting name="Auth.MicrosoftAccount.ClientId" value="" />
<Setting name="Auth.MicrosoftAccount.ClientSecret" value="" />

<!-- *************** -->
<!-- STABLE SETTINGS -->
Expand Down Expand Up @@ -55,4 +53,4 @@
<Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="D2CA3A778E08936DD4C61E2734158B0044831010" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
</ServiceConfiguration>
</ServiceConfiguration>
4 changes: 3 additions & 1 deletion src/NuGetGallery.Cloud/ServiceDefinition.csdef
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<Setting name="Gallery.LuceneIndexLocation" />
<Setting name="Gallery.GoogleAnalyticsPropertyId" />
<Setting name="Gallery.HasWorker" />
<Setting name="Feature.FriendlyLicenses" />
<Setting name="Auth.MicrosoftAccount.Enabled" />
<Setting name="Auth.MicrosoftAccount.ClientId" />
<Setting name="Auth.MicrosoftAccount.ClientSecret" />
</ConfigurationSettings>
<Sites>
<Site name="Web">
Expand Down
73 changes: 73 additions & 0 deletions src/NuGetGallery.Core/Auditing/AuditActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace NuGetGallery.Auditing
{
public class AuditActor
{
public string MachineName { get; set; }
public string MachineIP { get; set; }
public string UserName { get; set; }
public string AuthenticationType { get; set; }
public DateTime TimestampUtc { get; set; }

public AuditActor OnBehalfOf { get; set; }

public AuditActor(string machineName, string machineIP, string userName, string authenticationType, DateTime timeStampUtc)
: this(machineName, machineIP, userName, authenticationType, timeStampUtc, null) { }
public AuditActor(string machineName, string machineIP, string userName, string authenticationType, DateTime timeStampUtc, AuditActor onBehalfOf)
{
MachineName = machineName;
UserName = userName;
AuthenticationType = authenticationType;
TimestampUtc = timeStampUtc;
OnBehalfOf = onBehalfOf;
}

public static Task<AuditActor> GetCurrentMachineActor()
{
return GetCurrentMachineActor(null);
}

public static async Task<AuditActor> GetCurrentMachineActor(AuditActor onBehalfOf)
{
// Try to get local IP
string ipAddress = await GetLocalIP();

return new AuditActor(
Environment.MachineName,
ipAddress,
String.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName),
"MachineUser",
DateTime.UtcNow,
onBehalfOf);
}

public static async Task<string> GetLocalIP()
{
string ipAddress = null;
if (NetworkInterface.GetIsNetworkAvailable())
{
var entry = await Dns.GetHostEntryAsync(Dns.GetHostName());
if (entry != null)
{
ipAddress =
TryGetAddress(entry.AddressList, AddressFamily.InterNetworkV6) ??
TryGetAddress(entry.AddressList, AddressFamily.InterNetwork);
}
}
return ipAddress;
}

private static string TryGetAddress(IEnumerable<IPAddress> addrs, AddressFamily family)
{
return addrs.Where(a => a.AddressFamily == family).Select(a => a.ToString()).FirstOrDefault();
}
}
}
27 changes: 27 additions & 0 deletions src/NuGetGallery.Core/Auditing/AuditEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGetGallery.Auditing
{
/// <summary>
/// Represents the actual data stored in an audit entry, an AuditRecord/AuditEnvironment pair
/// </summary>
public class AuditEntry
{
public AuditRecord Record { get; set; }
public AuditActor Actor { get; set; }

public AuditEntry()
{
}

public AuditEntry(AuditRecord record, AuditActor actor)
{
Record = record;
Actor = actor;
}
}
}
47 changes: 47 additions & 0 deletions src/NuGetGallery.Core/Auditing/AuditRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NuGetGallery.Auditing
{
public abstract class AuditRecord
{
private string _resourceType;

public abstract string GetPath();

public virtual string GetResourceType()
{
return _resourceType ?? (_resourceType = InferResourceType());
}

public abstract string GetAction();

private string InferResourceType()
{
string type = GetType().Name;
if (type.EndsWith("AuditRecord", StringComparison.OrdinalIgnoreCase))
{
return type.Substring(0, type.Length - 11);
}
return type;
}
}

public abstract class AuditRecord<T> : AuditRecord
where T : struct
{
public T Action { get; set; }

protected AuditRecord(T action)
{
Action = action;
}

public override string GetAction()
{
return Action.ToString().ToLowerInvariant();
}
}
}
76 changes: 76 additions & 0 deletions src/NuGetGallery.Core/Auditing/AuditingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace NuGetGallery.Auditing
{
public abstract class AuditingService
{
public static readonly AuditingService None = new NullAuditingService();

private static readonly JsonSerializerSettings _auditRecordSerializerSettings;

static AuditingService()
{
var settings = new JsonSerializerSettings()
{
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DefaultValueHandling = DefaultValueHandling.Include,
Formatting = Formatting.Indented,
MaxDepth = 10,
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Include,
TypeNameHandling = TypeNameHandling.None
};
settings.Converters.Add(new StringEnumConverter());
_auditRecordSerializerSettings = settings;
}

public virtual async Task<Uri> SaveAuditRecord(AuditRecord record)
{
// Build an audit entry
var entry = new AuditEntry(record, await GetActor());

// Serialize to json
string rendered = RenderAuditEntry(entry);

// Save the record
return await SaveAuditRecord(rendered, record.GetResourceType(), record.GetPath(), record.GetAction(), entry.Actor.TimestampUtc);
}

public virtual string RenderAuditEntry(AuditEntry entry)
{
return JsonConvert.SerializeObject(entry, _auditRecordSerializerSettings);
}

/// <summary>
/// Performs the actual saving of audit data to an audit store
/// </summary>
/// <param name="auditData">The data to store in the audit record</param>
/// <param name="resourceType">The type of resource affected by the audit (usually used as the first-level folder)</param>
/// <param name="filePath">The file-system path to use to identify the audit record</param>
/// <param name="action">The action recorded in this audit record</param>
/// <param name="timestamp">A timestamp indicating when the record was created</param>
/// <returns>The URI identifying the audit record resource</returns>
protected abstract Task<Uri> SaveAuditRecord(string auditData, string resourceType, string filePath, string action, DateTime timestamp);

protected virtual Task<AuditActor> GetActor()
{
return AuditActor.GetCurrentMachineActor();
}

private class NullAuditingService : AuditingService
{
protected override Task<Uri> SaveAuditRecord(string auditData, string resourceType, string filePath, string action, DateTime timestamp)
{
return Task.FromResult<Uri>(new Uri("http://auditing.local/" + resourceType + "/" + filePath + "/" + timestamp.ToString("s") + "-" + action.ToLowerInvariant()));
}
}
}
}
Loading

0 comments on commit d402768

Please sign in to comment.