package Ġit . pol ito . ap . catalog service . config Ċ Ċ import Ġit . pol ito . ap . catalog service . repository . UserRepository Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . security . authentication . Authentication Provider Ċ import Ġorg . springframework . security . authentication . Username Password Authentication Token Ċ import Ġorg . springframework . security . core . Authentication Ċ import Ġorg . springframework . security . core . Authentication Exception Ċ import Ġorg . springframework . security . core . authority . Simple Granted Authority Ċ import Ġorg . springframework . stereotype . Component Ċ Ċ @ Component Ċ class ĠCustom Authentication Provider ( val Ġuser Repository : ĠUser Repository ) Ġ: ĠAuthentication Provider Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠLOGGER Ġ= ĠLoggerFactory . getLogger ( Custom Authentication Provider :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( Authentication Exception :: class ) ĊĠĠĠ Ġoverride Ġfun Ġauthenticate ( authentication : ĠAuthentication ): ĠAuthentication ? Ġ{ ĊĠĠĠĠĠĠĠ ĠLOGGER . info ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Authentication Ġuser Ġ${ authentication . name }, ${ authentication . credentials } Ġ-> Ġ${ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġauthentication . credentials . toString () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}" ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= Ġuser Repository . findBy Email And Password ( authentication . name , Ġauthentication . credentials . toString ()) ĊĠĠĠĠĠĠĠ Ġuser ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġauthor ities Ġ= Ġset Of ( Simple Granted Authority ( user . role . toString ())) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLOGGER . info (" Found Ġuser Ġ${ user . name }, Ġ${ user . surname }, Ġ$ author ities ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠUsername Password Authentication Token ( user , Ġauthentication . name , Ġauthor ities ) ĊĠĠĠĠĠĠĠ Ġ} Ġ?: Ġkotlin . run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLOGGER . info (" User Ġnot Ġfound Ġinto Ġthe ĠDB ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġsupports ( authentication : ĠClass < *> ?): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġauthentication Ġ== ĠUsername Password Authentication Token :: class . java ĊĠĠĠ Ġ} Ċ }