Skip to content

Commit

Permalink
【功能优化】spring security:antMatchers 替换成 requestMatchers
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Oct 3, 2024
1 parent d63a2ae commit cc1c0b6
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;

/**
* Statistics 模块的 Security 配置
*/
@Configuration("statisticsSecurityConfiguration")
@Configuration("reportSecurityConfiguration")
public class SecurityConfiguration {

@Bean("statisticsAuthorizeRequestsCustomizer")
@Bean("reportAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {

@Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
// Swagger 接口文档
registry.antMatchers("/v3/api-docs/**").permitAll()
.antMatchers("/webjars/**").permitAll()
.antMatchers("/swagger-ui").permitAll()
.antMatchers("/swagger-ui/**").permitAll();
registry.requestMatchers("/v3/api-docs/**").permitAll()
.requestMatchers("/webjars/**").permitAll()
.requestMatchers("/swagger-ui").permitAll()
.requestMatchers("/swagger-ui/**").permitAll();
// Spring Boot Actuator 的安全配置
registry.antMatchers("/actuator").anonymous()
.antMatchers("/actuator/**").anonymous();
registry.requestMatchers("/actuator").permitAll()
.requestMatchers("/actuator/**").permitAll();
// Druid 监控
registry.antMatchers("/druid/**").anonymous();
registry.requestMatchers("/druid/**").permitAll();
// 积木报表
registry.requestMatchers("/jmreport/**").permitAll();
}

};
Expand Down

0 comments on commit cc1c0b6

Please sign in to comment.