package Ġes . ur jc . real food . clients . infrastructure . api . security Ċ Ċ import Ġes . ur jc . real food . clients . infrastructure . api . security . filters . JWT Authentication Filter Ċ import Ġes . ur jc . real food . clients . infrastructure . api . security . filters . JWT Authorization Filter Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . http . HttpMethod Ċ import Ġorg . springframework . security . config . annotation . authentication . builders . Authentication Manager Builder Ċ import Ġorg . springframework . security . config . annotation . web . builders . Http Security Ċ import Ġorg . springframework . security . config . annotation . web . configuration . Enable Web Security Ċ import Ġorg . springframework . security . config . annotation . web . configuration . Web Security Configurer Adapter Ċ import Ġorg . springframework . security . config . http . Session Creation Policy Ċ import Ġorg . springframework . security . crypto . bcrypt . BC rypt Password Encoder Ċ import Ġorg . springframework . web . cors . Cors Configuration Ċ import Ġorg . springframework . web . cors . Cors Configuration Source Ċ import Ġorg . springframework . web . cors . Url Based Cors Configuration Source Ċ Ċ @ Configuration Ċ @ Enable Web Security Ċ class ĠWeb Security Config ( ĊĠĠĠ Ġ@ Value ("\ ${ jwt . secret }") Ġprivate Ġval Ġtoken Secret : ĠString , ĊĠĠĠ Ġprivate Ġval ĠuserService : ĠSpring UserService Ċ ) Ġ: ĠWeb Security Configurer Adapter () Ġ{ ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġcors Configuration Source (): ĠC ors Configuration Source Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsource Ġ= ĠUrl Based Cors Configuration Source () ĊĠĠĠĠĠĠĠ Ġsource . register Cors Configuration (" /** ", ĠC ors Configuration (). apply Permit Default Values ()) ĊĠĠĠĠĠĠĠ Ġreturn Ġsource ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġconfigure ( http : ĠHttp Security ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhttp ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. session Management (). session Creation Policy ( Session Creation Policy . STATE LESS ). and () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. cors (). and (). csrf (). disable () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. authorize Requests () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ( HttpMethod . POST , ĠREG ISTER _ ENDPOINT ). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ( HttpMethod . POST , ĠLOGIN _ ENDPOINT ). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ("/ swagger - ui /** "). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ("/ v 3 / api - docs /** "). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ("/ act uator / health "). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. any Request (). authenticated (). and () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Filter ( JWT Authentication Filter ( authentication Manager (), Ġtoken Secret )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Filter ( JWT Authorization Filter ( authentication Manager (), Ġtoken Secret )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġb Crypt Password Encoder () Ġ= ĠBC rypt Password Encoder () ĊĊĠĠĠ Ġoverride Ġfun Ġconfigure ( auth : ĠAuthentication Manager Builder ) Ġ{ ĊĠĠĠĠĠĠĠ Ġauth . user Details Service ( userService ). password Encoder ( b Crypt Password Encoder ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠLOGIN _ ENDPOINT Ġ= Ġ"/ api / sign - in " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠREG ISTER _ ENDPOINT Ġ= Ġ"/ api / clients " ĊĠĠĠ Ġ} Ċ Ċ } Ċ