com.itxiaoer.commons.security.JwtAuthenticationEntryPoint Maven / Gradle / Ivy
package com.itxiaoer.commons.security;
import com.itxiaoer.commons.core.json.JsonUtil;
import com.itxiaoer.commons.core.page.Response;
import com.itxiaoer.commons.core.page.ResponseCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
/**
* 拦截没有权限
*
* @author : liuyk
*/
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
private static final long serialVersionUID = -8970718410437077606L;
@Override
public void commence(HttpServletRequest request,
HttpServletResponse response,
AuthenticationException authException) throws IOException {
response.setContentType("application/json;charset=UTF-8");
Response res = Response.failure(ResponseCode.USER_NO_PERMISSION);
response.getWriter().write(JsonUtil.toJson(res));
}
}