org.zodiac.autoconfigure.security.http.reactive.SecurityHttpReactiveAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.security.http.reactive;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.zodiac.autoconfigure.security.condition.ConditionalOnSecurityHttpEnabled;
import org.zodiac.autoconfigure.security.http.SecurityHttpProperties;
import org.zodiac.autoconfigure.security.jwt.SecurityJwtProperties;
@Order
@SpringBootConfiguration
@ConditionalOnSecurityHttpEnabled
@ConditionalOnWebApplication(type = Type.REACTIVE)
//@AutoConfigureAfter(value = {SecurityJwtAutoConfiguration.class})
@ConditionalOnClass(value = {org.zodiac.security.auth.SecurityAuthAspect.class, org.zodiac.security.jwt.config.SecurityJwtInfo.class})
public class SecurityHttpReactiveAutoConfiguration implements WebFluxConfigurer {
private final org.zodiac.security.registry.SecurityRegistry securityRegistry;
private final org.zodiac.security.http.reactive.ReactiveSecurityHandler reactiveSecurityHandler;
private final SecurityJwtProperties securityJwtProperties;
private final SecurityHttpProperties securityHttpProperties;
public SecurityHttpReactiveAutoConfiguration(org.zodiac.security.registry.SecurityRegistry securityRegistry,
org.zodiac.security.http.reactive.ReactiveSecurityHandler reactiveSecurityHandler,
SecurityJwtProperties securityJwtProperties, SecurityHttpProperties securityHttpProperties) {
this.securityRegistry = securityRegistry;
this.reactiveSecurityHandler = reactiveSecurityHandler;
this.securityJwtProperties = securityJwtProperties;
this.securityHttpProperties = securityHttpProperties;
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = org.zodiac.security.constants.SecuritySystemPropertiesConstants.SPRING_SECURITY_HTTP_AUTH_ENABLED, havingValue = "true", matchIfMissing = true)
protected org.zodiac.security.http.reactive.interceptor.AuthInterceptor authInterceptor() {
return new org.zodiac.security.http.reactive.interceptor.AuthInterceptor(securityRegistry, securityHttpProperties);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = org.zodiac.security.constants.SecuritySystemPropertiesConstants.SPRING_SECURITY_HTTP_BASIC_ENABLED, havingValue = "true", matchIfMissing = true)
protected org.zodiac.security.http.reactive.interceptor.BasicInterceptor basicInterceptor() {
return new org.zodiac.security.http.reactive.interceptor.BasicInterceptor(securityRegistry, securityHttpProperties);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = org.zodiac.security.constants.SecuritySystemPropertiesConstants.SPRING_SECURITY_HTTP_SIGN_ENABLED, havingValue = "true", matchIfMissing = true)
protected org.zodiac.security.http.reactive.interceptor.SignInterceptor signInterceptor() {
return new org.zodiac.security.http.reactive.interceptor.SignInterceptor(securityRegistry, securityHttpProperties);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = org.zodiac.security.constants.SecuritySystemPropertiesConstants.SPRING_SECURITY_HTTP_CLIENT_ENABLED, havingValue = "true", matchIfMissing = true)
protected org.zodiac.security.http.reactive.interceptor.ClientInterceptor clientInterceptor() {
return new org.zodiac.security.http.reactive.interceptor.ClientInterceptor(securityRegistry, securityHttpProperties);
}
@Bean
@ConditionalOnMissingBean
protected org.zodiac.security.http.reactive.interceptor.TokenInterceptor tokenInterceptor() {
return new org.zodiac.security.http.reactive.interceptor.TokenInterceptor(securityRegistry, securityHttpProperties);
}
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// /*设置请求授权*/
// if (securityRegistry.isAuthEnabled() || securityHttpProperties.isAuthEnabled()) {
// List authSecures =
// this.securityRegistry.addAuthPatterns(securityHttpProperties.getAuth()).getAuthSecures();
// if (authSecures.size() > 0) {
// registry.addInterceptor(securityServletHandler.authInterceptor(authSecures));
// /*设置路径放行*/
// securityRegistry
// .excludePathPatterns(authSecures.stream().map(org.zodiac.security.http.AuthSecure::getPattern).collect(Collectors.toList()));
// }
// }
// /*设置基础认证授权*/
// if (securityRegistry.isBasicEnabled() || securityHttpProperties.isBasicEnabled()) {
// List basicSecures =
// this.securityRegistry.addBasicPatterns(securityHttpProperties.getBasic()).getBasicSecures();
// if (basicSecures.size() > 0) {
// registry.addInterceptor(securityServletHandler.basicInterceptor(basicSecures));
// /**/
// securityRegistry.excludePathPatterns(
// basicSecures.stream().map(org.zodiac.security.http.BasicSecure::getPattern).collect(Collectors.toList()));
// }
// }
// /*设置签名认证授权*/
// if (securityRegistry.isSignEnabled() || securityHttpProperties.isSignEnabled()) {
// List signSecures =
// this.securityRegistry.addSignPatterns(securityHttpProperties.getSign()).getSignSecures();
// if (signSecures.size() > 0) {
// registry.addInterceptor(securityServletHandler.signInterceptor(signSecures));
// /*设置路径放行*/
// securityRegistry
// .excludePathPatterns(signSecures.stream().map(org.zodiac.security.http.SignSecure::getPattern).collect(Collectors.toList()));
// }
// }
// /*设置客户端授权*/
// if (securityRegistry.isClientEnabled() || securityHttpProperties.isClientEnabled()) {
// securityHttpProperties.getClient().forEach(
// clientSecure -> registry.addInterceptor(securityServletHandler.clientInterceptor(clientSecure.getClientId()))
// .addPathPatterns(clientSecure.getPathPatterns()));
// }
// /*设置路径放行*/
// if (securityRegistry.isEnabled() || securityHttpProperties.isEnabled()) {
// registry.addInterceptor(securityServletHandler.tokenInterceptor())
// .excludePathPatterns(securityRegistry.getExcludePatterns())
// .excludePathPatterns(securityRegistry.getDefaultExcludePatterns())
// .excludePathPatterns(securityHttpProperties.getSkipUrl());
// }
// }
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(value = {org.springframework.cache.CacheManager.class})
protected org.zodiac.security.SecurityCacheOperations securityCacheOperations(org.springframework.cache.CacheManager cacheManager) {
return new org.zodiac.security.http.reactive.ReactiveSecurityCacheTemplate(cacheManager);
}
@Bean
@ConditionalOnMissingBean(value = org.zodiac.security.SecurityAuthOperations.class)
protected org.zodiac.security.SecurityAuthOperations securityAuthOperations() {
return new org.zodiac.security.http.reactive.ReactiveSecurityAuthTemplate(securityJwtProperties);
}
@Bean
@ConditionalOnMissingBean(value = org.zodiac.security.SecurityAuthOperations2.class)
protected org.zodiac.security.SecurityAuthOperations2 securityAuthOperations2() {
return new org.zodiac.security.http.reactive.ReactiveSecurityAuthTemplate2(securityJwtProperties);
}
@Bean
@ConditionalOnMissingBean(value = org.zodiac.security.SecurityOperations.class)
protected org.zodiac.security.SecurityOperations securityOperations(org.zodiac.security.SecurityClientDetailsService securityClientDetailsService) {
return new org.zodiac.security.http.reactive.ReactiveSecurityTemplate(securityClientDetailsService, securityJwtProperties);
}
}