Skip to content

Commit 08326ff

Browse files
authored
ROPC fixes for System.ServiceModel and System.Net (dotnet#10730)
1 parent fac2678 commit 08326ff

File tree

32 files changed

+280
-979
lines changed

32 files changed

+280
-979
lines changed

snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.ConnectionGroupName Example/CPP/source.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

snippets/csharp/System.Net/WebRequest/PreAuthenticate/Project.csproj

Lines changed: 0 additions & 8 deletions
This file was deleted.

snippets/csharp/System.Net/WebRequest/PreAuthenticate/webrequest_preauthenticate.cs

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net481</TargetFramework>
6+
<LangVersion>11</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Reference Include="System.Configuration" />
11+
<Reference Include="System.IdentityModel" />
12+
<Reference Include="System.ServiceModel" />
13+
</ItemGroup>
14+
15+
</Project>

snippets/csharp/VS_Snippets_CFX/c_claimset/cs/makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

snippets/csharp/VS_Snippets_CFX/c_claimset/cs/service.cs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Configuration;
7-
87
using System.IdentityModel.Claims;
98
using System.IdentityModel.Policy;
10-
using System.IdentityModel.Tokens;
119
using System.IdentityModel.Selectors;
12-
1310
using System.Security.Principal;
1411

1512
using System.ServiceModel;
16-
using System.ServiceModel.Description;
17-
using System.ServiceModel.Security;
1813

1914
namespace Microsoft.ServiceModel.Samples
2015
{
2116
// Define a service contract.
22-
[ServiceContract(Namespace="http://microsoft.servicemodel.samples/")]
17+
[ServiceContract(Namespace = "http://microsoft.servicemodel.samples/")]
2318
public interface ICalculator
2419
{
2520
[OperationContract]
@@ -34,16 +29,16 @@ public interface ICalculator
3429

3530
// Service class that implements the service contract.
3631
// Added code to write output to the console window.
37-
[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
38-
32+
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
33+
3934
public class CalculatorService : ICalculator
4035
{
4136
public double Add(double n1, double n2)
4237
{
4338
double result = n1 + n2;
4439
Console.WriteLine("Received Add({0},{1})", n1, n2);
4540
Console.WriteLine("Return: {0}", result);
46-
return result;
41+
return result;
4742
}
4843

4944
public double Subtract(double n1, double n2)
@@ -74,7 +69,7 @@ public double Divide(double n1, double n2)
7469
public class MyServiceAuthorizationManager : ServiceAuthorizationManager
7570
{
7671

77-
protected override bool CheckAccessCore(OperationContext operationContext)
72+
protected override bool CheckAccessCore(OperationContext operationContext)
7873
{
7974
// Extract the action URI from the OperationContext. Match this against the claims
8075
// in the AuthorizationContext.
@@ -83,7 +78,7 @@ protected override bool CheckAccessCore(OperationContext operationContext)
8378
Console.WriteLine("action: {0}", action);
8479

8580
// Iterate through the various claim sets in the AuthorizationContext.
86-
foreach(ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets)
81+
foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets)
8782
{
8883
// Examine only those claim sets issued by System.
8984
if (cs.Issuer == ClaimSet.System)
@@ -109,13 +104,14 @@ protected override bool CheckAccessCore(OperationContext operationContext)
109104
}
110105
}
111106
// </snippet1>
107+
112108
public class MyAuthorizationPolicy : IAuthorizationPolicy
113109
{
114110
string id;
115111

116112
public MyAuthorizationPolicy()
117113
{
118-
id = Guid.NewGuid().ToString();
114+
id = Guid.NewGuid().ToString();
119115
}
120116

121117
//
@@ -158,7 +154,7 @@ public bool Evaluate(EvaluationContext evaluationContext, ref object state)
158154
}
159155

160156
// Add claims to the evaluation context.
161-
evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer,claims));
157+
evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer, claims));
162158

163159
// Record that the claims have been added.
164160
customstate.ClaimsAdded = true;
@@ -193,14 +189,14 @@ private IEnumerable<string> GetAllowedOpList(string username)
193189

194190
if (username == "test1")
195191
{
196-
ret.Add ( "http://microsoft.servicemodel.samples/ICalculator/Add");
197-
ret.Add ("http://microsoft.servicemodel.samples/ICalculator/Multiply");
192+
ret.Add("http://microsoft.servicemodel.samples/ICalculator/Add");
193+
ret.Add("http://microsoft.servicemodel.samples/ICalculator/Multiply");
198194
ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract");
199195
}
200196
else if (username == "test2")
201197
{
202-
ret.Add ( "http://microsoft.servicemodel.samples/ICalculator/Add");
203-
ret.Add ("http://microsoft.servicemodel.samples/ICalculator/Subtract");
198+
ret.Add("http://microsoft.servicemodel.samples/ICalculator/Add");
199+
ret.Add("http://microsoft.servicemodel.samples/ICalculator/Subtract");
204200
}
205201
return ret;
206202
}
@@ -215,46 +211,37 @@ public CustomAuthState()
215211
bClaimsAdded = false;
216212
}
217213

218-
public bool ClaimsAdded { get { return bClaimsAdded; }
219-
set { bClaimsAdded = value; } }
214+
public bool ClaimsAdded
215+
{
216+
get { return bClaimsAdded; }
217+
set { bClaimsAdded = value; }
218+
}
220219
}
221220
}
222221

223222
public class MyCustomUserNameValidator : UserNamePasswordValidator
224223
{
225-
// This method validates users. It allows two users, test1 and test2
226-
// with passwords 1tset and 2tset respectively.
227-
// This code is for illustration purposes only and
228-
// MUST NOT be used in a production environment because it is NOT secure.
229224
public override void Validate(string userName, string password)
230225
{
231-
if (null == userName || null == password)
232-
{
233-
throw new ArgumentNullException();
234-
}
235-
236-
if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
237-
{
238-
throw new SecurityTokenException("Unknown Username or Password");
239-
}
226+
throw new NotImplementedException();
240227
}
241228
}
242229

243230
// Host the service within this EXE console application.
244231
public static void Main()
245232
{
246233
// Get the base address from appsettings in configuration.
247-
Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
234+
Uri baseAddress = new(ConfigurationManager.AppSettings["baseAddress"]);
248235

249236
// Create a ServiceHost for the CalculatorService type and provide the base address.
250237
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
251238
{
252239
// Open the ServiceHostBase to create listeners and start listening for messages.
253240
serviceHost.Open();
254-
241+
255242
// The service can now be accessed.
256243
Console.WriteLine("The service is ready.");
257-
Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name);
244+
Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name);
258245
Console.WriteLine("Press <ENTER> to terminate service.");
259246
Console.WriteLine();
260247
Console.ReadLine();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net481</TargetFramework>
6+
<LangVersion>11</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Reference Include="System.Configuration" />
11+
<Reference Include="System.IdentityModel" />
12+
<Reference Include="System.ServiceModel" />
13+
</ItemGroup>
14+
15+
</Project>

snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)