Skip to content

Commit

Permalink
PT-13290: Use correct authorization error codes (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Sep 11, 2023
1 parent fddd27a commit 9a05fa2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ private async Task CheckAuthAsync(string userId, object resource, bool checkPass

if (checkPasswordExpired && user.PasswordExpired)
{
throw new AuthorizationError($"This user has their password expired. Please change the password using 'changePassword' command.");
throw AuthorizationError.PasswordExpired();
}

var userPrincipal = await signInManager.CreateUserPrincipalAsync(user);
Expand All @@ -770,7 +770,7 @@ private async Task CheckAuthAsync(string userId, object resource, bool checkPass
{
if (user.Logins is null)
{
throw new AuthorizationError($"Can't run the operation under anonymous user or the token expired or invalid.");
throw AuthorizationError.AnonymousAccessDenied();
}

foreach (var permission in permissions)
Expand All @@ -779,7 +779,7 @@ private async Task CheckAuthAsync(string userId, object resource, bool checkPass
null, new PermissionAuthorizationRequirement(permission));
if (!permissionAuthorizationResult.Succeeded)
{
throw new ForbiddenError($"User doesn't have the required permission '{permission}'.");
throw AuthorizationError.PermissionRequired(permission);
}
}
}
Expand All @@ -789,7 +789,7 @@ private async Task CheckAuthAsync(string userId, object resource, bool checkPass

if (!authorizationResult.Succeeded)
{
throw new ForbiddenError($"Access denied");
throw AuthorizationError.Forbidden();
}
}
catch (AuthorizationError ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.400.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.400.0" />
<PackageReference Include="VirtoCommerce.ExperienceApiModule.Core" Version="3.400.0" />
<PackageReference Include="VirtoCommerce.ExperienceApiModule.Core" Version="3.411.0" />
<PackageReference Include="VirtoCommerce.MarketingModule.Core" Version="3.400.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.Core" Version="3.400.0" />
<PackageReference Include="VirtoCommerce.Platform.Security" Version="3.400.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<dependencies>
<dependency id="VirtoCommerce.Core" version="3.400.0" />
<dependency id="VirtoCommerce.Customer" version="3.400.0" />
<dependency id="VirtoCommerce.ExperienceApi" version="3.400.0" />
<dependency id="VirtoCommerce.ExperienceApi" version="3.411.0" />
<dependency id="VirtoCommerce.Marketing" version="3.400.0" />
<dependency id="VirtoCommerce.Notifications" version="3.400.0" />
<dependency id="VirtoCommerce.Pricing" version="3.400.0" />
Expand All @@ -33,4 +33,4 @@
<group>commerce</group>
</groups>
<useFullTypeNameInSwagger>false</useFullTypeNameInSwagger>
</module>
</module>

0 comments on commit 9a05fa2

Please sign in to comment.