package com.gkhy.safePlatform.config.security.customzie; import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 用来解决匿名用户访问无权限资源时的异常 */ @Component public class CustomizeAuthenticationEntryPoint extends JSONAuthentication implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest req, HttpServletResponse resp, AuthenticationException e) throws IOException, ServletException { ResultVO result = new ResultVO<>(ResultCodes.CLIENT_PERMISSION_NOT_ALLOW); this.writeJSON(req,resp,JSONObject.toJSONString(result)); } }