spring - Restrict access to Swager UI -


i have swagger ui working spring-boot. have stateless authentication setup spring rest api restricted based on roles every api path.

however, not sure how can put <server_url>/swagger-ui.html behind basic authentication.

update

i have following websecurity configured via websecurityconfig

@override protected void configure(httpsecurity httpsecurity) throws exception {     httpsecurity             .csrf().disable()             .exceptionhandling().authenticationentrypoint(unauthorizedhandler).and()             .sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless).and()             .authorizerequests()             .antmatchers("/sysadmin/**").hasrole("sysadmin")             .antmatchers("/admin/**").hasrole("admin")             .antmatchers("/siteadmin/**").hasrole("siteadmin")             .antmatchers("/api/**").hasrole("user")             .anyrequest().permitall();      // custom jwt based security filter     httpsecurity             .addfilterbefore(authenticationtokenfilterbean(), usernamepasswordauthenticationfilter.class);  } 

one suggestion without knowing more configuration question.

https://stackoverflow.com/a/24920752/1499549

with updated question details here example of can add:

@override protected void configure(httpsecurity httpsecurity) throws exception {     httpsecurity             .csrf().disable()             .exceptionhandling().authenticationentrypoint(unauthorizedhandler).and()             .sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless).and()             .authorizerequests()             .antmatchers("/sysadmin/**").hasrole("sysadmin")             .antmatchers("/admin/**").hasrole("admin")             .antmatchers("/siteadmin/**").hasrole("siteadmin")             .antmatchers("/api/**").hasrole("user")             // add specific swagger page security             .antmatchers("/swagger-ui.html").hasrole("user")             .anyrequest().permitall();      // custom jwt based security filter     httpsecurity             .addfilterbefore(authenticationtokenfilterbean(), usernamepasswordauthenticationfilter.class);  } 

the problem protects swagger ui page , not api specification loaded .json file ui page.

a better approach put swagger files under path can add antmatchers("/swagger/**").hasrole("user")


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -