Skip to content

Commit 462d949

Browse files
committed
Merge branch 'andulv-dev3061-2' into dev
2 parents 1ab3231 + 39b094a commit 462d949

195 files changed

Lines changed: 5206 additions & 739 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NuGet.Server.sln

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F277539-E9D
2222
EndProject
2323
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.Core.Tests", "test\NuGet.Server.Core.Tests\NuGet.Server.Core.Tests.csproj", "{FDE8DDFB-E01B-47FD-9945-0A151F3AE589}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.V2", "src\NuGet.Server.V2\NuGet.Server.V2.csproj", "{273E4575-4054-4578-9D14-8D4E640A365F}"
26+
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{D54BB20B-57E8-4D4F-BD9D-CF284CBFAB3B}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.V2.Samples.OwinHost", "samples\NuGet.Server.V2.Samples.OwinHost\NuGet.Server.V2.Samples.OwinHost.csproj", "{5CF9DB92-53DE-488E-82F9-4C3F867516B2}"
30+
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.V2.Tests", "test\NuGet.Server.V2.Tests\NuGet.Server.V2.Tests.csproj", "{BE64E341-7D99-43D9-A0D2-A38E977B7D97}"
32+
EndProject
2533
Global
2634
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2735
Coverage|Any CPU = Coverage|Any CPU
@@ -116,6 +124,66 @@ Global
116124
{FDE8DDFB-E01B-47FD-9945-0A151F3AE589}.Release|Any CPU.Build.0 = Release|Any CPU
117125
{FDE8DDFB-E01B-47FD-9945-0A151F3AE589}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
118126
{FDE8DDFB-E01B-47FD-9945-0A151F3AE589}.Release|Mixed Platforms.Build.0 = Release|Any CPU
127+
{273E4575-4054-4578-9D14-8D4E640A365F}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
128+
{273E4575-4054-4578-9D14-8D4E640A365F}.Coverage|Any CPU.Build.0 = Release|Any CPU
129+
{273E4575-4054-4578-9D14-8D4E640A365F}.Coverage|Mixed Platforms.ActiveCfg = Release|Any CPU
130+
{273E4575-4054-4578-9D14-8D4E640A365F}.Coverage|Mixed Platforms.Build.0 = Release|Any CPU
131+
{273E4575-4054-4578-9D14-8D4E640A365F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
132+
{273E4575-4054-4578-9D14-8D4E640A365F}.Debug|Any CPU.Build.0 = Debug|Any CPU
133+
{273E4575-4054-4578-9D14-8D4E640A365F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
134+
{273E4575-4054-4578-9D14-8D4E640A365F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
135+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Debug|Any CPU.ActiveCfg = Debug|Any CPU
136+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Debug|Any CPU.Build.0 = Debug|Any CPU
137+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
138+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Debug|Mixed Platforms.Build.0 = Debug|Any CPU
139+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Release|Any CPU.ActiveCfg = Release|Any CPU
140+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Release|Any CPU.Build.0 = Release|Any CPU
141+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Release|Mixed Platforms.ActiveCfg = Release|Any CPU
142+
{273E4575-4054-4578-9D14-8D4E640A365F}.Mono Release|Mixed Platforms.Build.0 = Release|Any CPU
143+
{273E4575-4054-4578-9D14-8D4E640A365F}.Release|Any CPU.ActiveCfg = Release|Any CPU
144+
{273E4575-4054-4578-9D14-8D4E640A365F}.Release|Any CPU.Build.0 = Release|Any CPU
145+
{273E4575-4054-4578-9D14-8D4E640A365F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
146+
{273E4575-4054-4578-9D14-8D4E640A365F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
147+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
148+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Coverage|Any CPU.Build.0 = Release|Any CPU
149+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Coverage|Mixed Platforms.ActiveCfg = Release|Any CPU
150+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Coverage|Mixed Platforms.Build.0 = Release|Any CPU
151+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
152+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
153+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
154+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
155+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
158+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Debug|Mixed Platforms.Build.0 = Debug|Any CPU
159+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Release|Any CPU.ActiveCfg = Release|Any CPU
160+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Release|Any CPU.Build.0 = Release|Any CPU
161+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Release|Mixed Platforms.ActiveCfg = Release|Any CPU
162+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Mono Release|Mixed Platforms.Build.0 = Release|Any CPU
163+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
164+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Any CPU.Build.0 = Release|Any CPU
165+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
166+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
167+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
168+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Any CPU.Build.0 = Release|Any CPU
169+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Mixed Platforms.ActiveCfg = Release|Any CPU
170+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Mixed Platforms.Build.0 = Release|Any CPU
171+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
172+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
173+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
174+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
175+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Any CPU.ActiveCfg = Debug|Any CPU
176+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Any CPU.Build.0 = Debug|Any CPU
177+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
178+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Mixed Platforms.Build.0 = Debug|Any CPU
179+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Any CPU.ActiveCfg = Release|Any CPU
180+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Any CPU.Build.0 = Release|Any CPU
181+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Mixed Platforms.ActiveCfg = Release|Any CPU
182+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Mixed Platforms.Build.0 = Release|Any CPU
183+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
184+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Any CPU.Build.0 = Release|Any CPU
185+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
186+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Mixed Platforms.Build.0 = Release|Any CPU
119187
EndGlobalSection
120188
GlobalSection(SolutionProperties) = preSolution
121189
HideSolutionNode = FALSE
@@ -125,5 +193,8 @@ Global
125193
{92D18050-3867-4E39-B305-9F9870F66F5E} = {E7B39EAD-EA32-4011-845A-C949A336389A}
126194
{1FE62F82-927A-4437-91F1-1A965E51682B} = {0F277539-E9D7-4A06-A731-D525D9AFCE54}
127195
{FDE8DDFB-E01B-47FD-9945-0A151F3AE589} = {E7B39EAD-EA32-4011-845A-C949A336389A}
196+
{273E4575-4054-4578-9D14-8D4E640A365F} = {0F277539-E9D7-4A06-A731-D525D9AFCE54}
197+
{5CF9DB92-53DE-488E-82F9-4C3F867516B2} = {D54BB20B-57E8-4D4F-BD9D-CF284CBFAB3B}
198+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97} = {E7B39EAD-EA32-4011-845A-C949A336389A}
128199
EndGlobalSection
129200
EndGlobal

build.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe tes
3434
IF %ERRORLEVEL% NEQ 0 goto error
3535
call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe test\NuGet.Server.Tests\bin\%config%\NuGet.Server.Tests.dll
3636
IF %ERRORLEVEL% NEQ 0 goto error
37+
call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe test\NuGet.Server.V2.Tests\bin\%config%\NuGet.Server.V2.Tests.dll
38+
IF %ERRORLEVEL% NEQ 0 goto error
3739

3840

3941
REM Package
@@ -43,6 +45,8 @@ call :ExecuteCmd tools\nuget.exe pack "src\NuGet.Server.Core\NuGet.Server.Core.c
4345
IF %ERRORLEVEL% NEQ 0 goto error
4446
call :ExecuteCmd tools\nuget.exe pack "src\NuGet.Server\NuGet.Server.csproj" -symbols -o artifacts\packages -p Configuration=%config% %version%
4547
IF %ERRORLEVEL% NEQ 0 goto error
48+
call :ExecuteCmd tools\nuget.exe pack "src\NuGet.Server.V2\NuGet.Server.V2.csproj" -symbols -o artifacts\packages -p Configuration=%config% %version%
49+
IF %ERRORLEVEL% NEQ 0 goto error
4650

4751

4852
goto end
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Security.Claims;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Microsoft.Owin;
10+
11+
namespace NuGet.Server.V2.Samples.OwinHost
12+
{
13+
/// <summary>
14+
/// Authenticates all users that supply a non-empty username and password.
15+
/// All usernames that starts with 'admin' are assigned to the 'Admin' role.
16+
/// For demonstratiion purposes only!
17+
///
18+
/// Modify this class or
19+
/// - override ValidateUser method to provide a real username/password check.
20+
/// - override GetRolesForUser method to return roles based on usernames.
21+
/// </summary>
22+
public class BasicAuthentication : OwinMiddleware
23+
{
24+
public BasicAuthentication(OwinMiddleware next) :
25+
base(next)
26+
{
27+
28+
}
29+
30+
public override async Task Invoke(IOwinContext context)
31+
{
32+
var response = context.Response;
33+
var request = context.Request;
34+
35+
response.OnSendingHeaders(state =>
36+
{
37+
var owinResponse = (OwinResponse)state;
38+
39+
if (owinResponse.StatusCode == 401)
40+
{
41+
owinResponse.Headers.Add("WWW-Authenticate", new[] { "Basic" });
42+
}
43+
}, response);
44+
45+
var header = request.Headers["Authorization"];
46+
47+
if (!String.IsNullOrWhiteSpace(header))
48+
{
49+
var authHeader = System.Net.Http.Headers.AuthenticationHeaderValue.Parse(header);
50+
51+
if ("Basic".Equals(authHeader.Scheme, StringComparison.OrdinalIgnoreCase))
52+
{
53+
var parameter = Encoding.UTF8.GetString(Convert.FromBase64String(authHeader.Parameter));
54+
55+
var parts = parameter.Split(':');
56+
57+
var username = parts[0];
58+
var password = parts[1];
59+
60+
if(ValidateUser(username, password))
61+
{
62+
SetClaimsIdentity(request, username);
63+
}
64+
}
65+
}
66+
67+
await Next.Invoke(context);
68+
}
69+
70+
protected virtual void SetClaimsIdentity(IOwinRequest request, string username)
71+
{
72+
var claims = new []
73+
{
74+
new Claim(ClaimTypes.Name, username)
75+
}
76+
.Concat(
77+
GetRolesForUser(username).Select(r=>new Claim(ClaimTypes.Role, r))
78+
);
79+
80+
var id = new ClaimsIdentity(claims, "Basic");
81+
request.User = new ClaimsPrincipal(id);
82+
}
83+
84+
protected virtual IEnumerable<string> GetRolesForUser(string username)
85+
{
86+
if (username.ToLower().StartsWith("admin"))
87+
return new[] { "Admin" };
88+
89+
return Enumerable.Empty<string>();
90+
}
91+
92+
protected virtual bool ValidateUser(string username, string password)
93+
{
94+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
95+
{
96+
return false;
97+
}
98+
99+
return true;
100+
}
101+
}
102+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using System.Web.Http;
4+
using NuGet.Server.V2.Controllers;
5+
6+
namespace NuGet.Server.V2.Samples.OwinHost.Controllers
7+
{
8+
/// <summary>
9+
/// Controller that exposes Program.NuGetPrivateRepository as NuGet OData feed
10+
/// that allows read/download access for all authenticated users.
11+
/// delete/upload is not allowed (no authenticationservice is passed to NuGetODataControllers constructor)
12+
/// </summary>
13+
[Authorize]
14+
public class NuGetPrivateODataController : NuGetODataController
15+
{
16+
public NuGetPrivateODataController()
17+
: base(Program.NuGetPrivateRepository)
18+
// Replace line above with the one below to allow upload/delete for all authenticated users
19+
// : base(Program.NuGetPrivateRepository, new ApiKeyPackageAuthenticationService(false, null))
20+
{
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using NuGet.Server.Core.Infrastructure;
4+
using NuGet.Server.V2.Controllers;
5+
6+
namespace NuGet.Server.V2.Samples.OwinHost.Controllers
7+
{
8+
/// <summary>
9+
/// Controller that exposes Program.NuGetPublicRepository as NuGet OData feed
10+
/// that allows unauthenticated read/download access.
11+
/// Delete/upload requires user supplied ApiKey to match Program.ApiKey.
12+
/// </summary>
13+
public class NuGetPublicODataController : NuGetODataController
14+
{
15+
public NuGetPublicODataController()
16+
: base(Program.NuGetPublicRepository, new ApiKeyPackageAuthenticationService(true,Program.ApiKey))
17+
{
18+
19+
}
20+
}
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using NuGet.Server.Core.Infrastructure;
4+
using NuGet.Server.V2.Controllers;
5+
6+
namespace NuGet.Server.V2.Samples.OwinHost.Controllers
7+
{
8+
/// <summary>
9+
/// Controller that exposes Program.NuGetPublicRepository as NuGet OData feed
10+
/// that allows unauthenticated read/download access.
11+
/// Delete/upload is allowed without authentication or apikey.
12+
/// </summary>
13+
public class NuGetVeryPublicODataController : NuGetODataController
14+
{
15+
static IPackageAuthenticationService CreateAuthenticationService()
16+
{
17+
//Allows write access without apikey
18+
return new ApiKeyPackageAuthenticationService(false, null);
19+
}
20+
21+
public NuGetVeryPublicODataController()
22+
: base(Program.NuGetVeryPublicRepository, CreateAuthenticationService())
23+
{
24+
25+
}
26+
27+
//Uncomment lines below to only allow delete for authorized users in Admin role
28+
//[Authorize(Roles = "Admin")]
29+
//public override Task<HttpResponseMessage> UploadPackage()
30+
//{
31+
// return base.UploadPackage();
32+
//}
33+
34+
//Uncomment lines below to only allow delete for authorized users in Admin role
35+
//[Authorize(Roles = "Admin")]
36+
//public override HttpResponseMessage DeletePackage(string id, string version)
37+
//{
38+
// return base.DeletePackage(id, version);
39+
//}
40+
}
41+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using System.Collections.Generic;
4+
using NuGet.Server.Core.Infrastructure;
5+
6+
namespace NuGet.Server.V2.Samples.OwinHost
7+
{
8+
public class DictionarySettingsProvider : ISettingsProvider
9+
{
10+
readonly Dictionary<string, bool> _settings;
11+
12+
public DictionarySettingsProvider(Dictionary<string, bool> settings)
13+
{
14+
_settings = settings;
15+
}
16+
17+
18+
public bool GetBoolSetting(string key, bool defaultValue)
19+
{
20+
System.Diagnostics.Debug.WriteLine("getSetting: " + key);
21+
return _settings.ContainsKey(key) ? _settings[key] : defaultValue;
22+
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)