package com.reyun.saas.common.constants;

import java.util.*;

/**
 * 需要放开权限的url
 */
public final class PermitAllUrl {

    /**
     * 监控中心和swagger需要访问的url
     */
    private static final String[] ENDPOINTS = {"/actuator/health", "/actuator/env", "/actuator/metrics/**", "/actuator/trace", "/actuator/dump",
            "/actuator/jolokia", "/actuator/info", "/actuator/logfile", "/actuator/refresh", "/actuator/flyway", "/actuator/liquibase",
            "/actuator/heapdump", "/actuator/loggers", "/actuator/auditevents", "/actuator/env/PID", "/actuator/jolokia/**",
            "/v3/api-docs/**","/favicon.ico",
            "/actuator/**",
            "/*/v3/api-docs",
            "/swagger/api-docs",
            "/swagger-ui.html",
            "/*/swagger-ui.html",
            "/swagger-resources/**",
            "/swagger-resources/configuration/ui",//用来获取支持的动作
            "/swagger-resources",//用来获取api-docs的URI
            "/swagger-resources/configuration/security",//安全选项
            "/swaggerList",
            "/webjars/**",
            "/doc.html",
            "/druid/**",
            "/css/style.css",
            "/css/*",
            "/api/user/register",//用户注册
            "/api/user/oauth/login",//用户登录
            "/api/user/userInfo", //单点登录系统获取用户信息接口
            "/api/user/emailResetPwd",//忘记密码发送邮件接口
            "/api/user/test",//临时
            "/oauth/token",//security的默认接口
            "/index.html",
            "/static/**",
            "/api/health/**",
            "/"
    };

    /**
     * openAPI的接口
     */
    public static final Set<String> OPENAPIURL = new LinkedHashSet<String>(){{
        add("/openapi/cp/user/signup");//注册用户
        add("/openapi/cp/user/users");//用户列表
        add("/openapi/cp/app/create");//创建app
        add("/openapi/cp/app/apps");//app列表
        add("/openapi/cp/rta/updateIpWhiteList");//更新rta ip白名单
        add("/openapi/cp/rta/ipWhiteList");//查询rta ip白名单
    }};


    /**
     * 需要放开权限的url
     *
     * @param urls 自定义的url
     * @return 自定义的url和监控中心需要访问的url集合
     */
    public static String[] permitAllUrl(String... urls) {

        Set<String> url = new LinkedHashSet<>();
        List<String> endpoints = Arrays.asList(ENDPOINTS);
        url.addAll(endpoints);
        url.addAll(OPENAPIURL);

        if (urls == null || urls.length == 0) {
            return url.toArray(new String[url.size()]);
        }

        Collections.addAll(url, urls);

        return url.toArray(new String[url.size()]);
    }

}
