From 1e65f834f5f24c71b22f55887705787001e68e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Fri, 27 Sep 2024 12:16:41 +0200 Subject: [PATCH] PMT-14: Add Spring Security with Oauth2 --- build.gradle.kts | 6 ++++++ src/main/resources/application.properties | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 858086b..d8e2076 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,6 +48,11 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-validation") implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-oauth2-client") + implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server") + + // Postgres runtimeOnly("org.postgresql:postgresql") // Lombok @@ -57,6 +62,7 @@ dependencies { // Test testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-testcontainers") + testImplementation("org.springframework.security:spring-security-test") testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:postgresql") testRuntimeOnly("org.junit.platform:junit-platform-launcher") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 676a110..4fc64fe 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,4 +6,15 @@ server.port=8080 spring.datasource.url=jdbc:postgresql://localhost:5432/pmt spring.datasource.username=pmt_user spring.datasource.password=pmt123 -spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file +spring.jpa.hibernate.ddl-auto=create-drop + +# JWT Auth +spring.security.oauth2.client.registration.keycloak.client-id=employee-management-service +spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.keycloak.scope=openid +spring.security.oauth2.client.provider.keycloak.issuer-uri=https://keycloak.szut.dev/auth/realms/szut +spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username +spring.security.oauth2.resourceserver.jwt.issuer-uri=https://keycloak.szut.dev/auth/realms/szut + +# Debugging +logging.level.org.springframework.security=DEBUG \ No newline at end of file