backend-api #6
@@ -1,22 +1,11 @@
 | 
			
		||||
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 {
 | 
			
		||||
@@ -24,6 +13,4 @@ public class MyinpulseApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(MyinpulseApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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<Administrateurs> 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,7 @@ import java.util.Optional;
 | 
			
		||||
@RestController
 | 
			
		||||
public class ComptesRendusController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    ComptesRendusRepository comptesRendusRepository;
 | 
			
		||||
    @Autowired ComptesRendusRepository comptesRendusRepository;
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/ComptesRendus")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Entrepreneurs> 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<Entrepreneurs> 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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Projets> 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<Projets> 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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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> 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> rendezVous = this.rendezVousRepository.findById(id);
 | 
			
		||||
        if (rendezVous.isEmpty()) {
 | 
			
		||||
            throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Sections> 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<Sections> 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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Utilisateurs> 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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -37,17 +37,24 @@ public class RendezVous {
 | 
			
		||||
    @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true)
 | 
			
		||||
    private List<ComptesRendus> 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<Sections> 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -34,10 +34,13 @@ public class Sections {
 | 
			
		||||
    @ManyToMany(mappedBy = "sections")
 | 
			
		||||
    private List<RendezVous> 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -28,10 +28,15 @@ public class Utilisateurs {
 | 
			
		||||
    @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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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<ComptesRendus, Long> {
 | 
			
		||||
}
 | 
			
		||||
public interface ComptesRendusRepository extends JpaRepository<ComptesRendus, Long> {}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Projets, Long> {
 | 
			
		||||
}
 | 
			
		||||
public interface ProjetsRepository extends JpaRepository<Projets, Long> {}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<RendezVous, Long> {
 | 
			
		||||
}
 | 
			
		||||
public interface RendezVousRepository extends JpaRepository<RendezVous, Long> {}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Sections, Long> {
 | 
			
		||||
}
 | 
			
		||||
public interface SectionsRepository extends JpaRepository<Sections, Long> {}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,40 +16,35 @@ import java.util.stream.Stream;
 | 
			
		||||
 | 
			
		||||
import static java.util.stream.Collectors.toSet;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class KeycloakJwtRolesConverter implements Converter<Jwt, AbstractAuthenticationToken> {
 | 
			
		||||
    /**
 | 
			
		||||
     * 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())
 | 
			
		||||
    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<GrantedAuthority> TEMPORARNAME(Jwt jwt) {
 | 
			
		||||
        // Collection that will hold the extracted roles
 | 
			
		||||
@@ -66,7 +61,8 @@ public class KeycloakJwtRolesConverter implements Converter<Jwt, AbstractAuthent
 | 
			
		||||
            // Check if any roles are present
 | 
			
		||||
            if (roles != null && !roles.isEmpty()) {
 | 
			
		||||
                // Iterate of the roles and add them to the granted authorities
 | 
			
		||||
                Collection<GrantedAuthority> realmRoles = roles.stream()
 | 
			
		||||
                Collection<GrantedAuthority> realmRoles =
 | 
			
		||||
                        roles.stream()
 | 
			
		||||
                                // Prefix all realm roles with "ROLE_realm_"
 | 
			
		||||
                                .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role))
 | 
			
		||||
                                .collect(Collectors.toList());
 | 
			
		||||
@@ -75,24 +71,33 @@ public class KeycloakJwtRolesConverter implements Converter<Jwt, AbstractAuthent
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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<String, Map<String, Collection<String>>> resourceAccess = jwt.getClaim(CLAIM_RESOURCE_ACCESS);
 | 
			
		||||
        Map<String, Map<String, Collection<String>>> 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) -> {
 | 
			
		||||
            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))
 | 
			
		||||
                );
 | 
			
		||||
                        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,5 @@ import org.springframework.boot.test.context.SpringBootTest;
 | 
			
		||||
class MyinpulseApplicationTests {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
	void contextLoads() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    void contextLoads() {}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user