package com.ningdatech.kqapi.security;

import com.ningdatech.basic.factory.PropertySourceFactory;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * AuthProperties
 * </p>
 *
 * @author WendyYang
 * @since 11:15 2024/4/20
 */
@Configuration
@PropertySource(value = "classpath:security/auth-${spring.profiles.active}.yml"
        , encoding = "utf-8", factory = PropertySourceFactory.class)
@ConfigurationProperties(prefix = "security.auth")
@Component
@Data
public class AuthProperties {

    private Boolean postOnlyByLogin = true;

    private String authRequireUrl;

    private String invalidSessionUrl;

    private String passwordLoginUrl;

    private String logoutUrl;

    private List<String> ignoreAuthUrls;

    private List<String> ignoreCsrfUrls;

    private Map<String, List<String>> roleMap = new HashMap<>();

    public String[] getIgnoreAuthUrlsArray() {
        String[] stringArray = new String[ignoreAuthUrls.size()];
        return ignoreAuthUrls.toArray(stringArray);
    }

    public String[] getIgnoreCsrfUrlsArray() {
        String[] stringArray = new String[ignoreCsrfUrls.size()];
        return ignoreCsrfUrls.toArray(stringArray);
    }

}
