Search in sources :

Example 1 with DeniedException

use of com.github.liuweijw.exception.DeniedException in project fw-cloud-framework by liuweijw.

the class AccessDeniedHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
    logger.info("授权失败,禁止访问");
    response.setCharacterEncoding(CommonConstant.UTF8);
    response.setContentType(CommonConstant.CONTENT_TYPE);
    R<String> result = new R<String>().failure(new DeniedException(MessageConstant.COMMONS_AUTH_NOTSUPPORT));
    response.setStatus(HttpStatus.SC_FORBIDDEN);
    PrintWriter printWriter = response.getWriter();
    printWriter.append(objectMapper.writeValueAsString(result));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) DeniedException(com.github.liuweijw.exception.DeniedException) PrintWriter(java.io.PrintWriter)

Aggregations

DeniedException (com.github.liuweijw.exception.DeniedException)1 PrintWriter (java.io.PrintWriter)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1