Browse Source

commit modif

placidenduwayo 2 years ago
parent
commit
2edd92a5c7

+ 10
- 3
src/main/java/fr/natan/microservices/springsecurityserverjwt/tt_authorizationFilter/JWTAuthorizationFilter.java View File

4
 import com.auth0.jwt.JWTVerifier;
4
 import com.auth0.jwt.JWTVerifier;
5
 import com.auth0.jwt.algorithms.Algorithm;
5
 import com.auth0.jwt.algorithms.Algorithm;
6
 import com.auth0.jwt.interfaces.DecodedJWT;
6
 import com.auth0.jwt.interfaces.DecodedJWT;
7
+import com.fasterxml.jackson.databind.ObjectMapper;
7
 import fr.natan.microservices.springsecurityserverjwt.t_authenticationFilter.b_authenticationFilter.FinalVariables;
8
 import fr.natan.microservices.springsecurityserverjwt.t_authenticationFilter.b_authenticationFilter.FinalVariables;
8
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
9
 import org.springframework.security.core.GrantedAuthority;
10
 import org.springframework.security.core.GrantedAuthority;
16
 import javax.servlet.http.HttpServletRequest;
17
 import javax.servlet.http.HttpServletRequest;
17
 import javax.servlet.http.HttpServletResponse;
18
 import javax.servlet.http.HttpServletResponse;
18
 import java.io.IOException;
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
 public class JWTAuthorizationFilter extends OncePerRequestFilter {
26
 public class JWTAuthorizationFilter extends OncePerRequestFilter {
50
 
52
 
51
            }catch (Exception exception){
53
            }catch (Exception exception){
52
                response.setHeader("error-message", exception.getMessage());
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
         else{
62
         else{

+ 2
- 0
src/main/java/fr/natan/microservices/springsecurityserverjwt/web/AccountController.java View File

53
     private UserAccount getProfil(Principal principal) throws UserAccountNotFoundException {
53
     private UserAccount getProfil(Principal principal) throws UserAccountNotFoundException {
54
         return accountService.getUserByUsername(principal.getName());
54
         return accountService.getUserByUsername(principal.getName());
55
     }
55
     }
56
+
57
+    //develop here refresh token
56
 }
58
 }

Powered by TurnKey Linux.