package Ġhr . fer . pp ij . service Ċ Ċ import Ġhr . fer . pp ij . repository . UserRepository Ċ import Ġorg . springframework . security . core . Granted Authority Ċ import Ġorg . springframework . security . core . authority . Simple Granted Authority Ċ import Ġorg . springframework . security . core . user details . User Ċ import Ġorg . springframework . security . core . user details . UserDetails Ċ import Ġorg . springframework . security . core . user details . UserDetails Service Ċ import Ġorg . springframework . security . core . user details . Username NotFoundException Ċ import Ġorg . springframework . stereotype . Component Ċ Ċ @ Component Ċ class ĠApp UserDetails Service ( ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġuser Repository : ĠUser Repository Ċ ) Ġ: ĠUser Details Service Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġload User By Username ( s : ĠString ): ĠUser Details Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Ġ= Ġuser Repository . findBy UserName ( s ). orElse Throw Ġ{ ĠUsername NotFoundException (" The Ġusername Ġ$ s Ġdoesn 't Ġexist ") Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġauthor ities Ġ= ĠArrayList < Granted Authority >() ĊĠĠĠĠĠĠĠ Ġauthor ities . add ( Simple Granted Authority ( if Ġ( user . admin ) Ġ" ADMIN " Ġelse Ġ" USER ")) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠUser ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġuser . userName , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġuser . password , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġauthor ities ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ }