Skip to content
Snippets Groups Projects
Commit 1d7b1f8e authored by BERTOLONE--LOPEZ-SERRANO MELVYN p1804487's avatar BERTOLONE--LOPEZ-SERRANO MELVYN p1804487
Browse files

CORS ok

parent 662845fd
No related branches found
No related tags found
No related merge requests found
Pipeline #85811 failed
......@@ -3,6 +3,8 @@ package com.mif13.authServer.controllers;
import com.mif13.authServer.dao.UsersDao;
import com.mif13.authServer.model.User;
import com.mif13.authServer.utils.JwtHelper;
import java.io.Console;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -43,7 +45,7 @@ public class UserOperations {
* @param login Le login de l'utilisateur. L'utilisateur doit avoir été créé préalablement et
* son login doit être présent dans le DAO.
* @param password Le password à vérifier.
* @return Une ResponseEntity avec le JWT dans le header "Authentication" si le login s'est bien
* @return Une ResponseEntity avec le JWT dans le header "Authorization" si le login s'est bien
* passé, et le code de statut approprié (204, 401 ou 404).
*/
@Operation(summary = "login utilisée par un utilisateur")
......@@ -64,11 +66,13 @@ public class UserOperations {
)
})
@PostMapping("/login")
//@CrossOrigin(origins = {"http://localhost", "http://192.168.75.68", "https://192.168.75.68"})
public ResponseEntity<Void> login(@RequestParam("login") String login,
@RequestParam("password") String password, @RequestHeader("Origin") String origin) {
ResponseEntity<Void> response;
response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
/*response.getHeaders().add("Access-Control-Expose-Headers", "Authorization");
response.getHeaders().add("Access-Control-Allow-Origin", origin);*/
String jwt;
Map<String, List<String>> headers = new HashMap<>();
......@@ -112,15 +116,11 @@ public class UserOperations {
headersSpring = new MultiValueMapAdapter<>(headers);
response = new ResponseEntity<>(headersSpring, HttpStatus.NOT_FOUND);
}
response.getHeaders().add("Access-Control-Expose-Headers", "Authorization");
return response;
}
/**
*
* @param login Le login de l'utilisateur.
* @return Une réponse vide avec un code de statut approprié (204, 400, 401).
*/
@Operation(summary = "Réalise la déconnexion.")
@ApiResponses(value = {
@ApiResponse(
......@@ -167,7 +167,7 @@ public class UserOperations {
/**
* .
*
* @param jwt Le token JWT qui se trouve dans le header "Authentication" de la requête
* @param jwt Le token JWT qui se trouve dans le header "Authorization" de la requête
* @param origin L'origine de la requête (pour la comparer avec celle du client, stockée dans le
* token JWT)
* @return Une réponse vide avec un code de statut approprié (204, 400, 401).
......@@ -183,17 +183,10 @@ public class UserOperations {
)
})
@GetMapping("/authenticate")
// @CrossOrigin(origins = {"http://localhost", "http://192.168.75.68", "https://192.168.75.68"})
public ResponseEntity<Void> authenticate(@RequestParam("jwt") String jwt,
@RequestParam("origin") String origin) {
// TODO
ResponseEntity<Void> response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
response.getHeaders().add("Access-Control-Expose-Headers", "Authorization");
/* response.getHeaders().add("Access-Control-Allow-Methods","GET");
response.getHeaders().add("Access-Control-Allow-Headers", "Authorization");
response.getHeaders().add("Access-Control-Max-Age", "1728000");
response.getHeaders().add("Access-Control-Expose-Headers", "*, Authorization"); */
return response;
}
}
\ No newline at end of file
......@@ -18,25 +18,25 @@ public class CorsConfig {
registry.addMapping("/login")
.allowedMethods("POST")
.allowedHeaders("*", "Authorization")
.allowedOrigins("http://localhost", "http://192.168.75.68:8080", "http://https://192.168.75.68:8443","https://localhost");
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /lougout POST - CORS pas reglé
registry.addMapping("/logout")
.allowedMethods("POST")
.allowedHeaders("*", "Authorization")
.allowedOrigins("http://localhost", "http://192.168.75.68:8080", "http://https://192.168.75.68:8443","https://localhost");
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /authenticate GET - Fonctionne
registry.addMapping("/authenticate")
.allowedMethods("GET")
.allowedHeaders("*")
.allowedOrigins("http://localhost", "http://192.168.75.68:8080", "http://https://192.168.75.68:8443","https://localhost");
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /users/{id} GET - Fonctionne
registry.addMapping("/{id}")
.allowedMethods("GET")
.allowedHeaders("*")
.allowedOrigins("http://localhost", "http://192.168.75.68:8080", "http://https://192.168.75.68:8443","https://localhost");
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment