package Ġpl . m ich ally sak . on lines hop . config Ċ Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . security . authentication . Authentication Manager Ċ import Ġorg . springframework . security . config . annotation . authentication . builders . Authentication Manager Builder Ċ import Ġorg . springframework . security . config . annotation . method . configuration . Enable Global Method Security Ċ 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 . security . web . authentication . Username Password Authentication Filter Ċ 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 Ċ import Ġpl . m ich ally sak . on lines hop . config . filters . Authentication Filter Ċ import Ġpl . m ich ally sak . on lines hop . config . filters . Authorization Filter Ċ import Ġpl . m ich ally sak . on lines hop . services . user . UserService Ċ import Ġpl . m ich ally sak . on lines hop . util . jwt . Jwt Util ĊĊ Ċ @ Configuration Ċ @ Enable Web Security Ċ @ Enable Global Method Security ( pre Post Enabled Ġ= Ġtrue ) Ċ class ĠWeb Security Config Ġ@ Autowired Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġjwt Util : ĠJwt Util , ĊĠĠĠ Ġprivate Ġval ĠuserService : ĠUserService Ċ ) Ġ: ĠWeb Security Configurer Adapter () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġno Auth Required Endpoints Ġ= ĠarrayOf ( ĊĠĠĠĠĠĠĠ Ġ"/ api / auth / registration ", ĊĠĠĠĠĠĠĠ Ġ"/ api / auth / login ", ĊĠĠĠĠĠĠĠ Ġ"/ api / auth / activate /** ", ĊĠĠĠĠĠĠĠ Ġ"/ api / auth / token / refresh " ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġval Ġauthentication Filter Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠAuthentication Filter ( jwt Util , Ġauthentication Manager Bean ()). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Filter Processes Url ("/ api / auth / login ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġauthorization Filter Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠAuthorization Filter ( jwt Util , Ġno Auth Required Endpoints ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġconfigure ( http : ĠHttp Security ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhttp . cors () ĊĠĠĠĠĠĠĠ Ġhttp . csrf (). disable () ĊĠĠĠĠĠĠĠ Ġhttp . session Management (). session Creation Policy ( Session Creation Policy . STATE LESS ) ĊĊĠĠĠĠĠĠĠ Ġhttp . authorize Requests () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers (* no Auth Required Endpoints ). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. any Request (). authenticated () ĊĊĠĠĠĠĠĠĠ Ġhttp ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Filter Before ( authorization Filter , ĠUsername Password Authentication Filter :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Filter ( authentication Filter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġcors Configuration Source (): ĠC ors Configuration Source ? Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= ĠC ors Configuration (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġallowed Origin Patterns Ġ= ĠlistOf ("* ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġallowed Methods Ġ= ĠlistOf (" GET ", Ġ" POST ", Ġ" PUT ", Ġ" PATCH ", Ġ" DELETE ", Ġ" OPTIONS ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġallowed Headers Ġ= ĠlistOf ("* ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġallow Credentials Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġsource Ġ= ĠUrl Based Cors Configuration Source (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġregister Cors Configuration (" /** ", Ġconfiguration ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġsource ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġpassword Encoder () Ġ= ĠBC rypt Password Encoder () ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġoverride Ġfun Ġauthentication Manager Bean (): ĠAuthentication Manager Ġ= Ġsuper . authentication Manager Bean () ĊĊĠĠĠ Ġoverride Ġfun Ġconfigure ( auth : ĠAuthentication Manager Builder ) Ġ{ ĊĠĠĠĠĠĠĠ Ġauth ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. user Details Service ( userService ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. password Encoder ( password Encoder ()) ĊĠĠĠ Ġ} Ċ Ċ } Ċ