diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java index 23c2f28..1c39eef 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java @@ -1,29 +1,16 @@ package enseirb.myinpulse; -import enseirb.myinpulse.security.KeycloakJwtRolesConverter; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.converter.Converter; -import org.springframework.security.authentication.AbstractAuthenticationToken; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.jwt.*; -import org.springframework.security.web.SecurityFilterChain; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import java.util.*; -import java.util.stream.Collectors; -import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; @SpringBootApplication public class MyinpulseApplication { - public static void main(String[] args) { - SpringApplication.run(MyinpulseApplication.class, args); - } - - + public static void main(String[] args) { + SpringApplication.run(MyinpulseApplication.class, args); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index 50262e1..63aef48 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -22,21 +22,21 @@ public class GetUserInfo { @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random") - public boolean rand(){ + public boolean rand() { System.err.println("HELLO"); return Math.random() > 0.5; } @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random2") - public boolean rand2(){ + public boolean rand2() { System.err.println("HELLO2"); return Math.random() > 0.5; } @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random3") - public boolean rand3(){ + public boolean rand3() { System.err.println("HELLO"); return Math.random() > 0.5; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index 14c46b3..e642fd8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -23,10 +23,13 @@ public class WebSecurityCustomConfiguration { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(List.of("*")); configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS")); - configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", - "x-auth-token")); // Do not remove, this fixes the CORS errors when unauthenticated - UrlBasedCorsConfigurationSource source = new - UrlBasedCorsConfigurationSource(); + configuration.setAllowedHeaders( + Arrays.asList( + "authorization", + "content-type", + "x-auth-token")); // Do not remove, this fixes the CORS errors when + // unauthenticated + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; @@ -34,17 +37,23 @@ public class WebSecurityCustomConfiguration { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http - .authorizeHttpRequests(authorize -> authorize - .requestMatchers("/random2").access(hasRole("REALM_MyINPulse-entrepreneur")) - .requestMatchers("/random").access(hasRole("REALM_MyINPulse-admin")) - .requestMatchers("/random3").permitAll() - .anyRequest().authenticated() - ) - .oauth2ResourceServer(oauth2 -> oauth2 - .jwt(jwt -> jwt. - jwtAuthenticationConverter(new KeycloakJwtRolesConverter()))); + http.authorizeHttpRequests( + authorize -> + authorize + .requestMatchers("/random2") + .access(hasRole("REALM_MyINPulse-entrepreneur")) + .requestMatchers("/random") + .access(hasRole("REALM_MyINPulse-admin")) + .requestMatchers("/random3") + .permitAll() + .anyRequest() + .authenticated()) + .oauth2ResourceServer( + oauth2 -> + oauth2.jwt( + jwt -> + jwt.jwtAuthenticationConverter( + new KeycloakJwtRolesConverter()))); return http.build(); - } -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java index 5f1a718..f27240e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class AdministrateursController { - @Autowired - AdministrateursRepository administrateursRepository; + @Autowired AdministrateursRepository administrateursRepository; @GetMapping("/Administrateurs") @ResponseBody @@ -22,11 +21,11 @@ public class AdministrateursController { } @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) - { + public Administrateurs getAdministrateursById(@PathVariable Long id) { Optional administrateur = this.administrateursRepository.findById(id); if (administrateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); } return administrateur.get(); } @@ -35,5 +34,4 @@ public class AdministrateursController { public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { return this.administrateursRepository.save(administrateurs); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 9bcc862..c6cccdb 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class ComptesRendusController { - @Autowired - ComptesRendusRepository comptesRendusRepository; + @Autowired ComptesRendusRepository comptesRendusRepository; @GetMapping("/ComptesRendus") @ResponseBody diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index 2bbc653..e07c359 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -3,19 +3,16 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.web.bind.annotation.*; import enseirb.myinpulse.postgres_db.model.Entrepreneurs; import org.springframework.web.server.ResponseStatusException; import java.util.Optional; - @RestController public class EntrepreneursController { - @Autowired - EntrepreneursRepository entrepreneursRepository; + @Autowired EntrepreneursRepository entrepreneursRepository; @GetMapping("/Entrepreneurs") @ResponseBody @@ -24,11 +21,11 @@ public class EntrepreneursController { } @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) - { + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { Optional entrepreneur = entrepreneursRepository.findById(id); if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } return entrepreneur.get(); } @@ -39,10 +36,12 @@ public class EntrepreneursController { } @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs(@PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + public Entrepreneurs updateEntrepreneurs( + @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { Optional entrepreneur = entrepreneursRepository.findById(id); if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } if (ecole != null) { entrepreneur.get().setEcole(ecole); @@ -55,5 +54,4 @@ public class EntrepreneursController { } return entrepreneur.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index 92b5908..2f11474 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -13,8 +13,7 @@ import java.util.Optional; @RestController public class ProjetsController { - @Autowired - ProjetsRepository projetsRepository; + @Autowired ProjetsRepository projetsRepository; @GetMapping("/Projets") @ResponseBody @@ -23,8 +22,7 @@ public class ProjetsController { } @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) - { + public Projets getProjetsById(@PathVariable Long id) { Optional projet = this.projetsRepository.findById(id); if (projet.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); @@ -38,7 +36,12 @@ public class ProjetsController { } @PostMapping("/Projets/{id}") - public Projets updateProjets(@PathVariable Long id, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + public Projets updateProjets( + @PathVariable Long id, + String nom_projet, + Byte[] logo, + LocalDate date_creation, + String status_projet) { Optional projet = this.projetsRepository.findById(id); if (projet.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); @@ -57,5 +60,4 @@ public class ProjetsController { } return projet.get(); } - -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index aa9e3ba..0ec0b0c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -14,8 +14,7 @@ import java.util.Optional; @RestController public class RendezVousController { - @Autowired - RendezVousRepository rendezVousRepository; + @Autowired RendezVousRepository rendezVousRepository; @GetMapping("/RendezVous") @ResponseBody @@ -24,8 +23,7 @@ public class RendezVousController { } @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) - { + public RendezVous getRendezVousById(@PathVariable Long id) { Optional rendezVous = this.rendezVousRepository.findById(id); if (rendezVous.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); @@ -39,7 +37,13 @@ public class RendezVousController { } @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous(@PathVariable Long id, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + public RendezVous updateRendezVous( + @PathVariable Long id, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { Optional rendezVous = this.rendezVousRepository.findById(id); if (rendezVous.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 49032fe..5f065a5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -13,8 +13,7 @@ import java.util.Optional; @RestController public class SectionsController { - @Autowired - SectionsRepository sectionsRepository; + @Autowired SectionsRepository sectionsRepository; @GetMapping("/Sections") @ResponseBody @@ -23,8 +22,7 @@ public class SectionsController { } @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) - { + public Sections getSectionsById(@PathVariable Long id) { Optional section = this.sectionsRepository.findById(id); if (section.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); @@ -38,7 +36,11 @@ public class SectionsController { } @PostMapping("/Sections/{id}") - public Sections updateSections(@PathVariable Long id, String titre, String contenu_section, LocalDateTime date_modification) { + public Sections updateSections( + @PathVariable Long id, + String titre, + String contenu_section, + LocalDateTime date_modification) { Optional section = this.sectionsRepository.findById(id); if (section.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); @@ -54,5 +56,4 @@ public class SectionsController { } return section.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index 059e2f0..040b4d0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class UtilisateursController { - @Autowired - UtilisateursRepository utilisateursRepository; + @Autowired UtilisateursRepository utilisateursRepository; @GetMapping("/Utilisateurs") @ResponseBody @@ -36,11 +35,18 @@ public class UtilisateursController { } @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs(@PathVariable Long id, String nom_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + public Utilisateurs updateUtilisateurs( + @PathVariable Long id, + String nom_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { Optional utilisateur = utilisateursRepository.findById(id); if (utilisateur.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - }if (nom_utilisateur != null) { + } + if (nom_utilisateur != null) { utilisateur.get().setNom_utilisateur(nom_utilisateur); } if (prenom_utilisateur != null) { @@ -57,5 +63,4 @@ public class UtilisateursController { } return utilisateur.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index 0255adf..5620b9a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -10,7 +10,6 @@ import java.util.List; @Entity @Table(name = "administrateurs") @PrimaryKeyJoinColumn(name = "id_administrateur") - public class Administrateurs extends Utilisateurs { @ManyToOne(fetch = FetchType.LAZY) @@ -24,11 +23,21 @@ public class Administrateurs extends Utilisateurs { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; - public Administrateurs() { - } + public Administrateurs() {} - public Administrateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + public Administrateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java index cd7f283..a629e3b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java @@ -21,9 +21,7 @@ public class ComptesRendus { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; - - public ComptesRendus() { - } + public ComptesRendus() {} public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { this.id_compte_rendu = id_compte_rendu; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java index b8f6964..4f73d19 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -9,10 +9,10 @@ import jakarta.persistence.Table; @PrimaryKeyJoinColumn(name = "id_entrepreneur") public class Entrepreneurs extends Utilisateurs { - @Column(length=255) + @Column(length = 255) private String ecole; - @Column(length=255) + @Column(length = 255) private String filiere; private boolean status_snee; @@ -29,12 +29,25 @@ public class Entrepreneurs extends Utilisateurs { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; + public Entrepreneurs() {} - public Entrepreneurs() { - } - - public Entrepreneurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone, String ecole, boolean status_snee, String filiere) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + public Entrepreneurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone, + String ecole, + boolean status_snee, + String filiere) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); this.ecole = ecole; this.status_snee = status_snee; this.filiere = filiere; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java index 6fd8d98..63d3bc3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -16,14 +16,14 @@ public class Projets { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_projet; - @Column(length=255) + @Column(length = 255) private String nom_projet; private Byte[] logo; private LocalDate date_creation; - @Column(length=255) + @Column(length = 255) private String status_projet; @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) @@ -41,10 +41,14 @@ public class Projets { // Hibernate expects entities to have a no-arg constructor, // though it does not necessarily have to be public. - public Projets() { - } + public Projets() {} - public Projets(Long id_projet, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + public Projets( + Long id_projet, + String nom_projet, + Byte[] logo, + LocalDate date_creation, + String status_projet) { this.id_projet = id_projet; this.nom_projet = nom_projet; this.logo = logo; @@ -91,5 +95,4 @@ public class Projets { public void setStatus_projet(String status_projet) { this.status_projet = status_projet; } - -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index 78fbfc2..55732c1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -23,7 +23,7 @@ public class RendezVous { private LocalDateTime duree_rdv; - @Column(length=255) + @Column(length = 255) private String lieu_rdv; private String sujet_rdv; @@ -37,17 +37,24 @@ public class RendezVous { @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) private List ListComptesRendus = new ArrayList<>(); - @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) @JoinTable( name = "concerner", joinColumns = @JoinColumn(name = "id_rdv"), inverseJoinColumns = @JoinColumn(name = "id_sections")) List ListSections = new ArrayList<>(); - public RendezVous() { - } + public RendezVous() {} - public RendezVous(Long id_rdv, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + public RendezVous( + Long id_rdv, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { this.id_rdv = id_rdv; this.date_rdv = date_rdv; this.heure_rdv = heure_rdv; @@ -103,5 +110,4 @@ public class RendezVous { public void setSujet_rdv(String sujet_rdv) { this.sujet_rdv = sujet_rdv; } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java index f5852ac..0c9d013 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java @@ -16,7 +16,7 @@ public class Sections { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_section; - @Column(length=255) + @Column(length = 255) private String titre; private String contenu_section; @@ -34,10 +34,13 @@ public class Sections { @ManyToMany(mappedBy = "sections") private List rendezVous = new ArrayList<>(); - public Sections() { - } + public Sections() {} - public Sections(Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { + public Sections( + Long id_section, + String titre, + String contenu_section, + LocalDateTime date_modification) { this.id_section = id_section; this.titre = titre; this.contenu_section = contenu_section; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java index e20de6b..9d81163 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -13,25 +13,30 @@ public class Utilisateurs { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_utilisateur; - @Column(length=255) + @Column(length = 255) private String nom_utilisateur; - @Column(length=255) + @Column(length = 255) private String prenom_utilisateur; - @Column(length=255) + @Column(length = 255) private String mail_principal; - @Column(length=255) + @Column(length = 255) private String mail_secondaire; - @Column(length=15) + @Column(length = 15) private String numero_telephone; - public Utilisateurs() { - } + public Utilisateurs() {} - public Utilisateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + public Utilisateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { this.nom_utilisateur = nom_utilisateur; this.id_utilisateur = id_utilisateur; this.prenom_utilisateur = prenom_utilisateur; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java index 41a9c0e..e4de376 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ComptesRendusRepository extends JpaRepository { -} +public interface ComptesRendusRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java index 6665c89..37f5d8e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ProjetsRepository extends JpaRepository { -} \ No newline at end of file +public interface ProjetsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java index be67f00..93074f8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface RendezVousRepository extends JpaRepository { -} +public interface RendezVousRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java index 70411d3..cc25ab1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface SectionsRepository extends JpaRepository { -} +public interface SectionsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java index fafbef5..dba41cc 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java @@ -16,40 +16,35 @@ import java.util.stream.Stream; import static java.util.stream.Collectors.toSet; - public class KeycloakJwtRolesConverter implements Converter { - /** - * Prefix used for realm level roles. - */ + /** Prefix used for realm level roles. */ public static final String PREFIX_REALM_ROLE = "ROLE_REALM_"; - /** - * Prefix used in combination with the resource (client) name for resource level roles. - */ + + /** Prefix used in combination with the resource (client) name for resource level roles. */ public static final String PREFIX_RESOURCE_ROLE = "ROLE_"; - /** - * Name of the claim containing the realm level roles - */ + /** Name of the claim containing the realm level roles */ private static final String CLAIM_REALM_ACCESS = "realm_access"; - /** - * Name of the claim containing the resources (clients) the user has access to. - */ + + /** Name of the claim containing the resources (clients) the user has access to. */ private static final String CLAIM_RESOURCE_ACCESS = "resource_access"; - /** - * Name of the claim containing roles. (Applicable to realm and resource level.) - */ + + /** Name of the claim containing roles. (Applicable to realm and resource level.) */ private static final String CLAIM_ROLES = "roles"; @Override - public AbstractAuthenticationToken convert(Jwt source) - { - return new JwtAuthenticationToken(source, Stream.concat(new JwtGrantedAuthoritiesConverter().convert(source) - .stream(), TEMPORARNAME(source).stream()) - .collect(toSet())); + public AbstractAuthenticationToken convert(Jwt source) { + return new JwtAuthenticationToken( + source, + Stream.concat( + new JwtGrantedAuthoritiesConverter().convert(source).stream(), + TEMPORARNAME(source).stream()) + .collect(toSet())); } /** - * Extracts the realm and resource level roles from a JWT token distinguishing between them using prefixes. + * Extracts the realm and resource level roles from a JWT token distinguishing between them + * using prefixes. */ public Collection TEMPORARNAME(Jwt jwt) { // Collection that will hold the extracted roles @@ -66,33 +61,43 @@ public class KeycloakJwtRolesConverter implements Converter realmRoles = roles.stream() - // Prefix all realm roles with "ROLE_realm_" - .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) - .collect(Collectors.toList()); + Collection realmRoles = + roles.stream() + // Prefix all realm roles with "ROLE_realm_" + .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) + .collect(Collectors.toList()); grantedAuthorities.addAll(realmRoles); } } // Resource (client) roles - // A user might have access to multiple resources all containing their own roles. Therefore, it is a map of + // A user might have access to multiple resources all containing their own roles. Therefore, + // it is a map of // resource each possibly containing a "roles" property. - Map>> resourceAccess = jwt.getClaim(CLAIM_RESOURCE_ACCESS); + Map>> resourceAccess = + jwt.getClaim(CLAIM_RESOURCE_ACCESS); // Check if resources are assigned if (resourceAccess != null && !resourceAccess.isEmpty()) { // Iterate of all the resources - resourceAccess.forEach((resource, resourceClaims) -> { - // Iterate of the "roles" claim inside the resource claims - resourceClaims.get(CLAIM_ROLES).forEach( - // Add the role to the granted authority prefixed with ROLE_ and the name of the resource - role -> grantedAuthorities.add(new SimpleGrantedAuthority(PREFIX_RESOURCE_ROLE + resource + "_" + role)) - ); - }); + resourceAccess.forEach( + (resource, resourceClaims) -> { + // Iterate of the "roles" claim inside the resource claims + resourceClaims + .get(CLAIM_ROLES) + .forEach( + // Add the role to the granted authority prefixed with ROLE_ + // and the name of the resource + role -> + grantedAuthorities.add( + new SimpleGrantedAuthority( + PREFIX_RESOURCE_ROLE + + resource + + "_" + + role))); + }); } return grantedAuthorities; } - - } diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java index dce5ab2..04669ca 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java @@ -6,8 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class MyinpulseApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} }