Skip to content

Commit

Permalink
feat: 调整filter加载机制
Browse files Browse the repository at this point in the history
  • Loading branch information
TsukasaHwan committed Jul 11, 2024
1 parent 840926f commit 1cb9f37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.properties.SpringDocConfigProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -51,10 +52,10 @@
@EnableConfigurationProperties({Knife4jProperties.class, Knife4jSetting.class, Knife4jHttpBasic.class})
@ConditionalOnProperty(name = "knife4j.enable", havingValue = "true")
public class Knife4jAutoConfiguration {

private final Knife4jProperties properties;
private final Environment environment;

/**
* 增强自定义配置
* @return
Expand All @@ -65,7 +66,7 @@ public Knife4jOpenApiCustomizer knife4jOpenApiCustomizer(SpringDocConfigProperti
log.debug("Register Knife4jOpenApiCustomizer");
return new Knife4jOpenApiCustomizer(this.properties, docProperties);
}

@Bean
@ConditionalOnMissingBean
public Knife4jJakartaOperationCustomizer knife4jJakartaOperationCustomizer() {
Expand Down Expand Up @@ -93,15 +94,15 @@ public CorsFilter corsFilter() {
CorsFilter corsFilter = new CorsFilter(source);
return corsFilter;
}

/**
* Security with Basic Http
* @param knife4jProperties Basic Properties
* @return BasicAuthFilter
*/
@Bean
@ConditionalOnMissingBean(JakartaServletSecurityBasicAuthFilter.class)
@ConditionalOnProperty(name = "knife4j.basic.enable", havingValue = "true")
@ConditionalOnExpression("${knife4j.production:false} && ${knife4j.basic.enable:true}")
public FilterRegistrationBean<JakartaServletSecurityBasicAuthFilter> securityBasicAuthFilter(Knife4jProperties knife4jProperties) {
JakartaServletSecurityBasicAuthFilter authFilter = new JakartaServletSecurityBasicAuthFilter();
if (knife4jProperties == null) {
Expand All @@ -127,7 +128,7 @@ public FilterRegistrationBean<JakartaServletSecurityBasicAuthFilter> securityBas
registration.setOrder(AbstractSecurityFilter.SPRING_FILTER_ORDER);
return registration;
}

@Bean
@ConditionalOnMissingBean(JakartaProductionSecurityFilter.class)
@ConditionalOnProperty(name = "knife4j.production", havingValue = "true")
Expand All @@ -152,5 +153,5 @@ public FilterRegistrationBean<JakartaProductionSecurityFilter> productionSecurit
registration.setOrder(AbstractSecurityFilter.SPRING_FILTER_ORDER - 1);
return registration;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.LoggerFactory;
import org.springdoc.core.SpringDocConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down Expand Up @@ -105,7 +106,7 @@ public CorsFilter corsFilter() {
*/
@Bean
@ConditionalOnMissingBean(ServletSecurityBasicAuthFilter.class)
@ConditionalOnProperty(name = "knife4j.basic.enable", havingValue = "true")
@ConditionalOnExpression("${knife4j.production:false} && ${knife4j.basic.enable:true}")
public FilterRegistrationBean<ServletSecurityBasicAuthFilter> securityBasicAuthFilter(Knife4jProperties knife4jProperties) {
ServletSecurityBasicAuthFilter authFilter = new ServletSecurityBasicAuthFilter();
if (knife4jProperties == null) {
Expand Down

0 comments on commit 1cb9f37

Please sign in to comment.