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;

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

    /**
     * 功能描述: 未登陆状态返回值
     * @return ResultBean
     *                  
     *                       
     */
    @ResponseBody
    @ExceptionHandler(value = BodyAuthenticationException.class)
    public ResultBean<String> bodyAuthenticationException(){
        return new ResultBean<>(ResultEnum.UNAUTHORIZED);
    }

    /**
     * 功能描述: 无权访问返回值
     * @return ResultBean
     *                  
     *                       
     */
    @ResponseBody
    @ExceptionHandler(value = BodyAuthorizationException.class)
    public ResultBean<String> bodyAuthorizationException(){
        return new ResultBean<>(ResultEnum.FORBIDDEN);
    }

}
