How to dynamically configure Httpsecurity in the Resource server using Spring security OAuth2 in Java? -
i new spring oauth 2. know how configure httpsecurity
in resource server dynamically using spring oauth 2.0. since have list of antmatchers
, scopes
stored in database (may in future antmatchers
, scopes
can added).
for single antmatchers
, scope
have tried below , worked expected:
@override public void configure(httpsecurity http) throws exception { http.authorizerequests() .antmatchers("/adminservice/") .access("#oauth2.hasscope('products')"); }
how should configure if there list of antmatchers
, scopes
stored in database such as:
**antmatchers** **scopes** /adminservice/ products /xxxx/ yyyy /yyyy/ xxxx /jkjlk/ uyuuy /klklk/ hjkskjk
here while spring booting want configure antmatchers
respective scope
database dynamically in resource server.
how can achieve this?
depending on database access mechanism autowire jdbctemplate, entityservice , do:
@override public void configure(httpsecurity http) throws exception { list<matcher> matchers=matchersservice.getall(); for(matcher m : matchers) { http.authorizerequests() .antmatchers(m.getmapping()) .access("#oauth2.hasscope('"+m.getscope()+"')"); } }
now solve configuration during startup. if want able dynamically change during runtime suggest restarting server if it's option.
Comments
Post a Comment