Skip to content

Commit

Permalink
Upgrade packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Rehan Saeed committed Jul 5, 2019
1 parent c73f152 commit aeb7c9a
Show file tree
Hide file tree
Showing 56 changed files with 2,843 additions and 2,443 deletions.
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup Label="Build">
<OutputType>Exe</OutputType>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">netcoreapp2.2;net461</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.2</TargetFramework>
<TargetFrameworks>netcoreapp2.2;net461;net472</TargetFrameworks>
<CodeAnalysisRuleSet>../../MinimumRecommendedRulesWithStyleCop.ruleset</CodeAnalysisRuleSet>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
Expand All @@ -15,10 +14,12 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper" Version="8.1.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="2.9.2" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.1-beta.61" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="2.9.3" />
<!-- See https://github.com/Microsoft/dotnet/tree/master/releases/reference-assemblies -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0-preview.2" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>

</Project>
43 changes: 27 additions & 16 deletions Benchmarks/Boxed.Mapping.Benchmark/Mapping/BoxedMapper.cs
@@ -1,16 +1,27 @@
namespace Boxed.Mapping.Benchmark.Mapping
{
using Boxed.Mapping.Benchmark.Models;

public class BoxedMapper : IMapper<MapFrom, MapTo>
{
public void Map(MapFrom source, MapTo destination)
{
destination.BooleanTo = source.BooleanFrom;
destination.DateTimeOffsetTo = source.DateTimeOffsetFrom;
destination.IntegerTo = source.IntegerFrom;
destination.LongTo = source.LongFrom;
destination.StringTo = source.StringFrom;
}
}
}
namespace Boxed.Mapping.Benchmark.Mapping
{
using System;
using Boxed.Mapping.Benchmark.Models;

public class BoxedMapper : IMapper<MapFrom, MapTo>
{
public void Map(MapFrom source, MapTo destination)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

if (destination == null)
{
throw new ArgumentNullException(nameof(destination));
}

destination.BooleanTo = source.BooleanFrom;
destination.DateTimeOffsetTo = source.DateTimeOffsetFrom;
destination.IntegerTo = source.IntegerFrom;
destination.LongTo = source.LongFrom;
destination.StringTo = source.StringFrom;
}
}
}
3 changes: 2 additions & 1 deletion Framework.sln
Expand Up @@ -5,9 +5,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F316174B-045B-4DC0-9097-8CE746A8BBB0}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
azure-pipelines.yml = azure-pipelines.yml
build.cake = build.cake
global.json = global.json
MinimumRecommendedRulesWithStyleCop.ruleset = MinimumRecommendedRulesWithStyleCop.ruleset
Expand Down
3 changes: 2 additions & 1 deletion MinimumRecommendedRulesWithStyleCop.ruleset
Expand Up @@ -10,7 +10,8 @@
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
Expand Down
Expand Up @@ -43,9 +43,9 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="2.9.2" />
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0-beta2-18618-05" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.1-beta.61" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="2.9.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0-beta2-19351-01" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>

Expand Down
@@ -1,39 +1,50 @@
namespace Boxed.AspNetCore.Swagger.OperationFilters
{
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Adds claims from any authorization policy's <see cref="ClaimsAuthorizationRequirement"/>'s.
/// </summary>
/// <seealso cref="IOperationFilter" />
public class ClaimsOperationFilter : IOperationFilter
{
/// <summary>
/// Applies the specified operation.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="context">The context.</param>
public void Apply(Operation operation, OperationFilterContext context)
{
var filterDescriptors = context.ApiDescription.ActionDescriptor.FilterDescriptors;
var authorizationRequirements = filterDescriptors.GetPolicyRequirements();
var claimTypes = authorizationRequirements
.OfType<ClaimsAuthorizationRequirement>()
.Select(x => x.ClaimType);
if (claimTypes.Any())
{
operation.Security = new List<IDictionary<string, IEnumerable<string>>>()
{
new Dictionary<string, IEnumerable<string>>()
{
{ "oauth2", claimTypes }
}
};
}
}
}
}
namespace Boxed.AspNetCore.Swagger.OperationFilters
{
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Adds claims from any authorization policy's <see cref="ClaimsAuthorizationRequirement"/>'s.
/// </summary>
/// <seealso cref="IOperationFilter" />
public class ClaimsOperationFilter : IOperationFilter
{
/// <summary>
/// Applies the specified operation.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="context">The context.</param>
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation == null)
{
throw new ArgumentNullException(nameof(operation));
}

if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

var filterDescriptors = context.ApiDescription.ActionDescriptor.FilterDescriptors;
var authorizationRequirements = filterDescriptors.GetPolicyRequirements();
var claimTypes = authorizationRequirements
.OfType<ClaimsAuthorizationRequirement>()
.Select(x => x.ClaimType);
if (claimTypes.Any())
{
operation.Security = new List<IDictionary<string, IEnumerable<string>>>()
{
new Dictionary<string, IEnumerable<string>>()
{
{ "oauth2", claimTypes }
}
};
}
}
}
}
@@ -1,56 +1,67 @@
namespace Boxed.AspNetCore.Swagger.OperationFilters
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Adds a 403 Forbidden response to the Swagger response documentation when the authorization policy contains a
/// <see cref="ClaimsAuthorizationRequirement"/>, <see cref="NameAuthorizationRequirement"/>,
/// <see cref="RolesAuthorizationRequirement"/> or <see cref="AssertionRequirement"/>.
/// </summary>
/// <seealso cref="IOperationFilter" />
public class ForbiddenResponseOperationFilter : IOperationFilter
{
private const string ForbiddenStatusCode = "403";
private static readonly Response ForbiddenResponse = new Response()
{
Description = "Forbidden - The user does not have the necessary permissions to access the resource."
};

/// <summary>
/// Applies the specified operation.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="context">The context.</param>
public void Apply(Operation operation, OperationFilterContext context)
{
var filterDescriptors = context.ApiDescription.ActionDescriptor.FilterDescriptors;
var authorizationRequirements = filterDescriptors.GetPolicyRequirements();
if (!operation.Responses.ContainsKey(ForbiddenStatusCode) &&
HasAuthorizationRequirement(authorizationRequirements))
{
operation.Responses.Add(ForbiddenStatusCode, ForbiddenResponse);
}
}

private static bool HasAuthorizationRequirement(
IEnumerable<IAuthorizationRequirement> authorizationRequirements)
{
foreach (var authorizationRequirement in authorizationRequirements)
{
if (authorizationRequirement is ClaimsAuthorizationRequirement ||
authorizationRequirement is NameAuthorizationRequirement ||
authorizationRequirement is RolesAuthorizationRequirement ||
authorizationRequirement is AssertionRequirement)
{
return true;
}
}

return false;
}
}
namespace Boxed.AspNetCore.Swagger.OperationFilters
{
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Adds a 403 Forbidden response to the Swagger response documentation when the authorization policy contains a
/// <see cref="ClaimsAuthorizationRequirement"/>, <see cref="NameAuthorizationRequirement"/>,
/// <see cref="RolesAuthorizationRequirement"/> or <see cref="AssertionRequirement"/>.
/// </summary>
/// <seealso cref="IOperationFilter" />
public class ForbiddenResponseOperationFilter : IOperationFilter
{
private const string ForbiddenStatusCode = "403";
private static readonly Response ForbiddenResponse = new Response()
{
Description = "Forbidden - The user does not have the necessary permissions to access the resource."
};

/// <summary>
/// Applies the specified operation.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="context">The context.</param>
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation == null)
{
throw new ArgumentNullException(nameof(operation));
}

if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

var filterDescriptors = context.ApiDescription.ActionDescriptor.FilterDescriptors;
var authorizationRequirements = filterDescriptors.GetPolicyRequirements();
if (!operation.Responses.ContainsKey(ForbiddenStatusCode) &&
HasAuthorizationRequirement(authorizationRequirements))
{
operation.Responses.Add(ForbiddenStatusCode, ForbiddenResponse);
}
}

private static bool HasAuthorizationRequirement(
IEnumerable<IAuthorizationRequirement> authorizationRequirements)
{
foreach (var authorizationRequirement in authorizationRequirements)
{
if (authorizationRequirement is ClaimsAuthorizationRequirement ||
authorizationRequirement is NameAuthorizationRequirement ||
authorizationRequirement is RolesAuthorizationRequirement ||
authorizationRequirement is AssertionRequirement)
{
return true;
}
}

return false;
}
}
}

0 comments on commit aeb7c9a

Please sign in to comment.