@@ -318,7 +318,16 @@ std::vector<TString> TLoginProvider::GetGroupsMembership(const TString& member)
318318}
319319
320320TLoginProvider::TLoginUserResponse TLoginProvider::LoginUser (const TLoginUserRequest& request) {
321+ auto now = std::chrono::system_clock::now ();
321322 TLoginUserResponse response;
323+ response.LoginAttemptTime = std::chrono::time_point_cast<std::chrono::microseconds>(now).time_since_epoch ().count ();
324+
325+ if (Keys.empty () || Keys.back ().PrivateKey .empty ()) {
326+ response.Status = TLoginUserResponse::EStatus::UNAVAILABLE_KEY;
327+ response.Error = " No key to generate token" ;
328+ return response;
329+ }
330+
322331 if (!request.ExternalAuth ) {
323332 auto itUser = Sids.find (request.User );
324333 if (itUser == Sids.end () || itUser->second .Type != ESidType::USER) {
@@ -332,22 +341,16 @@ TLoginProvider::TLoginUserResponse TLoginProvider::LoginUser(const TLoginUserReq
332341 response.Error = " Invalid password" ;
333342 return response;
334343 }
335- }
336344
337- if (Keys.empty () || Keys.back ().PrivateKey .empty ()) {
338- response.Status = TLoginUserResponse::EStatus::UNAVAILABLE_KEY;
339- response.Error = " No key to generate token" ;
340- return response;
345+ itUser->second .LastSuccessfulLogin = response.LoginAttemptTime ;
341346 }
342347
343348 const TKeyRecord& key = Keys.back ();
344-
345349 auto keyId = ToString (key.KeyId );
346350 const auto & publicKey = key.PublicKey ;
347351 const auto & privateKey = key.PrivateKey ;
348352
349353 // encode jwt
350- auto now = std::chrono::system_clock::now ();
351354 auto expires_at = now + MAX_TOKEN_EXPIRE_TIME;
352355 if (request.Options .ExpiresAfter != std::chrono::system_clock::duration::zero ()) {
353356 expires_at = std::min (expires_at, now + request.Options .ExpiresAfter );
@@ -668,6 +671,7 @@ void TLoginProvider::UpdateSecurityState(const NLoginProto::TSecurityState& stat
668671 sid.Type = pbSid.GetType ();
669672 sid.Name = pbSid.GetName ();
670673 sid.Hash = pbSid.GetHash ();
674+ sid.LastSuccessfulLogin = pbSid.GetLastSuccessfulLogin ();
671675 for (const auto & pbSubSid : pbSid.GetMembers ()) {
672676 sid.Members .emplace (pbSubSid);
673677 ChildToParentIndex[pbSubSid].emplace (sid.Name );
0 commit comments