| | |
| | | package com.xcong.excoin.configurations.security; |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.xcong.excoin.common.contants.AppContants; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import org.springframework.security.core.AuthenticationException; |
| | | import org.springframework.security.web.AuthenticationEntryPoint; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServlet; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | |
| | | |
| | | @Override |
| | | public void commence(HttpServletRequest httpServletRequest, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException { |
| | | Result result = Result.loginFail("fail"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | response.getWriter().write(new ObjectMapper().writeValueAsString(result)); |
| | | String timeOut = response.getHeader("TimeOut"); |
| | | if (AppContants.TIME_OUT.equals(timeOut)) { |
| | | Result result = Result.timeOut("Time Out"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | response.getWriter().write(new ObjectMapper().writeValueAsString(result)); |
| | | response.setStatus(HttpServletResponse.SC_REQUEST_TIMEOUT); |
| | | } else { |
| | | Result result = Result.loginFail("Unauthorized"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | response.getWriter().write(new ObjectMapper().writeValueAsString(result)); |
| | | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
| | | } |
| | | } |
| | | } |