All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.cloud.security.GwAuthenticationEntryPoint Maven / Gradle / Ivy

There is a newer version: 2.3.8.RELEASE
Show newest version
package com.feingto.cloud.security;

import com.feingto.cloud.core.web.WebResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 认证失败处理器
 *
 * @author longfei
 */
@Slf4j
public class GwAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        log.warn(authException.getMessage());
        PrintWriter writer = response.getWriter();
        writer.print(WebResult.error(authException.getMessage()).put("code", HttpServletResponse.SC_UNAUTHORIZED));
        writer.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy