All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.macrocloud.kernel.security.config.SecureConfiguration Maven / Gradle / Ivy

There is a newer version: 1.1.0-RELEASE
Show newest version
package org.macrocloud.kernel.security.config;


import lombok.AllArgsConstructor;
import org.macrocloud.kernel.security.handler.ISecureHandler;
import org.macrocloud.kernel.security.props.MacroSecureProperties;
import org.macrocloud.kernel.security.provider.ClientDetailsServiceImpl;
import org.macrocloud.kernel.security.provider.IClientDetailsService;
import org.macrocloud.kernel.security.registry.SecureRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 安全配置类
 *
 */
@Order
@Configuration
@AllArgsConstructor
@EnableConfigurationProperties({MacroSecureProperties.class})
public class SecureConfiguration implements WebMvcConfigurer {

    private final SecureRegistry secureRegistry;

    private final MacroSecureProperties secureProperties;

    private final JdbcTemplate jdbcTemplate;

    private final ISecureHandler secureHandler;

    @Override
    public void addInterceptors(@NonNull InterceptorRegistry registry) {
        if (secureRegistry.isEnabled() || secureProperties.getEnabled()) {
            registry.addInterceptor(secureHandler.tokenInterceptor())
                    .excludePathPatterns(secureRegistry.getExcludePatterns())
                    .excludePathPatterns(secureRegistry.getDefaultExcludePatterns())
                    .excludePathPatterns(secureProperties.getSkipUrl());
        }
    }


    @Bean
    @ConditionalOnMissingBean(IClientDetailsService.class)
    public IClientDetailsService clientDetailsService() {
        return new ClientDetailsServiceImpl(jdbcTemplate);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy