18
18
using VirtoCommerce . Platform . Core . Security ;
19
19
using VirtoCommerce . Platform . Core . Security . Events ;
20
20
using VirtoCommerce . Platform . Security ;
21
+ using VirtoCommerce . Platform . Security . Services ;
21
22
using VirtoCommerce . Platform . Web . Model . Security ;
22
23
using static OpenIddict . Abstractions . OpenIddictConstants ;
23
24
@@ -31,6 +32,7 @@ public class AuthorizationController : Controller
31
32
private readonly UserManager < ApplicationUser > _userManager ;
32
33
private readonly PasswordLoginOptions _passwordLoginOptions ;
33
34
private readonly IEventPublisher _eventPublisher ;
35
+ private readonly List < IUserSignInValidator > _userSignInValidators ;
34
36
35
37
private UserManager < ApplicationUser > UserManager => _signInManager . UserManager ;
36
38
@@ -40,14 +42,16 @@ public AuthorizationController(
40
42
SignInManager < ApplicationUser > signInManager ,
41
43
UserManager < ApplicationUser > userManager ,
42
44
IOptions < PasswordLoginOptions > passwordLoginOptions ,
43
- IEventPublisher eventPublisher )
45
+ IEventPublisher eventPublisher ,
46
+ IEnumerable < IUserSignInValidator > userSignInValidators )
44
47
{
45
48
_applicationManager = applicationManager ;
46
49
_identityOptions = identityOptions . Value ;
47
50
_passwordLoginOptions = passwordLoginOptions . Value ?? new PasswordLoginOptions ( ) ;
48
51
_signInManager = signInManager ;
49
52
_userManager = userManager ;
50
53
_eventPublisher = eventPublisher ;
54
+ _userSignInValidators = userSignInValidators . ToList ( ) ;
51
55
}
52
56
53
57
#region Password, authorization code and refresh token flows
@@ -101,6 +105,16 @@ public async Task<ActionResult> Exchange()
101
105
return BadRequest ( SecurityErrorDescriber . LoginFailed ( ) ) ;
102
106
}
103
107
108
+ foreach ( var loginValidation in _userSignInValidators . OrderByDescending ( x => x . Priority ) . ThenBy ( x => x . GetType ( ) . Name ) . ToList ( ) )
109
+ {
110
+ var validationErrors = await loginValidation . ValidateUserAsync ( user , result , new Dictionary < string , object > ( ) ) ;
111
+ var error = validationErrors . FirstOrDefault ( ) ;
112
+ if ( error != null )
113
+ {
114
+ return BadRequest ( error ) ;
115
+ }
116
+ }
117
+
104
118
await _eventPublisher . Publish ( new BeforeUserLoginEvent ( user ) ) ;
105
119
106
120
// Create a new authentication ticket.
0 commit comments