From 12a91236bf3cdd508c95d73066840ef7c5fe3e8d Mon Sep 17 00:00:00 2001 From: harryTheWizzard <hp324245@gmail.com> Date: Tue, 18 Apr 2023 10:53:40 +0200 Subject: [PATCH] Cors + folder structure --- .gitignore | 33 ++++++++++++ .idea/compiler.xml | 3 ++ .idea/misc.xml | 2 +- .../v233/SmartMat/SmartMatApplication.java | 3 ++ .../v233/SmartMat/config/CorsConfig.java | 51 ++++++++++++++++++ .../v233/SmartMat/config/SecurityConfig.java | 4 ++ .../config/properties/DomainProperty.java | 7 +++ .../SmartMat/controller/UserController.java | 4 ++ .../idatt2016/v233/SmartMat/entity/User.java | 4 ++ .../v233/SmartMat/repository/temp.java | 4 ++ .../v233/SmartMat/service/tempService.java | 4 ++ .../v233/SmartMat/util/tempUtil.java | 4 ++ src/main/resources/application.properties | 2 +- target/classes/application.properties | 2 +- .../v233/SmartMat/SmartMatApplication.class | Bin 769 -> 933 bytes 15 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/config/SecurityConfig.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/config/properties/DomainProperty.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/controller/UserController.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/entity/User.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/repository/temp.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/service/tempService.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/util/tempUtil.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fd860ebf..372e166d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,17 +2,20 @@ <project version="4"> <component name="CompilerConfiguration"> <annotationProcessing> + <profile default="true" name="Default" enabled="true" /> <profile name="Maven default annotation processors profile" enabled="true"> <sourceOutputDir name="target/generated-sources/annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <outputRelativeToContentRoot value="true" /> <module name="SmartMat" /> + <module name="backend" /> </profile> </annotationProcessing> </component> <component name="JavacSettings"> <option name="ADDITIONAL_OPTIONS_OVERRIDE"> <module name="SmartMat" options="-parameters" /> + <module name="backend" options="-parameters" /> </option> </component> </project> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ba18a6c3..14613fe5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,5 +8,5 @@ </list> </option> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" /> + <component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" /> </project> \ No newline at end of file diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.java index dedd771a..d8ee44d4 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.java @@ -1,9 +1,12 @@ package ntnu.idatt2016.v233.SmartMat; +import ntnu.idatt2016.v233.SmartMat.config.properties.DomainProperty; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication +@EnableConfigurationProperties({DomainProperty.class}) public class SmartMatApplication { public static void main(String[] args) { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java new file mode 100644 index 00000000..13829842 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java @@ -0,0 +1,51 @@ +package ntnu.idatt2016.v233.SmartMat.config; + +import lombok.AllArgsConstructor; +import ntnu.idatt2016.v233.SmartMat.config.properties.DomainProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.util.Arrays; + +/** + * Cors configuration for application + * @author Birk + * @version 1.0 + * + */ +@Configuration +@AllArgsConstructor +public class CorsConfig { + /** + * The frontend domain properties. + */ + private final DomainProperty domainProperty; + + /** + * Configures CORS for the application. + * @return {@link WebMvcConfigurer} with CORS configuration + */ + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins(domainProperty.domain()) + .allowedMethods(Arrays.asList( + HttpMethod.GET.name(), + HttpMethod.POST.name(), + HttpMethod.PUT.name(), + HttpMethod.DELETE.name(), + HttpMethod.OPTIONS.name() + ).toArray(String[]::new)) + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(3600); + } + }; + } +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/config/SecurityConfig.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/SecurityConfig.java new file mode 100644 index 00000000..f3b99a83 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/SecurityConfig.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.config; + +public class SecurityConfig { +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/config/properties/DomainProperty.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/properties/DomainProperty.java new file mode 100644 index 00000000..7a3b7170 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/properties/DomainProperty.java @@ -0,0 +1,7 @@ +package ntnu.idatt2016.v233.SmartMat.config.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "domain") +public record DomainProperty (String domain){ +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/UserController.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/UserController.java new file mode 100644 index 00000000..2e5af8df --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/UserController.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.controller; + +public class UserController { +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/User.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/User.java new file mode 100644 index 00000000..57104609 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/User.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.entity; + +public class User { +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/temp.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/temp.java new file mode 100644 index 00000000..15755905 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/temp.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.repository; + +public class temp { +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/tempService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/tempService.java new file mode 100644 index 00000000..f1d8e1e6 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/tempService.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.service; + +public class tempService { +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/tempUtil.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/tempUtil.java new file mode 100644 index 00000000..73e2d53a --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/tempUtil.java @@ -0,0 +1,4 @@ +package ntnu.idatt2016.v233.SmartMat.util; + +public class tempUtil { +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b137891..217b42da 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +domain.domain = "localhost:5334"; \ No newline at end of file diff --git a/target/classes/application.properties b/target/classes/application.properties index 8b137891..217b42da 100644 --- a/target/classes/application.properties +++ b/target/classes/application.properties @@ -1 +1 @@ - +domain.domain = "localhost:5334"; \ No newline at end of file diff --git a/target/classes/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.class b/target/classes/ntnu/idatt2016/v233/SmartMat/SmartMatApplication.class index b7e7eb2567cd5612ba303cd4a5074e5b982795be..08daf566bdd0df641c7e811e2467f06974cf8deb 100644 GIT binary patch delta 165 zcmZo<TguLL>ff$?3=9ko3<?{$JegP+8N7Wa)=SzZ=jWBAR+Q)$6y+DB7L{bC7VEp_ zB_`#hI_Kx5Wu})FC6;97=LNuJtr;0u%Mx=+QyCfTeJ0w=DgX@tszcWAlAoKH3DZ(J sIf%)ek!x}nlRYah13LrX<a10q!a@v83^G91$TBc8$VD?SCNszb0Q~PU(EtDd delta 47 zcmZ3=-pIyv>ff$?3=9ko46+-!JeelHW-?=BpRB}e&&tKX&cHo6jai4Cje(IthJgV9 DJgEu^ -- GitLab