فهرست منبع

config: 放行访问doc文档权限

370774330@qq.com 5 سال پیش
والد
کامیت
b0f6cd4683
1فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 15 4
      web/src/main/java/seecoder/devcloud/web/infrastructure/config/WebSecurityConfig.java

+ 15 - 4
web/src/main/java/seecoder/devcloud/web/infrastructure/config/WebSecurityConfig.java

@@ -54,13 +54,24 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     @Override
     protected void configure(HttpSecurity http) throws Exception {
         //访问控制
-        http.authorizeRequests()
+        http
+                //访问swagger
+                .anonymous()
+                .authorities("ROLE_ANONYMOUS").and()
+                .authorizeRequests()
+                .antMatchers("/**/*swagger*/**").permitAll()
+                .antMatchers("/**/*api-docs*/**").permitAll()
+                .and()
+                .authorizeRequests()
                 //跨域的Options请求进行放行
                 .requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
-                //其他所有接口都要在登陆认证状态下请求
-                .anyRequest().authenticated()
                 //todo 具体角色权限配置等开发完成之后再配, 这里先配为默认所有权限
-                .antMatchers("/**").hasAnyRole(WebSecurityConstants.STUDENT_ROLE, WebSecurityConstants.ADMIN_ROLE);
+                .antMatchers("/**").hasAnyRole(WebSecurityConstants.STUDENT_ROLE, WebSecurityConstants.ADMIN_ROLE)
+                //其他所有接口都要在登陆认证状态下请求
+                .anyRequest().authenticated();
+
+
+
 
         //开启跨域
         http.cors();