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

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -