add security to frontend
This commit is contained in:
104
README.md
104
README.md
@@ -1,95 +1,27 @@
|
||||
# hackathon
|
||||
|
||||
In order to launch any task (Maven compile, clean install ...) be sure to launch the Docker compose in the root directory with :
|
||||
## Pour lancer
|
||||
sudo docker compose up -d
|
||||
|
||||
docker compose up
|
||||
### back_end
|
||||
cd back_end
|
||||
|
||||
## Getting started
|
||||
#### Pour installer java 17
|
||||
sudo apt install openjdk-17-jdk
|
||||
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
||||
export PATH=$JAVA_HOME/bin:$PATH
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
#### Clean
|
||||
mvn clean install
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
#### Pour lancer back_end
|
||||
mvn spring-boot:run
|
||||
|
||||
## Add your files
|
||||
### front_end
|
||||
cd front_end
|
||||
|
||||
* [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
||||
#### Install
|
||||
npm install
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab2.istic.univ-rennes1.fr/tuvu/hackathon.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
* [Set up project integrations](https://gitlab2.istic.univ-rennes1.fr/tuvu/hackathon/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
* [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
* [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
* [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
* [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
||||
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
* [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
#### Lancer front_end
|
||||
npm start
|
||||
@@ -1,9 +0,0 @@
|
||||
services:
|
||||
postgres:
|
||||
image: 'postgres:latest'
|
||||
environment:
|
||||
- 'POSTGRES_DB=mydatabase'
|
||||
- 'POSTGRES_PASSWORD=secret'
|
||||
- 'POSTGRES_USER=myuser'
|
||||
ports:
|
||||
- '5432'
|
||||
@@ -11,7 +11,7 @@
|
||||
<groupId>hackathon</groupId>
|
||||
<artifactId>FrisbYEE</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<packaging>jar</packaging>
|
||||
<name>FrisbYEE</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<url/>
|
||||
@@ -35,60 +35,22 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security-oauth2-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security-oauth2-resource-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf.extras</groupId>
|
||||
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security-oauth2-client-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security-oauth2-resource-server-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -98,8 +60,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.32</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
|
||||
@@ -9,13 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import hackathon.FrisbYEE.jpa.dto.ActiviteDTO;
|
||||
@@ -32,19 +32,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/athletes")
|
||||
@Controller
|
||||
@RequestMapping("/athlete")
|
||||
public class AthleteResource {
|
||||
@Autowired
|
||||
private AthleteDAO athleteDAO;
|
||||
private SessionDAO sessionDAO;
|
||||
|
||||
|
||||
@Operation(summary = "Crée un Athlète avec les informations fournies")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = AthleteDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||
})
|
||||
|
||||
@PostMapping("/create")
|
||||
@@ -57,9 +54,7 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère tous les athlètes")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupère tous les athlètes",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = List.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupère tous les athlètes", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class)))
|
||||
})
|
||||
@GetMapping("/all")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')")
|
||||
@@ -74,9 +69,7 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère l'athlète ayant l'identifiant correspondant")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = AthleteDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')")
|
||||
@@ -88,13 +81,11 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = AthleteDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ADMIN') or #id == principal.id")
|
||||
public ResponseEntity<AthleteDTO> update(@PathVariable Integer id,@RequestBody AthleteDTO dto) {
|
||||
public ResponseEntity<AthleteDTO> update(@PathVariable Integer id, @RequestBody AthleteDTO dto) {
|
||||
try {
|
||||
Athlete athlete = athleteDAO.findById(id).get();
|
||||
athlete.setName(dto.getName());
|
||||
@@ -114,16 +105,14 @@ public class AthleteResource {
|
||||
|
||||
athleteDAO.save(athlete);
|
||||
return ResponseEntity.ok(mapToDTO(athlete));
|
||||
}catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Supprime l'athlète ayant l'identifiant correspondant")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Suppression effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = AthleteDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Suppression effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasRole('Admin')")
|
||||
@@ -155,19 +144,17 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère les sessions correspondant à l'athlète donné")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = SessionDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
||||
})
|
||||
@GetMapping("/athlete/{id}/session")
|
||||
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
||||
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
||||
// return pet
|
||||
System.out.println("ID A CHERCHER" + athleteId);
|
||||
java.util.Optional<Athlete> j = athleteDAO.findById(athleteId);
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
List<SessionDTO> athleteSessions = new ArrayList<>();
|
||||
for(Session s : sessions){
|
||||
if(s.getAthletes().contains(j.get())){
|
||||
for (Session s : sessions) {
|
||||
if (s.getAthletes().contains(j.get())) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(s.getId());
|
||||
dto.setName(s.getName());
|
||||
@@ -181,12 +168,10 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère toutes les sessions")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = SessionDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
||||
})
|
||||
@GetMapping("/athletes/session")
|
||||
public List<SessionDTO> getAllSessions() {
|
||||
public List<SessionDTO> getAllSessions() {
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
System.out.println(sessions);
|
||||
List<SessionDTO> sessionDTOs = new ArrayList<>();
|
||||
@@ -202,9 +187,7 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère les activités correspondant à la session donnée")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = ActiviteDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ActiviteDTO.class)))
|
||||
})
|
||||
@GetMapping("/athletes/session/{id}/activities")
|
||||
public List<ActiviteDTO> getActivitiesForSession(@PathVariable Integer id) {
|
||||
@@ -228,9 +211,7 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère toutes les sessions après une date donnée")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = SessionDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
||||
})
|
||||
@GetMapping("/athletes/{id}/session/after/{date}")
|
||||
public List<SessionDTO> getSessionsAfterDate(@PathVariable Integer id, @PathVariable String date) {
|
||||
@@ -242,7 +223,11 @@ public class AthleteResource {
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
List<SessionDTO> filteredSessions = new ArrayList<>();
|
||||
for (Session session : sessions) {
|
||||
if (session.getAthletes().contains(athlete) && session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(date)))) { //WTF toujours sympa les dates
|
||||
if (session.getAthletes().contains(athlete)
|
||||
&& session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(date)))) { // WTF
|
||||
// toujours
|
||||
// sympa les
|
||||
// dates
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(session.getId());
|
||||
dto.setName(session.getName());
|
||||
@@ -257,12 +242,11 @@ public class AthleteResource {
|
||||
|
||||
@Operation(summary = "Récupère les sessions entre deux dates")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(implementation = SessionDTO.class)))
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
||||
})
|
||||
@GetMapping("/athletes/{id}/session/between/{startDate}/{endDate}")
|
||||
public List<SessionDTO> getSessionsBetweenDates(@PathVariable Integer id, @PathVariable String startDate, @PathVariable String endDate) {
|
||||
public List<SessionDTO> getSessionsBetweenDates(@PathVariable Integer id, @PathVariable String startDate,
|
||||
@PathVariable String endDate) {
|
||||
// Récupérer l'athlète par ID
|
||||
java.util.Optional<Athlete> athleteOpt = athleteDAO.findById(id);
|
||||
if (athleteOpt.isPresent()) {
|
||||
@@ -271,7 +255,9 @@ public class AthleteResource {
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
List<SessionDTO> filteredSessions = new ArrayList<>();
|
||||
for (Session session : sessions) {
|
||||
if (session.getAthletes().contains(athlete) && session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(startDate))) && session.getCreneau().isBefore(ChronoLocalDateTime.from(LocalDate.parse(endDate)))) {
|
||||
if (session.getAthletes().contains(athlete)
|
||||
&& session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(startDate)))
|
||||
&& session.getCreneau().isBefore(ChronoLocalDateTime.from(LocalDate.parse(endDate)))) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(session.getId());
|
||||
dto.setName(session.getName());
|
||||
|
||||
@@ -7,12 +7,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/coach")
|
||||
public class CoachResource {
|
||||
@Autowired
|
||||
private CoachDAO coachDAO;
|
||||
@@ -49,7 +52,8 @@ public class CoachResource {
|
||||
public ResponseEntity<CoachDTO> update(@PathVariable Integer id, @RequestBody CoachDTO dto) {
|
||||
Coach coach = coachDAO.findById(id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
if (dto.getName() != null) coach.setName(dto.getName());
|
||||
if (dto.getName() != null)
|
||||
coach.setName(dto.getName());
|
||||
coachDAO.save(coach);
|
||||
CoachDTO updatedDto = mapToDTO(coach);
|
||||
return ResponseEntity.ok(updatedDto);
|
||||
@@ -78,4 +82,3 @@ public class CoachResource {
|
||||
return coach;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/session")
|
||||
|
||||
public class SessionResource {
|
||||
@@ -87,7 +88,7 @@ public class SessionResource {
|
||||
@PreAuthorize("hasRole('Coach')")
|
||||
public ResponseEntity<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {
|
||||
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
||||
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
||||
|
||||
if (dto.getDuree() != null) {
|
||||
session.setDuree(dto.getDuree());
|
||||
|
||||
@@ -6,4 +6,6 @@ spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
|
||||
server.port=8081
|
||||
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8080/realms/Frisbyee_realm
|
||||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri: http://localhost:8080/realms/Frisbyee_realm/protocol/openid-connect/certs
|
||||
@@ -1,12 +1,12 @@
|
||||
services:
|
||||
keycloak:
|
||||
container_name: baeldung-keycloak.openid-provider
|
||||
container_name: baeldung-keycloak
|
||||
image: quay.io/keycloak/keycloak:26.4
|
||||
command:
|
||||
- start-dev
|
||||
- --import-realm
|
||||
ports:
|
||||
- 8080:8080
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./keycloak/:/opt/keycloak/data/import/
|
||||
environment:
|
||||
@@ -16,17 +16,9 @@ services:
|
||||
KC_HOSTNAME_URL: http://localhost:8080
|
||||
KC_HOSTNAME_ADMIN_URL: http://localhost:8080
|
||||
KC_HOSTNAME_STRICT_BACKCHANNEL: true
|
||||
KC_HTTP_RELATIVE_PATH: /
|
||||
KC_HTTP_ENABLED: true
|
||||
KC_HEALTH_ENABLED: true
|
||||
KC_METRICS_ENABLED: true
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
healthcheck:
|
||||
test: ['CMD-SHELL', '[ -f /tmp/HealthCheck.java ] || echo "public class HealthCheck { public static void main(String[] args) throws java.lang.Throwable { System.exit(java.net.HttpURLConnection.HTTP_OK == ((java.net.HttpURLConnection)new java.net.URL(args[0]).openConnection()).getResponseCode() ? 0 : 1); } }" > /tmp/HealthCheck.java && java /tmp/HealthCheck.java http://localhost:8080/auth/health/live']
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
|
||||
postgres:
|
||||
image: postgres:16
|
||||
container_name: frisbyee-postgres
|
||||
@@ -41,22 +33,3 @@ services:
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
version: "3.9"
|
||||
postgres:
|
||||
image: postgres:16
|
||||
container_name: frisbyee-postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_DB: frisbyee
|
||||
POSTGRES_USER: frisbyee_user
|
||||
POSTGRES_PASSWORD: secret
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
version: "3.9"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export const Login =() =>{
|
||||
return(
|
||||
<div>
|
||||
<div>
|
||||
Authenticated : {keycloak.authenticated ? '✅' : '❌'}
|
||||
Authenticated : {keycloak.authenticated ? 'oui' : 'non'}
|
||||
</div>
|
||||
<button onClick={() => keycloak.login()}>
|
||||
Se connecter
|
||||
|
||||
Reference in New Issue
Block a user