package com.ruoyi.common.security.config;

import com.ruoyi.common.security.interceptor.FebsServerProtectInterceptor;
import com.ruoyi.common.security.properties.FebsCloudSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author MrBird
 */
public class FebsCloudSecurityInteceptorConfigure implements WebMvcConfigurer {

    private FebsCloudSecurityProperties properties;

    @Autowired
    public void setProperties(FebsCloudSecurityProperties properties) {
        this.properties = properties;
    }

    @Bean
    public HandlerInterceptor febsServerProtectInterceptor() {
        FebsServerProtectInterceptor febsServerProtectInterceptor = new FebsServerProtectInterceptor();
        febsServerProtectInterceptor.setProperties(properties);
        return febsServerProtectInterceptor;
    }

    @Override
    @SuppressWarnings("all")
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(febsServerProtectInterceptor());
    }
}
