package com.schisandra.oss.application.config;

import com.cxytiandi.encrypt.core.EncryptionConfig;
import com.cxytiandi.encrypt.core.EncryptionFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.Collections;

/**
 * @Classname EncryptFilterConfig
 * @BelongsProject: schisandra-cloud-storage
 * @BelongsPackage: com.schisandra.oss.application.config
 * @Author: landaiqing
 * @CreateTime: 2024-05-22  21:46
 * @Description: TODO
 * @Version: 1.0
 */
@Configuration
public class EncryptFilterConfig {
    @Bean
    public FilterRegistrationBean<EncryptionFilter> filterRegistration() {
        EncryptionConfig config = new EncryptionConfig();
        config.setKey("d86d7bab3d6ac01ad9dc6a897652f2d2");//1.2版本及以下key 16位，1.2以上key 32位
        config.setRequestDecryptUriList(Collections.emptyList());
        config.setResponseCharset("UTF-8");
        config.setDebug(true);
        config.setResponseEncryptUriList(Collections.singletonList("/oss/minio/getAllMinioInfo"));
        FilterRegistrationBean<EncryptionFilter> registration = new FilterRegistrationBean<EncryptionFilter>();
        registration.setFilter(new EncryptionFilter(config));
        registration.addUrlPatterns("/*");
        registration.setName("EncryptionFilter");
        registration.setOrder(1);
        return registration;
    }
}
