backend/spring/src/main/java/com/sbank/spring/jwt/JwtAuthenticationEntryPoint.java
<filename>backend/spring/src/main/java/com/sbank/spring/jwt/JwtAuthenticationEntryPoint.javapackage com.sbank.spring.jwt;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

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

@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request,
                        HttpServletResponse response,
                        AuthenticationException authException) throws IOException {
        // 유효한 자격증명을 제공하지 않고 접근하려 할때 401 Unauthorized 에러 리턴
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
}
