package Ġcom . gn ir ps . keycloak . config Ċ Ċ import Ġcom . gn ir ps . keycloak . config . properties . Key cloak Properties Ċ import Ġorg . keycloak . adapters . spring security . Key cloak Security Components Ċ import Ġorg . keycloak . adapters . spring security . authentication . Key cloak Authentication Provider Ċ import Ġorg . keycloak . adapters . spring security . client . Key cloak Client Request Factory Ċ import Ġorg . keycloak . adapters . spring security . client . Key cloak Rest Template Ċ import Ġorg . keycloak . adapters . spring security . config . Key cloak Web Security Configurer Adapter Ċ import Ġorg . keycloak . adapters . spring security . filter . Key cloak Authentication Processing Filter Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . beans . factory . config . Configurable BeanFactory Ċ import Ġorg . springframework . boot . context . properties . Configuration Properties Scan Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Component Scan Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . context . annotation . Scope Ċ import Ġorg . springframework . http . HttpMethod Ċ 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 . builders . Web Security Ċ import Ġorg . springframework . security . config . annotation . web . configuration . Enable Web Security Ċ import Ġorg . springframework . security . core . authority . mapping . Simple Authority Mapper Ċ import Ġorg . springframework . security . core . session . Session Registry Impl Ċ import Ġorg . springframework . security . web . authentication . session . Register Session Authentication Strategy Ċ import Ġorg . springframework . security . web . authentication . session . Session Authentication Strategy Ċ import Ġorg . springframework . security . web . util . matcher . And Request Matcher Ċ import Ġorg . springframework . security . web . util . matcher . Ant Path Request Matcher Ċ import Ġorg . springframework . security . web . util . matcher . Neg ated Request Matcher ĊĊ Ċ @ Configuration Ċ @ Enable Web Security Ċ @ Enable Global Method Security ( pre Post Enabled Ġ= Ġtrue , Ġsec ured Enabled Ġ= Ġtrue , Ġjsr 2 5 0 Enabled Ġ= Ġtrue ) Ċ @ Component Scan ( base Package Classes Ġ= Ġ[ Key cloak Security Components :: class ]) Ċ @ Configuration Properties Scan ( base Package Classes Ġ= Ġ[ Key cloak Properties :: class ]) Ċ class ĠKey cloak Configurer Adapter ( ĊĠĠĠ Ġprivate Ġval Ġkey cloak Properties : ĠKey cloak Properties , ĊĠĠĠ Ġprivate Ġval Ġkey cloak Client Request Factory : ĠKey cloak Client Request Factory , ĊĠĠĠ Ġprivate Ġval Ġauthentication Failure Handler : ĠCustom Authentication Failure Handler , ĊĠĠĠ Ġprivate Ġval Ġcustom Access Denied Handler : ĠCustom Access Denied Handler , Ċ ) Ġ: ĠKey cloak Web Security Configurer Adapter () Ġ{ ĊĠĠĠ Ġ// Ġhandle Ġthe Ġprefix ĠROLE _ ĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġconfigure Global ( auth : ĠAuthentication Manager Builder ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey cloak Authentication Provider : ĠKey cloak Authentication Provider Ġ= Ġkey cloak Authentication Provider () ĊĠĠĠĠĠĠĠ Ġkey cloak Authentication Provider . set Granted Author ities Mapper ( Simple Authority Mapper ()) ĊĠĠĠĠĠĠĠ Ġauth . authentication Provider ( keycloak Authentication Provider ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġ@ Scope ( Configurable BeanFactory . SCOPE _ PRO TOT YPE ) ĊĠĠĠ Ġfun Ġkey cloak Rest Template (): ĠKey cloak Rest Template Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠKey cloak Rest Template ( keycloak Client Request Factory ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġoverride Ġfun Ġsession Authentication Strategy (): ĠSession Authentication Strategy Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠRegister Session Authentication Strategy ( Session Registry Impl ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠIgnore Ġauthentication Ġfor Ġsome Ġurls Ġat Ġthe Ġ" Spring ĠSecurity " Ġlevel ĊĠĠĠĠ Ġ* Ġ@ param Ġweb ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġoverride Ġfun Ġconfigure ( web : ĠWeb Security ) Ġ{ ĊĠĠĠĠĠĠĠ Ġweb . ign oring (). ant Matchers ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpMethod . GET , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ* keycloak Properties . resources . to Typed Array () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġweb . ign oring (). ant Matchers ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpMethod . GET , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ* keycloak Properties . endpoints . un secure Get . to Typed Array () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġweb . ign oring (). ant Matchers ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpMethod . POST , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ* keycloak Properties . endpoints . un secure Post . to Typed Array () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġweb . ign oring (). ant Matchers ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpMethod . PUT , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ* keycloak Properties . endpoints . un secure Put . to Typed Array () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġweb . ign oring (). ant Matchers ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpMethod . DELETE , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ* keycloak Properties . endpoints . un secure Delete . to Typed Array () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠIgnore Ġauthentication Ġfor Ġsome Ġurls Ġat Ġthe Ġ" Key cloak " Ġlevel ĊĠĠĠĠ Ġ* Ġ@ param Ġweb ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġ@ Throws ( java . lang . Exception :: class ) ĊĠĠĠ Ġoverride Ġfun Ġkey cloak Authentication Processing Filter (): ĠKey cloak Authentication Processing Filter ? Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexcluded Routes Ġ= Ġmutable ListOf < Neg ated Request Matcher >() ĊĠĠĠĠĠĠĠ Ġfor Ġ( url Ġin Ġkey cloak Properties . resources ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexcluded Routes . add ( Neg ated Request Matcher ( Ant Path Request Matcher ( url , ĠHttpMethod . GET . toString ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfor Ġ( url Ġin Ġkey cloak Properties . endpoints . un secure Get ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexcluded Routes . add ( Neg ated Request Matcher ( Ant Path Request Matcher ( url , ĠHttpMethod . GET . toString ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfor Ġ( url Ġin Ġkey cloak Properties . endpoints . un secure Post ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexcluded Routes . add ( Neg ated Request Matcher ( Ant Path Request Matcher ( url , ĠHttpMethod . POST . toString ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfor Ġ( url Ġin Ġkey cloak Properties . endpoints . un secure Put ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexcluded Routes . add ( Neg ated Request Matcher ( Ant Path Request Matcher ( url , ĠHttpMethod . PUT . toString ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfor Ġ( url Ġin Ġkey cloak Properties . endpoints . un secure Delete ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexcluded Routes . add ( Neg ated Request Matcher ( Ant Path Request Matcher ( url , ĠHttpMethod . DELETE . toString ()))) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġfilter Ġ= ĠKey cloak Authentication Processing Filter ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġauthentication Manager Bean (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAnd Request Matcher ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠKey cloak Authentication Processing Filter . DEFAULT _ REQUEST _ MATCH ER , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ* excluded Routes . to Typed Array () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġfilter . set Session Authentication Strategy ( session Authentication Strategy ()) ĊĠĠĠĠĠĠĠ Ġreturn Ġfilter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġoverride Ġfun Ġconfigure ( http : ĠHttp Security ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . configure ( http ) ĊĠĠĠĠĠĠĠ Ġhttp ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exception Handling () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. access Denied Handler ( custom Access Denied Handler ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. and (). cors () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. and (). csrf (). disable () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. authorize Requests () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. ant Matchers ( HttpMethod . OPTIONS ). permit All () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. any Request (). authenticated () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. and (). form Login (). failure Handler ( authentication Failure Handler ) ĊĠĠĠ Ġ} Ċ } Ċ