package org.nl.config.saconfig;

import cn.dev33.satoken.config.SaSsoConfig;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ModelAndView;

/*
 * @author ZZQ
 * @Date 2022/11/28 10:58 上午
 */
@Configuration
public class SaInitCOnfig {

    @Autowired
    LoginUserHandler loginUserHandler;

    @Autowired
    public void configSso(SaSsoConfig sso) {
        System.out.println("启动初始化-----SaSsoConfig");
        // 配置：未登录时返回的View
        sso.setNotLoginView(() -> new ModelAndView("sa-login"));
        // 配置：登录处理函数
        sso.setDoLoginHandle(loginUserHandler);

        sso.setSendHttp(s -> {
            HttpResponse execute = HttpRequest.get(s).execute();
            return execute.body();
        });
    }
}
