Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliyaMalik committed May 11, 2018
2 parents 57c26b4 + ed75c93 commit 037547f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.1.1</Version>
<Version>3.1.2</Version>
<Description>The storefront implementation of the Virto Commerce platform.</Description>
<Copyright>Copyright © 2011-2018 Virto Commerce - an enterprise Microsoft ecommerce platform ©. All rights reserved</Copyright>
<Authors>Virto Commerce</Authors>
Expand All @@ -12,18 +12,18 @@
<PackageProjectUrl>https://github.com/VirtoCommerce/vc-storefront-core</PackageProjectUrl>
<PackageIconUrl>https://virtocommerce.com/themes/assets/logo.jpg</PackageIconUrl>
<RepositoryUrl>https://github.com/VirtoCommerce/vc-storefront-core</RepositoryUrl>
<AssemblyVersion>3.1.1.0</AssemblyVersion>
<FileVersion>3.1.1.0</FileVersion>
<AssemblyVersion>3.1.2.0</AssemblyVersion>
<FileVersion>3.1.2.0</FileVersion>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="DotLiquid.VirtoCommerce" Version="1.8.3" />
<PackageReference Include="LibSassHost" Version="1.1.3" />
<PackageReference Include="LibSassHost.Native.linux-x64" Version="1.1.3" />
<PackageReference Include="LibSassHost.Native.win-x64" Version="1.1.3" />
<PackageReference Include="LibSassHost.Native.win-x86" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="LibSassHost" Version="1.1.9" />
<PackageReference Include="LibSassHost.Native.linux-x64" Version="1.1.9" />
<PackageReference Include="LibSassHost.Native.win-x64" Version="1.1.9" />
<PackageReference Include="LibSassHost.Native.win-x86" Version="1.1.9" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="PagedList.Core" Version="1.17.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class CancellableCacheRegion<T>

public static IChangeToken CreateChangeToken()
{
if(_regionTokenSource == null)
if(_regionChangeToken == null)
{
lock (_lock)
{
if (_regionTokenSource == null)
if (_regionChangeToken == null)
{
_regionTokenSource = new CancellationTokenSource();
_regionChangeToken = new CancellationChangeToken(_regionTokenSource.Token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<PackageProjectUrl>https://github.com/VirtoCommerce/vc-storefront-core</PackageProjectUrl>
<PackageIconUrl>https://virtocommerce.com/themes/assets/logo.jpg</PackageIconUrl>
<RepositoryUrl>https://github.com/VirtoCommerce/vc-storefront-core</RepositoryUrl>
<AssemblyVersion>3.1.1.0</AssemblyVersion>
<FileVersion>3.1.1.0</FileVersion>
<Version>3.1.1</Version>
<AssemblyVersion>3.1.2.0</AssemblyVersion>
<FileVersion>3.1.2.0</FileVersion>
<Version>3.1.2</Version>
<Authors>Virto Commerce</Authors>
<Company>Virto Commerce</Company>
<Product>Virto Commerce</Product>
Expand All @@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="FluentValidation" Version="7.5.2" />
<PackageReference Include="PagedList.Core" Version="1.17.4" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.1" />
<PackageReference Include="PagedList.Core" Version="1.17.4" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.console" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion VirtoCommerce.Storefront/Domain/Security/CustomUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CustomUserManager(IUserStore<User> userStore, IOptions<IdentityOptions> o
}

//Stub for UserManager
public sealed class UserStoreStub : IUserStore<User>, IUserEmailStore<User>, IUserPasswordStore<User>, IUserLockoutStore<User>, IUserLoginStore<User>
public sealed class UserStoreStub : IUserStore<User>, IUserEmailStore<User>, IUserPasswordStore<User>, IUserLockoutStore<User>, IUserLoginStore<User>, IUserSecurityStampStore<User>
{
private readonly ISecurity _platformSecurityApi;
private readonly IMemoryCache _memoryCache;
Expand Down Expand Up @@ -322,11 +322,25 @@ public Task SetPasswordHashAsync(User user, string passwordHash, CancellationTok
}
#endregion

#region IUserSecurityStampStore<User> members
public Task SetSecurityStampAsync(User user, string stamp, CancellationToken cancellationToken)
{
user.SecurityStamp = stamp;
return Task.CompletedTask;
}

public Task<string> GetSecurityStampAsync(User user, CancellationToken cancellationToken)
{
return Task.FromResult(user.SecurityStamp);
}
#endregion

public void Dispose()
{
// Cleanup
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static async Task WithCurrentUserAsync(this IWorkContextBuilder builder)
};

var identity = builder.HttpContext.User.Identity;
if (identity.IsAuthenticated)
if (identity.IsAuthenticated && user.UserName != SecurityConstants.AnonymousUsername)
{
user = await signInManager.UserManager.FindByNameAsync(identity.Name);
//User has been removed from storage or current store is not allowed for signed in user
Expand All @@ -49,6 +49,7 @@ public static async Task WithCurrentUserAsync(this IWorkContextBuilder builder)
user = new User
{
Id = Guid.NewGuid().ToString(),
SecurityStamp = Guid.NewGuid().ToString(),
UserName = SecurityConstants.AnonymousUsername,
};
//Workaround: Do not sign out for js map requests they are always coming without authentication
Expand Down
46 changes: 18 additions & 28 deletions VirtoCommerce.Storefront/Domain/Security/UserPrincipalFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,56 @@

namespace VirtoCommerce.Storefront.Domain.Security
{
public class UserPrincipalFactory : IUserClaimsPrincipalFactory<User>
public class UserPrincipalFactory : UserClaimsPrincipalFactory<User>
{
private readonly IdentityOptions _options;

public UserPrincipalFactory(IOptions<IdentityOptions> optionsAccessor)
public UserPrincipalFactory(UserManager<User> userManager, IOptions<IdentityOptions> optionsAccessor)
:base(userManager, optionsAccessor)
{
_options = optionsAccessor?.Value ?? new IdentityOptions();
}

public Task<ClaimsPrincipal> CreateAsync(User user)
protected override async Task<ClaimsIdentity> GenerateClaimsAsync(User user)
{
//Create first anonymous identity
var identity = new ClaimsIdentity();
if(user.IsRegisteredUser)
{
//https://stackoverflow.com/questions/45261732/user-identity-isauthenticated-always-false-in-net-core-custom-authentication
identity = new ClaimsIdentity("Registered");
}

identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));

var result = await base.GenerateClaimsAsync(user);

if (user.IsAdministrator)
{
identity.AddClaim(new Claim(ClaimTypes.Role, SecurityConstants.Roles.Administrator));
result.AddClaim(new Claim(ClaimTypes.Role, SecurityConstants.Roles.Administrator));
}

if (user.SelectedCurrencyCode != null)
{
identity.AddClaim(new Claim(SecurityConstants.Claims.CurrencyClaimType, user.SelectedCurrencyCode));
result.AddClaim(new Claim(SecurityConstants.Claims.CurrencyClaimType, user.SelectedCurrencyCode));
}

if (!string.IsNullOrEmpty(user.OperatorUserName))
{
identity.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserNameClaimType, user.OperatorUserName));
result.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserNameClaimType, user.OperatorUserName));
}

if (!string.IsNullOrEmpty(user.OperatorUserId))
{
identity.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserIdClaimType, user.OperatorUserId));
identity.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserNameClaimType, user.OperatorUserName));
result.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserIdClaimType, user.OperatorUserId));
result.AddClaim(new Claim(SecurityConstants.Claims.OperatorUserNameClaimType, user.OperatorUserName));
}

if(!user.Permissions.IsNullOrEmpty())
if (!user.Permissions.IsNullOrEmpty())
{
foreach(var permission in user.Permissions)
foreach (var permission in user.Permissions)
{
identity.AddClaim(new Claim(SecurityConstants.Claims.PermissionClaimType, permission));
result.AddClaim(new Claim(SecurityConstants.Claims.PermissionClaimType, permission));
}
}
if (!user.Roles.IsNullOrEmpty())
{
foreach (var role in user.Roles)
{
identity.AddClaim(new Claim(ClaimTypes.Role, role.Id));
result.AddClaim(new Claim(ClaimTypes.Role, role.Id));
}
}
var principal = new ClaimsPrincipal(identity);

return Task.FromResult(principal);

return result;
}

}
}
31 changes: 18 additions & 13 deletions VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
<PackageLicenseUrl>https://virtocommerce.com/open-source-license</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/VirtoCommerce/vc-storefront-core</PackageProjectUrl>
<RepositoryUrl>https://github.com/VirtoCommerce/vc-storefront-core</RepositoryUrl>
<AssemblyVersion>3.1.1.0</AssemblyVersion>
<FileVersion>3.1.1.0</FileVersion>
<Version>3.1.1</Version>
<AssemblyVersion>3.1.2.0</AssemblyVersion>
<FileVersion>3.1.2.0</FileVersion>
<Version>3.1.2</Version>
<Copyright>Copyright © 2011-2018 Virto Commerce - an enterprise Microsoft ecommerce platform ©. All rights reserved</Copyright>
<PackageIconUrl>https://virtocommerce.com/themes/assets/logo.jpg</PackageIconUrl>
<PackageReleaseNotes></PackageReleaseNotes>
<ApplicationInsightsResourceId>/subscriptions/bb0218ea-8621-40d8-811e-e3a17bc72362/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/VirtoCommerce.Storefront</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/bb0218ea-8621-40d8-811e-e3a17bc72362/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/VirtoCommerce.Storefront</ApplicationInsightsAnnotationResourceId>
<!--Remove later when Azure apps has been updated-->
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Routing\StorefrontRouteExtensions.cs" />
</ItemGroup>

<ItemGroup>
<Content Remove="wwwroot\%2a%2a" />
</ItemGroup>

<ItemGroup>
<Content Include="IISUrlRewrite.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -33,16 +37,16 @@
<ItemGroup>
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="2.0.0-rc2-final" />
<PackageReference Include="AspNet.Security.OAuth.StackExchange" Version="2.0.0-rc2-final" />
<PackageReference Include="Markdig" Version="0.13.3" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.0-beta1" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.5.0-beta1" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.5.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.0" />
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.0" />
<PackageReference Include="Markdig" Version="0.15.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.6.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.5.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.3" />
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
<PackageReference Include="MimeTypes" Version="1.0.6" />
<PackageReference Include="PagedList.Core" Version="1.17.4" />
<PackageReference Include="Scrutor" Version="2.1.2" />
<PackageReference Include="Scrutor" Version="2.2.2" />
<PackageReference Include="VirtoCommerce.Tools" Version="1.2.0" />
<PackageReference Include="YamlDotNet.NetCore" Version="1.0.0" />
</ItemGroup>
Expand All @@ -54,6 +58,7 @@

<ItemGroup>
<Folder Include="AutoRestClients\" />
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 037547f

Please sign in to comment.