Skip to content

Commit

Permalink
Final merge 🎉
Browse files Browse the repository at this point in the history
Final merge 🎉
  • Loading branch information
AWerbrouck authored May 23, 2024
2 parents 5002437 + 36a3514 commit 88e3ab9
Show file tree
Hide file tree
Showing 386 changed files with 31,560 additions and 7,156 deletions.
13 changes: 13 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
client-secret=<your-client-secret>
client-id=<your-client-id>
tenant-id=<your-tenant-id>
PGU=<your-postgres-user>
PGP=<your-postgres-password>
POSTGRES_USER=${PGU}
URI=<your-uri>
EXPRESS_SESSION_SECRET=<your-express-session-secret>
PORT=<your-port>
ENVIRONMENT=<your-environment>
DB_HOST=<your-db-host>
DB_PORT=<your-db-port>
DB_NAME=<your-db-name>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: running test with github actions
name: Backend Testing
on: pull_request

jobs:
Expand All @@ -11,4 +11,4 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 17
- run: gradle test -p backend/app/
- run: gradle unitTests -p backend/app/
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
backend/web-bff/App/.env.dev

HELP.md
.gradle
build/
Expand Down Expand Up @@ -36,7 +38,17 @@ out/
.vscode/
backend/app/data/*
backend/data/*
backend/tmp/*
backend/app/tmp/*
data/*

### Secrets ###
backend/app/src/main/resources/application-secrets.properties
docker.env


./startBackend.sh
startBackend.sh

/.env
backend/web-bff/App/.env
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# UGent-6
![badge](https://github.com/SELab-2/UGent-6/actions/workflows/backend_testing.yaml/badge.svg)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

<img src="https://github.com/SELab-2/UGent-6/assets/15960534/bf16e825-2d96-46af-8dc0-12ec03ba545b" width="700">



| Student | E-mailadres |
----------------------------------------------------|-----------------------------|
| [Matthias Vaneyck](https://github.com/Matthias-VE) | [email protected] |
| [Inti Danschutter](https://github.com/Aqua-sc) | [email protected] |
| [Arthur Werbrouck](https://github.com/AWerbrouck) | [email protected] |
| [Arne Dierick](https://github.com/arnedierick) | [email protected] |
| [Wout Verdyck](https://github.com/usserwoutV2) | [email protected] |
| [Floris Kornelis Van Dijken](https://github.com/badduck32) | [email protected] |
| [Tristan Verbeken](https://github.com/TR1VER) | [email protected]|


[wiki documentation](https://github.com/SELab-2/UGent-6/wiki)

[api documentation](https://apidog.com/apidoc/project-467959)
## Tree view of the project

- backend
- app
- src
- main/java/com/ugent/pidgeon
- auth (Authentication related logic)
- config (Configuration settings and beans)
- controllers (Web controllers for handling requests)
- model (models for testing submissions)
- json (request/response bodies)
- postgre (Database models and repositories)
- util (Utility classes and helpers)
- resources (Configuration files, property files etc.)
- test/java/com/ugent/pidgeon (Unit and integration tests)
- database (Database schemas and scripts)
- db (Database related scripts)
- web-bff (Express webserver that manages user authentication with cookie sessions)

- frontend
- public (Static files like images, fonts, and `index.html`)
- src
- @types (TypeScript type definitions)
- assets (Static assets like images and logos used in the app)
- components (Reusable UI components)
- common (Commonly used components across the application)
- forms (Form components, including project form tabs)
- layout (Components related to layout such as navbars and sidebars)
- hooks (Custom React hooks)
- i18n (Internationalization setup, including language files)
- pages (Component structure for each page)
- providers (Context providers for state management)
- router (Routing and path management)
- theme (Styling themes and fonts)
- util (Utility functions and helpers such as our `apiFetch`)

https://github.com/SELab-2/UGent-6/wiki
34 changes: 0 additions & 34 deletions app.conf

This file was deleted.

2 changes: 2 additions & 0 deletions backend/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*T.jar /app/spring-boot-application.jar
ENTRYPOINT ["java", "-jar","/app/spring-boot-application.jar"]

#@Relevant
Empty file added backend/app/artifactPath
Empty file.
41 changes: 35 additions & 6 deletions backend/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-config'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
Expand All @@ -44,13 +43,43 @@ dependencies {
implementation "org.springframework.boot:spring-boot-devtools"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.mockito:mockito-junit-jupiter:4.0.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
testImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
}

// tasks.named('test',Test) {
// useJUnitPlatform()
// maxHeapSize = '1G'

// testLogging {
// events "passed"

// }
// }

task unitTests (type: Test){

exclude '**/docker'

useJUnitPlatform()
maxHeapSize = '1G'

testLogging {
events "passed"
}

}

tasks.named('test',Test) {
task allTest (type: Test) {

include '**'
useJUnitPlatform()
maxHeapSize = '1G'
maxHeapSize = '1G'


testLogging {
events "passed"
}
testLogging {
events "passed"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ugent.pidgeon;

import java.time.OffsetDateTime;

public record ApiErrorReponse(OffsetDateTime timestamp, int status, String error, String message, String path) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.ugent.pidgeon;


import jakarta.servlet.http.HttpServletRequest;
import java.time.OffsetDateTime;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@ControllerAdvice
public class GlobalErrorHandler {



private void logError(Exception ex) {
Logger logger = Logger.getGlobal();
// Log the error with the logger
logger.log(Level.SEVERE, ex.getMessage(), ex);
}

/* Gets thrown when a invalid json is sent */
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ApiErrorReponse> handleHttpMessageNotReadableException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.BAD_REQUEST;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(),status.getReasonPhrase(),
"Unable to process the request due to invalid or missing data. Please ensure the request body is properly formatted and all required fields are provided.", path));
}

/* Gets thrown when endpoint doesn't exist */
@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<ApiErrorReponse> handleNoHandlerFoundException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.NOT_FOUND;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(), status.getReasonPhrase(),
"Resource/endpoint doesn't exist", path));
}

@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<ApiErrorReponse> handleNoResourceFoundException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.NOT_FOUND;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(), status.getReasonPhrase(),
"Resource/endpoint doesn't exist", path));
}

/* Gets thrown when the method is not allowed */
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ApiErrorReponse> handleMethodNotSupportedException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.METHOD_NOT_ALLOWED;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(), status.getReasonPhrase(),
"Method not supported", path));
}

/* Gets thrown when u path variable is of the wrong type */
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<ApiErrorReponse> handleMethodArgumentTypeMismatchException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.BAD_REQUEST;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(), status.getReasonPhrase(),
"Invalid url argument type", path));
}

/* Gets thrown when an unexpected error occurs */
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiErrorReponse> handleException(HttpServletRequest request, Exception ex) {
logError(ex);
String path = request.getRequestURI();
HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
return ResponseEntity.status(status).body(new ApiErrorReponse(OffsetDateTime.now(), status.value(), status.getReasonPhrase(),
"An unexpected error occurred", path));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

/**
* This class extends OncePerRequestFilter to provide a filter that decodes and verifies JWT tokens.
Expand Down Expand Up @@ -83,6 +81,7 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res
String lastName;
String email;
String oid;
String studentnumber;

String version = jwt.getClaim("ver").asString();

Expand All @@ -92,21 +91,21 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res
lastName = jwt.getClaim("family_name").asString();
email = jwt.getClaim("unique_name").asString();
oid = jwt.getClaim("oid").asString();
studentnumber = jwt.getClaim("ugentStudentID").asString();
} else if (version.startsWith("2.0")) {
displayName = jwt.getClaim("name").asString();
lastName = jwt.getClaim("surname").asString();
firstName = displayName.replace(lastName, "").strip();
email = jwt.getClaim("mail").asString();
oid = jwt.getClaim("oid").asString();
studentnumber = jwt.getClaim("ugentStudentID").asString();
} else {
throw new JwkException("Invalid OAuth version");
}
// print full object
// logger.info(jwt.getClaims());


logger.info(jwt.getClaims());

User user = new User(displayName, firstName,lastName, email, oid);
User user = new User(displayName, firstName,lastName, email, oid, studentnumber);

Auth authUser = new Auth(user, new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(authUser);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ugent.pidgeon.auth;

import com.ugent.pidgeon.postgre.models.types.UserRole;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
Loading

0 comments on commit 88e3ab9

Please sign in to comment.