
package com.tmerclub.cloud.common.security.adapter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author tmerclub
 * @date 2020/7/16
 */
public class DefaultAuthConfigAdapter implements AuthConfigAdapter {

    static final Set<String> SET;

    static {
        SET = new CopyOnWriteArraySet<>();
        SET.add(EXTERNAL_URI);
        SET.add(DOC_URI);
        // 容器存活检查探针、容器就绪检查探针
        SET.add("/actuator/health/liveness");
        SET.add("/actuator/health/readiness");
        // 生成jsapi签名接口不需要授权
        SET.add("/wx/jsapi/createJsapiSignature");
        SET.add("/admin/**/**");
        SET.add("/app/**/**");
        SET.add("/mp/**/**");
    }

    private static final Logger logger = LoggerFactory.getLogger(DefaultAuthConfigAdapter.class);

    public DefaultAuthConfigAdapter() {
        logger.info("not implement other AuthConfigAdapter, use DefaultAuthConfigAdapter... all url need auth...");
    }


    @Override
    public List<String> pathPatterns() {
        return Collections.singletonList("/*");
    }

    @Override
    public Set<String> excludePathPatterns(String... paths) {
        if (paths.length == 0) {
            return SET;
        }
        SET.addAll(Arrays.asList(paths));
        return SET;
    }
}
