package com.maintain.common.helper;

import com.maintain.common.core.domain.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 自定义积木报表鉴权(如果不进行自定义，则所有请求不做权限控制)
 *  * 1.自定义获取登录token
 *  * 2.自定义获取登录用户
 * @author: jeecg-boot
 */


@Slf4j
@Component
public class JimuReportTokenService implements JmReportTokenServiceI {


    @Override
    public String getUsername(String s) {
        System.out.println("---------call---------getUsername-----------------------");
        return "";
    }

    /**
     * 自定义获取TOKEN
     * @param request
     * @return
     */
    @Override
    public String getToken(HttpServletRequest request) {
        System.out.println("---------call---------getToken-----------------------");
        return request.getHeader("token");
    }
    /**
     * Token校验
     * @param token
     * @return
     */
    @Override
    public Boolean verifyToken(String token) {
        System.out.println("---------verify-----Token---------------");
        System.out.println(token);
        return true;
    }

    /**
     * 自定义用户拥有的角色
     *
     * @param token
     * @return
     */
    @Override
    public String[] getRoles(String token) {
        System.out.println("---------call---------getRoles-----------------------");
        return new String[]{"admin","lowdeveloper","dbadeveloper"};
    }

    /**
     * 自定义用户拥有的权限指令
     *
     * @param token
     * @return
     */
    @Override
    public String[] getPermissions(String token) {
        System.out.println("---------call---------getPermissions-----------------------");
        return new String[]{"drag:datasource:testConnection","onl:drag:clear:recovery","drag:analysis:sql","drag:design:getTotalData"};
    }
}
