Skip to content

Commit

Permalink
Merge branch 'development' into feature/test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
arnedierick authored Mar 4, 2024
2 parents 023c86c + cf6b6b1 commit ec54edf
Show file tree
Hide file tree
Showing 76 changed files with 3,510 additions and 198 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# UGent-6


WIP (ik ga korte uitleg schrijven hoe je dit lokaal kan opzetten)
# dependencies
docker compose
https://github.com/SELab-2/UGent-6/wiki
17 changes: 13 additions & 4 deletions backend/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
COPY build/libs/*T.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
FROM gradle:jdk17 AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon

FROM eclipse-temurin:17

EXPOSE 8080

RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar
ENTRYPOINT ["java", "-jar","/app/spring-boot-application.jar"]
6 changes: 4 additions & 2 deletions backend/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
Expand All @@ -19,7 +19,6 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
runtimeOnly 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand All @@ -33,7 +32,10 @@ dependencies {
implementation 'com.auth0:java-jwt:3.18.2'
implementation 'com.auth0:jwks-rsa:0.18.0'
implementation 'javax.servlet:javax.servlet-api:4.0.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.postgresql:postgresql'

implementation "org.springframework.boot:spring-boot-devtools"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
@SpringBootApplication
public class PidgeonApplication {

@RequestMapping("/")
public String home(){
return "hello world form spring!";
}

public static void main(String[] args) {
SpringApplication.run(PidgeonApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class AuthConfig {

@Value("${azure.activedirectory.tenant-id}")
Expand All @@ -18,13 +21,13 @@ public FilterRegistrationBean<JwtAuthenticationFilter> filterRegistrationBean()
System.out.println("tenantId: " + tenantId);
FilterRegistrationBean<JwtAuthenticationFilter> filter = new FilterRegistrationBean<>();
filter.setFilter(new JwtAuthenticationFilter(tenantId));
filter.addUrlPatterns("/api/*");
filter.addUrlPatterns("/api/ietswatiknietwiltesten");
return filter;
}

@Bean
SecurityFilterChain web(HttpSecurity http) throws Exception {
http
public SecurityFilterChain web(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().permitAll()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
public JwtAuthenticationFilter(String tenantId)
{
try {
logger.info("tenantId: " + tenantId);

provider = new UrlJwkProvider(new URL("https://login.microsoftonline.com/"+tenantId+"/discovery/v2.0/keys"));
} catch (MalformedURLException e) {
e.printStackTrace();
Expand All @@ -55,11 +57,18 @@ protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request,
algorithm.verify(jwt);// if the token signature is invalid, the method will throw SignatureVerificationException

// get the data from the token
String name = jwt.getClaim("name").asString();
String email = jwt.getClaim("email").asString();
String displayName = jwt.getClaim("name").asString();
String firstName = jwt.getClaim("given_name").asString();
String lastName = jwt.getClaim("family_name").asString();
String email = jwt.getClaim("unique_name").asString();
List<String> groups = jwt.getClaim("groups").asList(String.class);
String oid = jwt.getClaim("oid").asString();
User user = new User(name, email, groups, oid);

// print full object
//logger.info(jwt.getClaims());


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

Auth authUser = new Auth(user, new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(authUser);
Expand All @@ -73,8 +82,6 @@ protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request,

response.setStatus(HttpStatus.UNAUTHORIZED.value()); // Forbidden
}
logger.info("Token: " + token);

} else {
logger.warn("No token found!");
response.setStatus(HttpStatus.UNAUTHORIZED.value()); // Unauthorized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package com.ugent.pidgeon.controllers;
import com.ugent.pidgeon.model.Auth;
import com.ugent.pidgeon.model.User;
import com.ugent.pidgeon.postgre.repository.UserRepository;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthTestController {

@Autowired
private UserRepository userRepository;

@GetMapping("/api/test")
public User testApi(HttpServletRequest request, Auth auth) {
return auth.getUser();
}

@PostMapping("/api/test2")
public String postTest(){
return "Post test succeeded!";
}

@GetMapping("/ping")
public String ping() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.ugent.pidgeon.controllers;

import com.ugent.pidgeon.postgre.models.CourseEntity;
import com.ugent.pidgeon.postgre.models.GroupClusterEntity;
import com.ugent.pidgeon.postgre.models.ProjectEntity;
import com.ugent.pidgeon.postgre.models.UserEntity;
import com.ugent.pidgeon.postgre.repository.CourseRepository;
import com.ugent.pidgeon.postgre.repository.GroupClusterRepository;
import com.ugent.pidgeon.postgre.repository.ProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class JpaCourseController {
@Autowired
private CourseRepository courseRepository;

@Autowired
private GroupClusterRepository groupClusterRepository;

@Autowired
private ProjectRepository projectRepository;

@GetMapping("/api/courses")
public String getCourses() {
StringBuilder res = new StringBuilder();
for (CourseEntity course : courseRepository.findAll()) {
res.append(course.getName()).append(" with users: ");
for (CourseRepository.UserWithRelation user : courseRepository.findUsersByCourseId(course.getId())) {
UserEntity userEntity = user.getUser();
String relation = user.getRelation();
res.append(userEntity.getName()).append("(").append(relation).append("), ");
}
res.append("- with group clusters:");
for (GroupClusterEntity groupcluster: groupClusterRepository.findByCourseId(course.getId())) {
res.append(groupcluster.getName()).append(" (").append(groupcluster.getGroupAmount()).append("), ");
}
res.append("- with projects:");
for (ProjectEntity project: projectRepository.findByCourseId(course.getId())) {
res.append(project.getName()).append(", ");
}
res.append("|\n");
}

return res.toString();
}

// @GetMapping("/api/course")
// public String addCourse(String name, String description) {
// CourseEntity course = new CourseEntity("test", "added to test creating with contstructing");
// course.setId(1);
// courseRepository.save(course);
// return "Course added";
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.ugent.pidgeon.controllers;

import com.ugent.pidgeon.postgre.models.GroupEntity;
import com.ugent.pidgeon.postgre.models.GroupFeedbackEntity;
import com.ugent.pidgeon.postgre.models.SubmissionEntity;
import com.ugent.pidgeon.postgre.models.UserEntity;
import com.ugent.pidgeon.postgre.repository.GroupFeedbackRepository;
import com.ugent.pidgeon.postgre.repository.GroupRepository;
import com.ugent.pidgeon.postgre.repository.SubmissionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class JpaGroupController {

@Autowired
private GroupRepository groupRepository;

@Autowired
private GroupFeedbackRepository groupFeedbackRepository;

@Autowired
SubmissionRepository submissionRepository;

@GetMapping("/api/groups")
public List<String> getGroups() {
List<String> res = new ArrayList<>();
for (GroupEntity group : groupRepository.findAll()) {
StringBuilder groupString = new StringBuilder();
groupString.append(group.getName()).append("-with users: ");
for (UserEntity user : groupRepository.findCourseUsersByGroupId(group.getId())) {
groupString.append(user.getName()).append(", ");
}
List<Long> projectIds = groupRepository.findProjectsByGroupId(group.getId());
groupString.append("-with grades: ");
for (long projectId : projectIds) {
GroupFeedbackEntity feedback = groupFeedbackRepository.findByGroupIdAndProjectId(group.getId(), projectId);
groupString.append(feedback.getGrade()).append(", ");
}
groupString.append("-with submissions: ");
for (long projectId : projectIds) {
for (SubmissionEntity submission : submissionRepository.findByGroupIdAndProjectId(group.getId(), projectId)) {
groupString.append(submission.getSubmissionTime()).append(", ");
}
}
groupString.append("|");
res.add(groupString.toString());
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ugent.pidgeon.controllers;

import com.ugent.pidgeon.postgre.models.DeadlineEntity;
import com.ugent.pidgeon.postgre.models.ProjectEntity;
import com.ugent.pidgeon.postgre.models.TestEntity;
import com.ugent.pidgeon.postgre.repository.ProjectRepository;
import com.ugent.pidgeon.postgre.repository.TestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
public class JpaProjectController {
@Autowired
private ProjectRepository projectRepository;

@Autowired
private TestRepository testRepository;

@GetMapping("/api/projects")
public List<String> getProjects() {
List<String> res = new ArrayList<>();
for (ProjectEntity project : projectRepository.findAll()) {
StringBuilder projectString = new StringBuilder(project.getName());
Optional<TestEntity> test = testRepository.findById(project.getId());
test.ifPresent(testEntity -> projectString.append(" with test: ").append(testEntity.getId()));
projectString.append(" with deadlines: ");
for (DeadlineEntity deadline : project.getDeadlines()) {
projectString.append(deadline.getDeadline());
}
res.add(projectString.toString());
}
return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ugent.pidgeon.controllers;

import com.ugent.pidgeon.postgre.models.FileEntity;
import com.ugent.pidgeon.postgre.models.SubmissionEntity;
import com.ugent.pidgeon.postgre.repository.FileRepository;
import com.ugent.pidgeon.postgre.repository.SubmissionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
public class JpaSubmissionController {
@Autowired
private SubmissionRepository submissionRepository;

@Autowired
private FileRepository fileRepository;

@GetMapping("/api/submissions")
public List<String> getSubmissions() {
List<String> res = new ArrayList<>();
for (SubmissionEntity submission : submissionRepository.findAll()) {
StringBuilder submissionString = new StringBuilder();
submissionString.append(submission.getSubmissionTime()).append(" with files: ");
Optional<FileEntity> file = fileRepository.findById(submission.getFileId());
file.ifPresent(fileEntity -> submissionString.append(fileEntity.getName()).append(", "));

submissionString.append("|");
res.add(submissionString.toString());
}
return res;
}

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

import com.ugent.pidgeon.postgre.models.CourseEntity;
import com.ugent.pidgeon.postgre.models.types.CourseRelation;
import com.ugent.pidgeon.postgre.models.UserEntity;
import com.ugent.pidgeon.postgre.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JpaUserController {
@Autowired
private UserRepository userRepository;

Logger logger = LoggerFactory.getLogger(JpaUserController.class);
@GetMapping("/api/users")
public String getUsers() {
StringBuilder res = new StringBuilder();
for (UserEntity user : userRepository.findAll()) {
res.append(user.getName()).append("(").append(user.getRole().toString()).append(") in courses: ");
for (UserRepository.CourseWithRelation course : userRepository.findCoursesByUserId(user.getId())) {
CourseEntity courseEntity = course.getCourse();
CourseRelation courseRelation = course.getRelation();
res.append(courseEntity.getName()).append("(").append(courseRelation.toString()).append("), ");
}
res.append("\n");
}

return res.toString();
}
}
Loading

0 comments on commit ec54edf

Please sign in to comment.