Google Java Format
This commit is contained in:
parent
c715955758
commit
45bbe51897
@ -1,29 +1,16 @@
|
|||||||
package enseirb.myinpulse;
|
package enseirb.myinpulse;
|
||||||
|
|
||||||
import enseirb.myinpulse.security.KeycloakJwtRolesConverter;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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.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.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class MyinpulseApplication {
|
public class MyinpulseApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MyinpulseApplication.class, args);
|
SpringApplication.run(MyinpulseApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,21 +22,21 @@ public class GetUserInfo {
|
|||||||
|
|
||||||
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
||||||
@GetMapping("/random")
|
@GetMapping("/random")
|
||||||
public boolean rand(){
|
public boolean rand() {
|
||||||
System.err.println("HELLO");
|
System.err.println("HELLO");
|
||||||
return Math.random() > 0.5;
|
return Math.random() > 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
||||||
@GetMapping("/random2")
|
@GetMapping("/random2")
|
||||||
public boolean rand2(){
|
public boolean rand2() {
|
||||||
System.err.println("HELLO2");
|
System.err.println("HELLO2");
|
||||||
return Math.random() > 0.5;
|
return Math.random() > 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
||||||
@GetMapping("/random3")
|
@GetMapping("/random3")
|
||||||
public boolean rand3(){
|
public boolean rand3() {
|
||||||
System.err.println("HELLO");
|
System.err.println("HELLO");
|
||||||
return Math.random() > 0.5;
|
return Math.random() > 0.5;
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,13 @@ public class WebSecurityCustomConfiguration {
|
|||||||
CorsConfiguration configuration = new CorsConfiguration();
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
configuration.setAllowedOrigins(List.of("*"));
|
configuration.setAllowedOrigins(List.of("*"));
|
||||||
configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS"));
|
configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS"));
|
||||||
configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type",
|
configuration.setAllowedHeaders(
|
||||||
"x-auth-token")); // Do not remove, this fixes the CORS errors when unauthenticated
|
Arrays.asList(
|
||||||
UrlBasedCorsConfigurationSource source = new
|
"authorization",
|
||||||
UrlBasedCorsConfigurationSource();
|
"content-type",
|
||||||
|
"x-auth-token")); // Do not remove, this fixes the CORS errors when
|
||||||
|
// unauthenticated
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
source.registerCorsConfiguration("/**", configuration);
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@ -34,17 +37,23 @@ public class WebSecurityCustomConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http.authorizeHttpRequests(
|
||||||
.authorizeHttpRequests(authorize -> authorize
|
authorize ->
|
||||||
.requestMatchers("/random2").access(hasRole("REALM_MyINPulse-entrepreneur"))
|
authorize
|
||||||
.requestMatchers("/random").access(hasRole("REALM_MyINPulse-admin"))
|
.requestMatchers("/random2")
|
||||||
.requestMatchers("/random3").permitAll()
|
.access(hasRole("REALM_MyINPulse-entrepreneur"))
|
||||||
.anyRequest().authenticated()
|
.requestMatchers("/random")
|
||||||
)
|
.access(hasRole("REALM_MyINPulse-admin"))
|
||||||
.oauth2ResourceServer(oauth2 -> oauth2
|
.requestMatchers("/random3")
|
||||||
.jwt(jwt -> jwt.
|
.permitAll()
|
||||||
jwtAuthenticationConverter(new KeycloakJwtRolesConverter())));
|
.anyRequest()
|
||||||
|
.authenticated())
|
||||||
|
.oauth2ResourceServer(
|
||||||
|
oauth2 ->
|
||||||
|
oauth2.jwt(
|
||||||
|
jwt ->
|
||||||
|
jwt.jwtAuthenticationConverter(
|
||||||
|
new KeycloakJwtRolesConverter())));
|
||||||
return http.build();
|
return http.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class AdministrateursController {
|
public class AdministrateursController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired AdministrateursRepository administrateursRepository;
|
||||||
AdministrateursRepository administrateursRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Administrateurs")
|
@GetMapping("/Administrateurs")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -22,11 +21,11 @@ public class AdministrateursController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/Administrateurs/{id}")
|
@GetMapping("/Administrateurs/{id}")
|
||||||
public Administrateurs getAdministrateursById(@PathVariable Long id)
|
public Administrateurs getAdministrateursById(@PathVariable Long id) {
|
||||||
{
|
|
||||||
Optional<Administrateurs> administrateur = this.administrateursRepository.findById(id);
|
Optional<Administrateurs> administrateur = this.administrateursRepository.findById(id);
|
||||||
if (administrateur.isEmpty()) {
|
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();
|
return administrateur.get();
|
||||||
}
|
}
|
||||||
@ -35,5 +34,4 @@ public class AdministrateursController {
|
|||||||
public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) {
|
public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) {
|
||||||
return this.administrateursRepository.save(administrateurs);
|
return this.administrateursRepository.save(administrateurs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class ComptesRendusController {
|
public class ComptesRendusController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired ComptesRendusRepository comptesRendusRepository;
|
||||||
ComptesRendusRepository comptesRendusRepository;
|
|
||||||
|
|
||||||
@GetMapping("/ComptesRendus")
|
@GetMapping("/ComptesRendus")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -3,19 +3,16 @@ package enseirb.myinpulse.postgres_db.controller;
|
|||||||
import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository;
|
import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.HttpStatusCode;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import enseirb.myinpulse.postgres_db.model.Entrepreneurs;
|
import enseirb.myinpulse.postgres_db.model.Entrepreneurs;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class EntrepreneursController {
|
public class EntrepreneursController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired EntrepreneursRepository entrepreneursRepository;
|
||||||
EntrepreneursRepository entrepreneursRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Entrepreneurs")
|
@GetMapping("/Entrepreneurs")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -24,11 +21,11 @@ public class EntrepreneursController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/Entrepreneurs/{id}")
|
@GetMapping("/Entrepreneurs/{id}")
|
||||||
public Entrepreneurs getEntrepreneursById(@PathVariable Long id)
|
public Entrepreneurs getEntrepreneursById(@PathVariable Long id) {
|
||||||
{
|
|
||||||
Optional<Entrepreneurs> entrepreneur = entrepreneursRepository.findById(id);
|
Optional<Entrepreneurs> entrepreneur = entrepreneursRepository.findById(id);
|
||||||
if (entrepreneur.isEmpty()) {
|
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();
|
return entrepreneur.get();
|
||||||
}
|
}
|
||||||
@ -39,10 +36,12 @@ public class EntrepreneursController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Entrepreneurs/{id}")
|
@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);
|
Optional<Entrepreneurs> entrepreneur = entrepreneursRepository.findById(id);
|
||||||
if (entrepreneur.isEmpty()) {
|
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) {
|
if (ecole != null) {
|
||||||
entrepreneur.get().setEcole(ecole);
|
entrepreneur.get().setEcole(ecole);
|
||||||
@ -55,5 +54,4 @@ public class EntrepreneursController {
|
|||||||
}
|
}
|
||||||
return entrepreneur.get();
|
return entrepreneur.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class ProjetsController {
|
public class ProjetsController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired ProjetsRepository projetsRepository;
|
||||||
ProjetsRepository projetsRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Projets")
|
@GetMapping("/Projets")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -23,8 +22,7 @@ public class ProjetsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/Projets/{id}")
|
@GetMapping("/Projets/{id}")
|
||||||
public Projets getProjetsById(@PathVariable Long id)
|
public Projets getProjetsById(@PathVariable Long id) {
|
||||||
{
|
|
||||||
Optional<Projets> projet = this.projetsRepository.findById(id);
|
Optional<Projets> projet = this.projetsRepository.findById(id);
|
||||||
if (projet.isEmpty()) {
|
if (projet.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
||||||
@ -38,7 +36,12 @@ public class ProjetsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Projets/{id}")
|
@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);
|
Optional<Projets> projet = this.projetsRepository.findById(id);
|
||||||
if (projet.isEmpty()) {
|
if (projet.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
||||||
@ -57,5 +60,4 @@ public class ProjetsController {
|
|||||||
}
|
}
|
||||||
return projet.get();
|
return projet.get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -14,8 +14,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class RendezVousController {
|
public class RendezVousController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired RendezVousRepository rendezVousRepository;
|
||||||
RendezVousRepository rendezVousRepository;
|
|
||||||
|
|
||||||
@GetMapping("/RendezVous")
|
@GetMapping("/RendezVous")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -24,8 +23,7 @@ public class RendezVousController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/RendezVous/{id}")
|
@GetMapping("/RendezVous/{id}")
|
||||||
public RendezVous getRendezVousById(@PathVariable Long id)
|
public RendezVous getRendezVousById(@PathVariable Long id) {
|
||||||
{
|
|
||||||
Optional<RendezVous> rendezVous = this.rendezVousRepository.findById(id);
|
Optional<RendezVous> rendezVous = this.rendezVousRepository.findById(id);
|
||||||
if (rendezVous.isEmpty()) {
|
if (rendezVous.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
||||||
@ -39,7 +37,13 @@ public class RendezVousController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/RendezVous/{id}")
|
@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);
|
Optional<RendezVous> rendezVous = this.rendezVousRepository.findById(id);
|
||||||
if (rendezVous.isEmpty()) {
|
if (rendezVous.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
||||||
|
@ -13,8 +13,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class SectionsController {
|
public class SectionsController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired SectionsRepository sectionsRepository;
|
||||||
SectionsRepository sectionsRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Sections")
|
@GetMapping("/Sections")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -23,8 +22,7 @@ public class SectionsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/Sections/{id}")
|
@GetMapping("/Sections/{id}")
|
||||||
public Sections getSectionsById(@PathVariable Long id)
|
public Sections getSectionsById(@PathVariable Long id) {
|
||||||
{
|
|
||||||
Optional<Sections> section = this.sectionsRepository.findById(id);
|
Optional<Sections> section = this.sectionsRepository.findById(id);
|
||||||
if (section.isEmpty()) {
|
if (section.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas");
|
||||||
@ -38,7 +36,11 @@ public class SectionsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Sections/{id}")
|
@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);
|
Optional<Sections> section = this.sectionsRepository.findById(id);
|
||||||
if (section.isEmpty()) {
|
if (section.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas");
|
||||||
@ -54,5 +56,4 @@ public class SectionsController {
|
|||||||
}
|
}
|
||||||
return section.get();
|
return section.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ import java.util.Optional;
|
|||||||
@RestController
|
@RestController
|
||||||
public class UtilisateursController {
|
public class UtilisateursController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired UtilisateursRepository utilisateursRepository;
|
||||||
UtilisateursRepository utilisateursRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Utilisateurs")
|
@GetMapping("/Utilisateurs")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -36,11 +35,18 @@ public class UtilisateursController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Utilisateurs/{id}")
|
@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);
|
Optional<Utilisateurs> utilisateur = utilisateursRepository.findById(id);
|
||||||
if (utilisateur.isEmpty()) {
|
if (utilisateur.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
|
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);
|
utilisateur.get().setNom_utilisateur(nom_utilisateur);
|
||||||
}
|
}
|
||||||
if (prenom_utilisateur != null) {
|
if (prenom_utilisateur != null) {
|
||||||
@ -57,5 +63,4 @@ public class UtilisateursController {
|
|||||||
}
|
}
|
||||||
return utilisateur.get();
|
return utilisateur.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import java.util.List;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "administrateurs")
|
@Table(name = "administrateurs")
|
||||||
@PrimaryKeyJoinColumn(name = "id_administrateur")
|
@PrimaryKeyJoinColumn(name = "id_administrateur")
|
||||||
|
|
||||||
public class Administrateurs extends Utilisateurs {
|
public class Administrateurs extends Utilisateurs {
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@ -24,11 +23,21 @@ public class Administrateurs extends Utilisateurs {
|
|||||||
@JoinColumn(name = "RendezVous.id_rdv")
|
@JoinColumn(name = "RendezVous.id_rdv")
|
||||||
private RendezVous rendezVous;
|
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) {
|
public Administrateurs(
|
||||||
super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone);
|
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")
|
@JoinColumn(name = "RendezVous.id_rdv")
|
||||||
private RendezVous rendezVous;
|
private RendezVous rendezVous;
|
||||||
|
|
||||||
|
public ComptesRendus() {}
|
||||||
public ComptesRendus() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) {
|
public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) {
|
||||||
this.id_compte_rendu = id_compte_rendu;
|
this.id_compte_rendu = id_compte_rendu;
|
||||||
|
@ -9,10 +9,10 @@ import jakarta.persistence.Table;
|
|||||||
@PrimaryKeyJoinColumn(name = "id_entrepreneur")
|
@PrimaryKeyJoinColumn(name = "id_entrepreneur")
|
||||||
public class Entrepreneurs extends Utilisateurs {
|
public class Entrepreneurs extends Utilisateurs {
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String ecole;
|
private String ecole;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String filiere;
|
private String filiere;
|
||||||
|
|
||||||
private boolean status_snee;
|
private boolean status_snee;
|
||||||
@ -29,12 +29,25 @@ public class Entrepreneurs extends Utilisateurs {
|
|||||||
@JoinColumn(name = "RendezVous.id_rdv")
|
@JoinColumn(name = "RendezVous.id_rdv")
|
||||||
private RendezVous rendezVous;
|
private RendezVous rendezVous;
|
||||||
|
|
||||||
|
public Entrepreneurs() {}
|
||||||
|
|
||||||
public Entrepreneurs() {
|
public Entrepreneurs(
|
||||||
}
|
String nom_utilisateur,
|
||||||
|
Long id_utilisateur,
|
||||||
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) {
|
String prenom_utilisateur,
|
||||||
super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone);
|
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.ecole = ecole;
|
||||||
this.status_snee = status_snee;
|
this.status_snee = status_snee;
|
||||||
this.filiere = filiere;
|
this.filiere = filiere;
|
||||||
|
@ -16,14 +16,14 @@ public class Projets {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id_projet;
|
private Long id_projet;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String nom_projet;
|
private String nom_projet;
|
||||||
|
|
||||||
private Byte[] logo;
|
private Byte[] logo;
|
||||||
|
|
||||||
private LocalDate date_creation;
|
private LocalDate date_creation;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String status_projet;
|
private String status_projet;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true)
|
@OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
@ -41,10 +41,14 @@ public class Projets {
|
|||||||
// Hibernate expects entities to have a no-arg constructor,
|
// Hibernate expects entities to have a no-arg constructor,
|
||||||
// though it does not necessarily have to be public.
|
// 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.id_projet = id_projet;
|
||||||
this.nom_projet = nom_projet;
|
this.nom_projet = nom_projet;
|
||||||
this.logo = logo;
|
this.logo = logo;
|
||||||
@ -91,5 +95,4 @@ public class Projets {
|
|||||||
public void setStatus_projet(String status_projet) {
|
public void setStatus_projet(String status_projet) {
|
||||||
this.status_projet = status_projet;
|
this.status_projet = status_projet;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -23,7 +23,7 @@ public class RendezVous {
|
|||||||
|
|
||||||
private LocalDateTime duree_rdv;
|
private LocalDateTime duree_rdv;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String lieu_rdv;
|
private String lieu_rdv;
|
||||||
|
|
||||||
private String sujet_rdv;
|
private String sujet_rdv;
|
||||||
@ -37,17 +37,24 @@ public class RendezVous {
|
|||||||
@OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true)
|
@OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
private List<ComptesRendus> ListComptesRendus = new ArrayList<>();
|
private List<ComptesRendus> ListComptesRendus = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
|
@ManyToMany(
|
||||||
|
fetch = FetchType.LAZY,
|
||||||
|
cascade = {CascadeType.ALL})
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "concerner",
|
name = "concerner",
|
||||||
joinColumns = @JoinColumn(name = "id_rdv"),
|
joinColumns = @JoinColumn(name = "id_rdv"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "id_sections"))
|
inverseJoinColumns = @JoinColumn(name = "id_sections"))
|
||||||
List<Sections> ListSections = new ArrayList<>();
|
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.id_rdv = id_rdv;
|
||||||
this.date_rdv = date_rdv;
|
this.date_rdv = date_rdv;
|
||||||
this.heure_rdv = heure_rdv;
|
this.heure_rdv = heure_rdv;
|
||||||
@ -103,5 +110,4 @@ public class RendezVous {
|
|||||||
public void setSujet_rdv(String sujet_rdv) {
|
public void setSujet_rdv(String sujet_rdv) {
|
||||||
this.sujet_rdv = sujet_rdv;
|
this.sujet_rdv = sujet_rdv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class Sections {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id_section;
|
private Long id_section;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String titre;
|
private String titre;
|
||||||
|
|
||||||
private String contenu_section;
|
private String contenu_section;
|
||||||
@ -34,10 +34,13 @@ public class Sections {
|
|||||||
@ManyToMany(mappedBy = "sections")
|
@ManyToMany(mappedBy = "sections")
|
||||||
private List<RendezVous> rendezVous = new ArrayList<>();
|
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.id_section = id_section;
|
||||||
this.titre = titre;
|
this.titre = titre;
|
||||||
this.contenu_section = contenu_section;
|
this.contenu_section = contenu_section;
|
||||||
|
@ -13,25 +13,30 @@ public class Utilisateurs {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id_utilisateur;
|
private Long id_utilisateur;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String nom_utilisateur;
|
private String nom_utilisateur;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String prenom_utilisateur;
|
private String prenom_utilisateur;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String mail_principal;
|
private String mail_principal;
|
||||||
|
|
||||||
@Column(length=255)
|
@Column(length = 255)
|
||||||
private String mail_secondaire;
|
private String mail_secondaire;
|
||||||
|
|
||||||
@Column(length=15)
|
@Column(length = 15)
|
||||||
private String numero_telephone;
|
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.nom_utilisateur = nom_utilisateur;
|
||||||
this.id_utilisateur = id_utilisateur;
|
this.id_utilisateur = id_utilisateur;
|
||||||
this.prenom_utilisateur = prenom_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;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
@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;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
@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;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
@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;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
@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;
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
|
|
||||||
public class KeycloakJwtRolesConverter implements Converter<Jwt, AbstractAuthenticationToken> {
|
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_";
|
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_";
|
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";
|
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";
|
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";
|
private static final String CLAIM_ROLES = "roles";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractAuthenticationToken convert(Jwt source)
|
public AbstractAuthenticationToken convert(Jwt source) {
|
||||||
{
|
return new JwtAuthenticationToken(
|
||||||
return new JwtAuthenticationToken(source, Stream.concat(new JwtGrantedAuthoritiesConverter().convert(source)
|
source,
|
||||||
.stream(), TEMPORARNAME(source).stream())
|
Stream.concat(
|
||||||
.collect(toSet()));
|
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) {
|
public Collection<GrantedAuthority> TEMPORARNAME(Jwt jwt) {
|
||||||
// Collection that will hold the extracted roles
|
// Collection that will hold the extracted roles
|
||||||
@ -66,33 +61,43 @@ public class KeycloakJwtRolesConverter implements Converter<Jwt, AbstractAuthent
|
|||||||
// Check if any roles are present
|
// Check if any roles are present
|
||||||
if (roles != null && !roles.isEmpty()) {
|
if (roles != null && !roles.isEmpty()) {
|
||||||
// Iterate of the roles and add them to the granted authorities
|
// Iterate of the roles and add them to the granted authorities
|
||||||
Collection<GrantedAuthority> realmRoles = roles.stream()
|
Collection<GrantedAuthority> realmRoles =
|
||||||
// Prefix all realm roles with "ROLE_realm_"
|
roles.stream()
|
||||||
.map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role))
|
// Prefix all realm roles with "ROLE_realm_"
|
||||||
.collect(Collectors.toList());
|
.map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role))
|
||||||
|
.collect(Collectors.toList());
|
||||||
grantedAuthorities.addAll(realmRoles);
|
grantedAuthorities.addAll(realmRoles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resource (client) roles
|
// 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.
|
// 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
|
// Check if resources are assigned
|
||||||
if (resourceAccess != null && !resourceAccess.isEmpty()) {
|
if (resourceAccess != null && !resourceAccess.isEmpty()) {
|
||||||
// Iterate of all the resources
|
// Iterate of all the resources
|
||||||
resourceAccess.forEach((resource, resourceClaims) -> {
|
resourceAccess.forEach(
|
||||||
// Iterate of the "roles" claim inside the resource claims
|
(resource, resourceClaims) -> {
|
||||||
resourceClaims.get(CLAIM_ROLES).forEach(
|
// Iterate of the "roles" claim inside the resource claims
|
||||||
// Add the role to the granted authority prefixed with ROLE_ and the name of the resource
|
resourceClaims
|
||||||
role -> grantedAuthorities.add(new SimpleGrantedAuthority(PREFIX_RESOURCE_ROLE + resource + "_" + role))
|
.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;
|
return grantedAuthorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class MyinpulseApplicationTests {
|
class MyinpulseApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user