From ec70ea55963ceb518593c62e0099264ff9dd00a4 Mon Sep 17 00:00:00 2001
From: Andreas Svanberg <andreass@dsv.su.se>
Date: Mon, 3 Mar 2025 07:32:25 +0100
Subject: [PATCH 1/3] Make session serializable (#121)

When re-deploying the application, or restarting Tomcat, it will attempt to serialize the active sessions to prevent users from getting logged out and losing in-progess work. This requires that all attributes that are stored in the session implement `java.io.Serializable`. Spring stores the entire security context in the session which includes a reference to the principal, and that principal may be of type "WicketControlledPrincipal" and it must therefore be serializable.

## How to test
1. Be on the `develop` branch
2. Make sure session preservation is turned on (in IntelliJ check "Preserve sessions across restarts and redeploys", or read https://tomcat.apache.org/tomcat-10.0-doc/config/manager.html#Persistence_Across_Restarts)
3. Log in as the default admin `dev@localhost`
4. Switch to "Sture Student" under "Admin / Users / Switch user"
5. Restart Tomcat
6. Refresh page and you'll be prompted to log in again
7. Switch to this branch and repeat step 1-6

Reviewed-on: https://gitea.dsv.su.se/DMC/scipro/pulls/121
Reviewed-by: Nico Athanassiadis <nico@dsv.su.se>
Co-authored-by: Andreas Svanberg <andreass@dsv.su.se>
Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
---
 .../se/su/dsv/scipro/war/CurrentUserFromSpringSecurity.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/war/src/main/java/se/su/dsv/scipro/war/CurrentUserFromSpringSecurity.java b/war/src/main/java/se/su/dsv/scipro/war/CurrentUserFromSpringSecurity.java
index 6f209f38aa..3d71fd12a3 100644
--- a/war/src/main/java/se/su/dsv/scipro/war/CurrentUserFromSpringSecurity.java
+++ b/war/src/main/java/se/su/dsv/scipro/war/CurrentUserFromSpringSecurity.java
@@ -4,6 +4,7 @@ import jakarta.inject.Inject;
 import jakarta.inject.Provider;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
+import java.io.Serializable;
 import java.security.Principal;
 import java.util.Collections;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -81,7 +82,7 @@ public class CurrentUserFromSpringSecurity implements AuthenticationContext {
         return authentication.getName();
     }
 
-    private static final class WicketControlledPrincipal implements Principal {
+    private static final class WicketControlledPrincipal implements Principal, Serializable {
 
         private final String username;
 

From a71eeb5e2ce35e38a39dfa9630f39fd41b093859 Mon Sep 17 00:00:00 2001
From: Andreas Svanberg <andreass@dsv.su.se>
Date: Mon, 3 Mar 2025 07:48:46 +0100
Subject: [PATCH 2/3] Fix crash when editing an application period (#117)

Fixes #68

## How to test
1. Log in as admin
2. Go to "Match / Application periods"
3. Click the edit icon (6th column)
4. Click "Save"

Co-authored-by: Nico Athanassiadis <nico@dsv.su.se>
Reviewed-on: https://gitea.dsv.su.se/DMC/scipro/pulls/117
Reviewed-by: Nico Athanassiadis <nico@dsv.su.se>
Co-authored-by: Andreas Svanberg <andreass@dsv.su.se>
Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
---
 .../se/su/dsv/scipro/match/ApplicationPeriod.java    | 12 +++++-------
 .../AdminApplicationPeriodsPanel.java                |  8 +-------
 .../scipro/datatables/target/AddTargetLinkPanel.java |  7 +------
 .../scipro/projectpartner/ProjectPartnerPage.java    |  8 +-------
 4 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java
index 9dc48661d9..b21a586607 100755
--- a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java
+++ b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java
@@ -176,18 +176,16 @@ public class ApplicationPeriod extends DomainObject {
         return Collections.unmodifiableSet(answerSet);
     }
 
-    public void setProjectTypes(Iterable<ProjectType> projectTypes) {
-        this.projectTypes.clear();
+    public void setProjectTypes(Set<ProjectType> projectTypes) {
+        this.projectTypes.removeIf(appt -> !projectTypes.contains(appt.getProjectType()));
         for (ProjectType pt : projectTypes) {
-            this.projectTypes.add(new ApplicationPeriodProjectType(this, pt));
+            if (this.projectTypes.stream().noneMatch(appt -> appt.getProjectType().equals(pt))) {
+                addProjectType(pt);
+            }
         }
     }
 
     public void addProjectType(ProjectType projectType) {
         this.projectTypes.add(new ApplicationPeriodProjectType(this, projectType));
     }
-
-    public void removeProjectType(ProjectType projectType) {
-        this.projectTypes.removeIf(next -> next.getProjectType().equals(projectType));
-    }
 }
diff --git a/view/src/main/java/se/su/dsv/scipro/applicationperiod/AdminApplicationPeriodsPanel.java b/view/src/main/java/se/su/dsv/scipro/applicationperiod/AdminApplicationPeriodsPanel.java
index 307d7858f3..b8bb7d9e76 100755
--- a/view/src/main/java/se/su/dsv/scipro/applicationperiod/AdminApplicationPeriodsPanel.java
+++ b/view/src/main/java/se/su/dsv/scipro/applicationperiod/AdminApplicationPeriodsPanel.java
@@ -123,13 +123,7 @@ public class AdminApplicationPeriodsPanel extends Panel {
                     item.add(
                         new DisplayMultiplesPanel<>(
                             s,
-                            new ListAdapterModel<>(
-                                LambdaModel.of(
-                                    iModel,
-                                    ApplicationPeriod::getProjectTypes,
-                                    ApplicationPeriod::setProjectTypes
-                                )
-                            )
+                            new ListAdapterModel<>(iModel.map(ApplicationPeriod::getProjectTypes))
                         ) {
                             @Override
                             public Component getComponent(String componentId, IModel<ProjectType> t) {
diff --git a/view/src/main/java/se/su/dsv/scipro/datatables/target/AddTargetLinkPanel.java b/view/src/main/java/se/su/dsv/scipro/datatables/target/AddTargetLinkPanel.java
index 2f4d027af5..8c4c98a6d0 100644
--- a/view/src/main/java/se/su/dsv/scipro/datatables/target/AddTargetLinkPanel.java
+++ b/view/src/main/java/se/su/dsv/scipro/datatables/target/AddTargetLinkPanel.java
@@ -22,12 +22,7 @@ public class AddTargetLinkPanel extends Panel {
     public AddTargetLinkPanel(String id, final IModel<ApplicationPeriod> model) {
         super(id, model);
         add(
-            new ListView<>(
-                "list",
-                new ListAdapterModel<>(
-                    LambdaModel.of(model, ApplicationPeriod::getProjectTypes, ApplicationPeriod::setProjectTypes)
-                )
-            ) {
+            new ListView<>("list", new ListAdapterModel<>(model.map(ApplicationPeriod::getProjectTypes))) {
                 @Override
                 protected void populateItem(ListItem<ProjectType> item) {
                     item.add(new Label("pc", item.getModelObject().getName()));
diff --git a/view/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartnerPage.java b/view/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartnerPage.java
index a70588801a..ca3736e027 100755
--- a/view/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartnerPage.java
+++ b/view/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartnerPage.java
@@ -76,13 +76,7 @@ public class ProjectPartnerPage extends AbstractIdeaProjectPage implements MenuH
             }
         );
         final IModel<? extends List<ProjectType>> matchableTypes = getMatchableTypes(
-            new ListAdapterModel<>(
-                LambdaModel.of(
-                    applicationPeriod,
-                    ApplicationPeriod::getProjectTypes,
-                    ApplicationPeriod::setProjectTypes
-                )
-            )
+            new ListAdapterModel<>(applicationPeriod.map(ApplicationPeriod::getProjectTypes))
         );
         panelContainer.add(
             new ListView<>("ads", matchableTypes) {

From 7f9e72484aaf00e1550374af2f644ec33eb0c94c Mon Sep 17 00:00:00 2001
From: Andreas Svanberg <andreass@dsv.su.se>
Date: Mon, 3 Mar 2025 07:59:14 +0100
Subject: [PATCH 3/3] Remove unused javax.inject and jersey-hk2 dependencies
 (#118)

Co-authored-by: Nico Athanassiadis <nico@dsv.su.se>
Reviewed-on: https://gitea.dsv.su.se/DMC/scipro/pulls/118
Reviewed-by: Nico Athanassiadis <nico@dsv.su.se>
Co-authored-by: Andreas Svanberg <andreass@dsv.su.se>
Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
---
 core/pom.xml | 22 ----------------------
 pom.xml      |  7 -------
 2 files changed, 29 deletions(-)

diff --git a/core/pom.xml b/core/pom.xml
index e34cb44596..532b1d4d04 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -23,36 +23,14 @@
         <dependency>
             <groupId>org.glassfish.jersey.core</groupId>
             <artifactId>jersey-client</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.glassfish.hk2.external</groupId>
-                    <artifactId>javax.inject</artifactId>
-                </exclusion>
-            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.media</groupId>
             <artifactId>jersey-media-jaxb</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.glassfish.hk2.external</groupId>
-                    <artifactId>javax.inject</artifactId>
-                </exclusion>
-            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.media</groupId>
             <artifactId>jersey-media-json-jackson</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.glassfish.hk2.external</groupId>
-                    <artifactId>javax.inject</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.jersey.inject</groupId>
-            <artifactId>jersey-hk2</artifactId>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
diff --git a/pom.xml b/pom.xml
index a43a6491cd..1940f2ed25 100755
--- a/pom.xml
+++ b/pom.xml
@@ -295,13 +295,6 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
 
-        <!-- Additional dependencies -->
-        <dependency>
-            <groupId>javax.inject</groupId>
-            <artifactId>javax.inject</artifactId>
-            <version>1</version>
-        </dependency>
-
         <!-- Test stuff -->
         <dependency>
             <groupId>org.junit.jupiter</groupId>