package com.ssyf.common.security.config;

import com.ssyf.common.core.util.MapUtil;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * swagger 路由控制
 *
 * @author huwei
 * @date 2023/11/5 14:31
 */
@Component
public class GlobalRequestConfig implements RequestConfig {
    @Override
    public List<String> math() {
        return Arrays.asList("/auth/**", "/auth/**", "/api/**");
    }

    @Override
    public List<String> notMath() {
        return Arrays.asList("/openapi","/test/**", "/share/**", "/doc.html", "/webjars/**", "/swagger-resources/**", "/*/api-docs"
                , "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/swagger**/**", "/v2/api-docs", "/v3/api-docs");
    }

    @Override
    public Map<String, String> responseHeader() {
        return MapUtil.builder()
                // 是否启用浏览器默认XSS防护： 0=禁用 | 1=启用 | 1; mode=block 启用, 并在检查到XSS攻击时，停止渲染页面
                .put("X-XSS-Protection", "1; mode=block")
                // 禁用浏览器内容嗅探
                .put("X-Content-Type-Options", "nosniff")
                //跨域
                .put("Access-Control-Allow-Origin", "*")
                .put("Access-Control-Allow-Methods", "*")
                .put("Access-Control-Allow-Headers", "*")
                .build();
    }

}
