【发布时间】:2021-04-07 00:10:59
【问题描述】:
我有使用 spring-boot 的招摇 UI。我的 spring rest api 有一个无状态身份验证设置,它根据每个 api 路径的角色进行限制。
但是,我不确定如何将<server_url>/swagger-ui.html 放在基本身份验证后面。
更新
我通过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);
}
【问题讨论】:
-
通常值得包括您当前如何定义安全性,以便人们可以提供适合您设置的解决方案。有很多方法可以做到这一点,但了解更多关于您的实施会有所帮助。
-
更新了我的问题
标签: spring security spring-boot swagger-ui swagger-2.0