main
Last change
on this file was 5a9c93b, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Authorization layer
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | package com.example.rezevirajmasa.demo.model.exceptions;
|
---|
2 |
|
---|
3 | import com.example.rezevirajmasa.demo.dto.ErrorDto;
|
---|
4 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
5 | import jakarta.servlet.ServletException;
|
---|
6 | import jakarta.servlet.http.HttpServletRequest;
|
---|
7 | import jakarta.servlet.http.HttpServletResponse;
|
---|
8 | import org.springframework.http.HttpHeaders;
|
---|
9 | import org.springframework.http.MediaType;
|
---|
10 | import org.springframework.security.web.AuthenticationEntryPoint;
|
---|
11 | import org.springframework.stereotype.Component;
|
---|
12 |
|
---|
13 | import java.io.IOException;
|
---|
14 |
|
---|
15 | @Component
|
---|
16 | public class CustomerAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
---|
17 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | public void commence(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException, ServletException {
|
---|
21 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
---|
22 | response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
---|
23 | OBJECT_MAPPER.writeValue(response.getOutputStream(), new ErrorDto("Unauthorized path"));
|
---|
24 | }
|
---|
25 |
|
---|
26 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.