package Ġat . rech ner her z . example . config . auth Ċ Ċ import Ġmu . Kotlin Logging Ċ import Ġorg . springframework . security . authentication . Username Password Authentication Token Ċ import Ġorg . springframework . security . authentication . dao . Dao Authentication Provider Ċ import Ġorg . springframework . security . core . user details . UserDetails Ċ import Ġorg . springframework . security . core . user details . UserDetails Service Ċ import Ġorg . springframework . security . crypto . password . Password Encoder Ċ Ċ /** Ċ Ġ* ĠExt ends Ġthe Ġdefault Ġ[ Dao Authentication Provider ] Ġto Ġadd Ġadditional Ġauthentication Ġchecks . Ċ Ġ* Ċ Ġ* ĠRetrieves Ġ[ UserDetails ] Ġfrom Ġthe Ġ[ UserDetails Service ] Ġand Ġauthentic ates Ġthe Ġuser Ġwith Ġa Ġ[ Password Encoder ]. Ċ Ġ* Ċ Ġ* ĠIf Ġ[ password Encoder ] Ġis Ġnot Ġset , Ġuses Ġthe Ġdefault Ġ[ org . springframework . security . crypto . factory . Password Encoder Factories . create Delegating Password Encoder ]. Ċ Ġ* Ċ Ġ* ĠAdditionally Ġchecks Ġfor Ġtoo Ġmany Ġfailed Ġlogin Ġattempts Ġwith Ġthe Ġ[ Login Attempt Service ]. Ċ Ġ* Ċ Ġ* Ġ[ How Ġdo ĠI Ġaccess Ġthe Ġuser 's ĠIP ĠAddress Ġ... ?]( https :// docs . spring . io / spring - security / site / faq / faq . html # faq - request - details - in - user - service ) Ċ Ġ*/ Ċ class ĠLogin Attempt Dao Authentication Provider ( ĊĠĠĠ Ġprivate Ġvar Ġlogin Attempt Service : ĠLogin Attempt Service , ĊĠĠĠ Ġuser Details Service : ĠUser Details Service , ĊĠĠĠ Ġpassword Encoder : ĠPassword Encoder ? Ġ= Ġnull Ċ ) Ġ: ĠDao Authentication Provider () Ġ{ ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUser Details Service ( user Details Service ) ĊĠĠĠĠĠĠĠ Ġif Ġ( password Encoder Ġ!= Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuper . set Password Encoder ( password Encoder ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠKotlin Logging . logger Ġ{} ĊĊĠĠĠ Ġoverride Ġfun Ġadditional Authentication Checks ( ĊĠĠĠĠĠĠĠ Ġuser Details : ĠUser Details , ĊĠĠĠĠĠĠĠ Ġauthentication : ĠUsername Password Authentication Token ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . additional Authentication Checks ( user Details , Ġauthentication ) ĊĊĠĠĠĠĠĠĠ Ġval Ġip : ĠString Ġ= Ġauthentication . remote Address () Ġ?: Ġ"[ unknown ]" ĊĠĠĠĠĠĠĠ Ġval Ġusername : ĠString Ġ= Ġauthentication . name ĊĠĠĠĠĠĠĠ Ġlog . debug Ġ{ Ġ" Login Ġattempt Ġfor Ġuser Ġ'$ username ' Ġfrom ĠIP Ġ'$ ip '" Ġ} ĊĊĠĠĠĠĠĠĠ Ġif Ġ( login Attempt Service . is IP Blocked ( ip )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠLogin Attempt Blocked Exception (" Too Ġmany Ġfailed Ġlogin Ġattempts Ġfrom ĠIP Ġ'$ ip '") ĊĊĠĠĠĠĠĠĠ Ġif Ġ( login Attempt Service . is Username Blocked ( username )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠLogin Attempt Blocked Exception (" Too Ġmany Ġfailed Ġlogin Ġattempts Ġfor Ġuser Ġ'$ username '") ĊĠĠĠ Ġ} Ċ Ċ } Ċ