|
@@ -4,6 +4,7 @@ import com.auth0.jwt.JWT;
|
4
|
4
|
import com.auth0.jwt.JWTVerifier;
|
5
|
5
|
import com.auth0.jwt.algorithms.Algorithm;
|
6
|
6
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
|
7
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
7
|
8
|
import fr.natan.microservices.springsecurityserverjwt.t_authenticationFilter.b_authenticationFilter.FinalVariables;
|
8
|
9
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
9
|
10
|
import org.springframework.security.core.GrantedAuthority;
|
|
@@ -16,9 +17,10 @@ import javax.servlet.ServletException;
|
16
|
17
|
import javax.servlet.http.HttpServletRequest;
|
17
|
18
|
import javax.servlet.http.HttpServletResponse;
|
18
|
19
|
import java.io.IOException;
|
19
|
|
-import java.util.ArrayList;
|
20
|
|
-import java.util.Collection;
|
21
|
|
-import java.util.List;
|
|
20
|
+import java.util.*;
|
|
21
|
+
|
|
22
|
+import static org.springframework.http.HttpStatus.FORBIDDEN;
|
|
23
|
+import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
22
|
24
|
|
23
|
25
|
|
24
|
26
|
public class JWTAuthorizationFilter extends OncePerRequestFilter {
|
|
@@ -50,6 +52,11 @@ public class JWTAuthorizationFilter extends OncePerRequestFilter {
|
50
|
52
|
|
51
|
53
|
}catch (Exception exception){
|
52
|
54
|
response.setHeader("error-message", exception.getMessage());
|
|
55
|
+ Map<String, String> errors = new HashMap<>();
|
|
56
|
+ errors.put("error-message", exception.getMessage());
|
|
57
|
+ response.setContentType(APPLICATION_JSON_VALUE);
|
|
58
|
+ new ObjectMapper().writeValue(response.getOutputStream(), errors);
|
|
59
|
+ response.sendError(FORBIDDEN.value());
|
53
|
60
|
}
|
54
|
61
|
}
|
55
|
62
|
else{
|