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 | |
---|
1 | package finki.diplomska.tripplanner.security;
|
---|
2 |
|
---|
3 | import com.google.gson.Gson;
|
---|
4 | import finki.diplomska.tripplanner.models.exceptions.InvalidLoginResponse;
|
---|
5 | import org.springframework.security.core.AuthenticationException;
|
---|
6 | import org.springframework.security.web.AuthenticationEntryPoint;
|
---|
7 | import org.springframework.stereotype.Component;
|
---|
8 |
|
---|
9 | import javax.servlet.ServletException;
|
---|
10 | import javax.servlet.http.HttpServletRequest;
|
---|
11 | import javax.servlet.http.HttpServletResponse;
|
---|
12 | import java.io.IOException;
|
---|
13 |
|
---|
14 | @Component
|
---|
15 | public 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.