package Ġmen . br ak h . bs u irst udent . security . authentication . credentials Ċ Ċ import Ġmen . br ak h . bs u irst udent . Spring Context Ċ import Ġmen . br ak h . bs u irst udent . domain . i is . student . repository . Student Repository Ċ import Ġmen . br ak h . bs u irst udent . security . authentication . bs uir . Password Encrypt Ċ import Ġorg . springframework . security . core . context . SecurityContext Holder Ċ import Ġorg . springframework . security . core . user details . UserDetails Ċ Ċ val Ġuser Credentials Repository Ġ= ĠSpring Context . getBean ( User Credentials Repository :: class . java ) Ċ val Ġpassword Encrypt Ġ= ĠSpring Context . getBean ( Password Encrypt :: class . java ) Ċ val Ġstudent Repository Ġ= ĠSpring Context . getBean ( Student Repository :: class . java ) Ċ fun ĠgetCurrent User Username (): ĠString Ġ{ ĊĠĠĠ Ġval Ġprincipal Ġ= ĠSecurity Context Holder . getContext ()?. authentication ?. principal ĊĊĠĠĠ Ġreturn Ġif Ġ( principal Ġis ĠUser Details ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprincipal . username ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġprincipal . toString () ĊĠĠĠ Ġ} Ċ } ĊĊ Ċ inline Ġfun Ġuse B su ir Credentials ( func : Ġ( username : ĠString , Ġpassword : ĠString ) Ġ-> ĠAny ) Ġ{ ĊĠĠĠ Ġval Ġusername Ġ= ĠgetCurrent User Username () ĊĊĠĠĠ Ġval Ġcredentials Ġ= Ġuser Credentials Repository . findOne By Username ( username ) !! ĊĊĠĠĠ Ġfunc ( username , Ġpassword Encrypt . decrypt ( credentials . password )) Ċ } Ċ