source: trip-planner/src/main/java/finki/diplomska/tripplanner/security/JwtAuthenticationEntryPoint.java

Last change on this file was 1ad8e64, checked in by Ema <ema_spirova@…>, 3 years ago

spring security

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package finki.diplomska.tripplanner.security;
2
3import com.google.gson.Gson;
4import finki.diplomska.tripplanner.models.exceptions.InvalidLoginResponse;
5import org.springframework.security.core.AuthenticationException;
6import org.springframework.security.web.AuthenticationEntryPoint;
7import org.springframework.stereotype.Component;
8
9import javax.servlet.ServletException;
10import javax.servlet.http.HttpServletRequest;
11import javax.servlet.http.HttpServletResponse;
12import java.io.IOException;
13
14@Component
15public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
16 @Override
17 public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
18 AuthenticationException e) throws IOException, ServletException {
19
20 InvalidLoginResponse loginResponse = new InvalidLoginResponse();
21 String jsonLoginResponse = new Gson().toJson(loginResponse);
22
23
24 httpServletResponse.setContentType("application/json");
25 httpServletResponse.setStatus(401);
26 httpServletResponse.getWriter().print(jsonLoginResponse);
27 }
28}
Note: See TracBrowser for help on using the repository browser.