This commit is contained in:
Your Name 2022-03-04 11:27:41 +01:00
commit 82ac354e7a
3 changed files with 38 additions and 15 deletions

View File

@ -27,7 +27,7 @@ import fr.cardon.simpleat.repository.RoleRepository;
import fr.cardon.simpleat.service.PersonneService; import fr.cardon.simpleat.service.PersonneService;
@RestController @RestController
@CrossOrigin("*") @CrossOrigin("http://localhost:4200")
public class PersonneController { public class PersonneController {

View File

@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import fr.cardon.simpleat.exception.InvalidJWTException; import fr.cardon.simpleat.exception.InvalidJWTException;
import fr.cardon.simpleat.model.EnumRole; import fr.cardon.simpleat.model.EnumRole;
import fr.cardon.simpleat.repository.PersonneRepository;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException; import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
@ -43,6 +44,9 @@ public class JwtTokenProvider {
@Autowired @Autowired
private UserDetailsService userDetailsService; private UserDetailsService userDetailsService;
@Autowired
private PersonneRepository personneRepository;
/** /**
* Cette méthode d'initialisation s'exécute avant le constructeur * Cette méthode d'initialisation s'exécute avant le constructeur
@ -104,6 +108,7 @@ public class JwtTokenProvider {
public String createToken(String email, List<EnumRole> roleList){ public String createToken(String email, List<EnumRole> roleList){
Claims claims = Jwts.claims().setSubject(email); Claims claims = Jwts.claims().setSubject(email);
claims.put("userId", personneRepository.findByEmail(email).get().getId());
claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList())); claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
System.out.println("claims = "+claims); System.out.println("claims = "+claims);

View File

@ -1,19 +1,37 @@
insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', 'pjKxIN'); insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', '$2a$10$724bLjLyGOEKTBbHy.s3C.ETc.HuBnhEoCOuoO7.Ts7kyPbz6hkme');
insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', 'YY0TuY6JH0di'); insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', '$2a$10$x6.VyO9PCMXSPsi5/m/Hze9xOP.IUdYbaye7cNFc.PfyuRuVLbG7e');
insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', 'C4sfAW4'); insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', '$2a$10$oe/h0ZDpi6xFmTj8CvDMDe13hoEGv0DhHziY7GUatbb9ETcRw/8RG');
insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', 'ACdXxMr'); insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', '$2a$10$ArSe7TSUapTs9oGE8824fOv4PM6NJwu7mzcg72cSmHy0.ds585Oke');
insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', 'pjKxIN'); insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', '$2a$10$6UbvPYBR2Ql09M1kgK0.HuoX3X1gxScmaOxI242EB2U7cXiylX3z.');
insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', 'YY0TuY6JH0di'); insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', '$2a$10$at1EZABxNN32M5pCttV36OvzbUWx1myGisa36i3..vveO6j0Lk2Da');
insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', 'C4sfAW4'); insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', '$2a$10$koeHn0Wg54MTc7iDb9hbsujy/Opfrhhu0uuhhBNA00rMXLeMpSl.m');
insert into personne (nom, prenom, email, password) values ('El hiri', 'Sana', 'sana.el-hiri@gmail.com', 'ACdXxMr'); insert into personne (nom, prenom, email, password) values ('El Hiri', 'Sana', 'sana.el-hiri@gmail.com', '$2a$10$jBBk1RQrl5XOeSQYz3xdJ.Xl8hBIu/x3mqHpYyL10m6KjwfDsWGEW');
insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', 'pjKxIN'); insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', '$2a$10$HAUg8vlmtvS/YphJzWAPfuGJdLd/3SeSZ48JVvybK6Wh/AY3QirGG');
insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', 'YY0TuY6JH0di'); insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', '$2a$10$BpWZMlDLKXA2qGMo9t6cxeS6G/6mvjdsdN4nIUOAjE2sr/0sJNiCW');
insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', 'C4sfAW4'); insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', '$2a$10$FJKDTcipj/8PKos7AcCnZ.HHAmdDh6EjknpUWPLDcVfSXWPcHZI5O');
insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr'); insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', '$2a$10$5iowOIUv72hFVsT9B8K.nerA3YTPAyyUiqOAwKR55ZZcpiHT96LhG');
insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN'); insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', '$2a$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.');
insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di'); insert into personne (nom, prenom, email, password) values ('Mjid', 'Hedi', 'hedi.mjid@gmail.com', '$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.');
insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.'); insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (1,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (2,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (3,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (4,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (5,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (6,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (7,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (8,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (9,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (10,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (11,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (12,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (13,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (14,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_CREATOR');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_READER');
insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (1, 'Admin');
insert into role (id_role, intitule) values (2, 'User'); insert into role (id_role, intitule) values (2, 'User');