package com.sptg.gateway.handler;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.security.exception.BodyAuthenticationException;
import com.sptg.common.security.exception.BodyAuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * title: SecurityExceptionHandler
 * package: com.sptg.gateway.handler
 * description: 权限异常拦截
 *
 *                  
 *                 
 */
@ControllerAdvice
public class SecurityExceptionHandler {

    /**
     * 功能描述: 未登陆状态返回值
     * @return ResultBean
     *                  
     *                       
     */
    @ResponseBody
    @ExceptionHandler(value = BodyAuthenticationException.class)
    public Map<String,Object> bodyAuthenticationException(){
        Map<String,Object> hashMap = new HashMap<>(2);
        hashMap.put("result_code", 3);
        hashMap.put("result_msg", "登录超时，请重新登录");
        return hashMap;
    }

    /**
     * 功能描述: 无权访问返回值
     * @return ResultBean
     *                  
     *                       
     */
    @ResponseBody
    @ExceptionHandler(value = BodyAuthorizationException.class)
    public Map<String,Object> bodyAuthorizationException(){
        Map<String,Object> hashMap = new HashMap<>(2);
        hashMap.put("result_code", 4);
        hashMap.put("result_msg", "无权限访问该功能，请联系管理员");
        return hashMap;
    }

}
