|
@@ -26,6 +26,8 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
* 自定义的 Spring Security 配置适配器实现
|
|
@@ -62,14 +64,22 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap
|
|
|
@Resource
|
|
|
private JWTAuthenticationTokenFilter authenticationTokenFilter;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- * 自定义的权限映射 Bean
|
|
|
+ * 自定义的权限映射 Bean 们
|
|
|
*
|
|
|
* @see #configure(HttpSecurity)
|
|
|
*/
|
|
|
@Resource
|
|
|
- private Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry>
|
|
|
- authorizeRequestsCustomizer;
|
|
|
+ private List<AuthorizeRequestsCustomizer> authorizeRequestsCustomizers;
|
|
|
|
|
|
|
|
|
* 由于 Spring Security 创建 AuthenticationManager 对象时,没声明 @Bean 注解,导致无法被注入
|
|
@@ -126,44 +136,31 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap
|
|
|
StrUtil.equalsAny(request.getRequestURI(), buildAdminApi("/system/logout"),
|
|
|
buildAppApi("/member/logout")));
|
|
|
|
|
|
-
|
|
|
- httpSecurity.authorizeRequests()
|
|
|
-
|
|
|
- .antMatchers(buildAdminApi("/system/login"), buildAdminApi("/member/login")).anonymous()
|
|
|
+
|
|
|
+ httpSecurity
|
|
|
+
|
|
|
+ .authorizeRequests()
|
|
|
|
|
|
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
|
|
|
-
|
|
|
- .antMatchers(buildAdminApi("/infra/file/get/**")).anonymous()
|
|
|
-
|
|
|
- .antMatchers("/swagger-ui.html").anonymous()
|
|
|
- .antMatchers("/swagger-resources/**").anonymous()
|
|
|
- .antMatchers("/webjars/**").anonymous()
|
|
|
- .antMatchers("/*/api-docs").anonymous()
|
|
|
-
|
|
|
- .antMatchers("/actuator").anonymous()
|
|
|
- .antMatchers("/actuator/**").anonymous()
|
|
|
-
|
|
|
- .antMatchers("/druid/**").anonymous()
|
|
|
-
|
|
|
- .antMatchers(buildAdminApi("/auth2/login/**")).anonymous()
|
|
|
- .antMatchers(buildAdminApi("/auth2/authorization/**")).anonymous()
|
|
|
- .antMatchers("/api/callback/**").anonymous()
|
|
|
-
|
|
|
- .and().authorizeRequests(authorizeRequestsCustomizer)
|
|
|
-
|
|
|
- .authorizeRequests().anyRequest().authenticated()
|
|
|
+
|
|
|
+ .antMatchers(buildAppApi("/**")).permitAll()
|
|
|
+
|
|
|
+ .and().authorizeRequests(registry ->
|
|
|
+ authorizeRequestsCustomizers.forEach(customizer -> customizer.customize(registry)))
|
|
|
+
|
|
|
+ .authorizeRequests()
|
|
|
+ .anyRequest().authenticated()
|
|
|
;
|
|
|
+
|
|
|
|
|
|
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
|
|
}
|
|
|
|
|
|
private String buildAdminApi(String url) {
|
|
|
-
|
|
|
return webProperties.getAdminApi().getPrefix() + url;
|
|
|
}
|
|
|
|
|
|
private String buildAppApi(String url) {
|
|
|
-
|
|
|
return webProperties.getAppApi().getPrefix() + url;
|
|
|
}
|
|
|
|