From 60ca3335fc7a51dedea22fcba5ea1f11a97b76ef Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 13:28:13 +0200 Subject: [PATCH 1/8] Add Version changes --- generator-templates/postgres/pom.ftl | 6 +++--- generator-templates/service/Service.ftl | 6 +++--- reacthookspring/pom.xml | 12 +++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/generator-templates/postgres/pom.ftl b/generator-templates/postgres/pom.ftl index 82d7f1c..145be18 100644 --- a/generator-templates/postgres/pom.ftl +++ b/generator-templates/postgres/pom.ftl @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.1 + 3.1.2 de.${app.packageName?lower_case} @@ -18,8 +18,8 @@ UTF-8 UTF-8 - 3.1.1 - 6.0.1 + 3.1.2 + 6.0.8 2.1.0 2.7.4 diff --git a/generator-templates/service/Service.ftl b/generator-templates/service/Service.ftl index ef4b1f8..c491e6e 100755 --- a/generator-templates/service/Service.ftl +++ b/generator-templates/service/Service.ftl @@ -78,7 +78,7 @@ public class ${entity.name}Service implements ServiceInterface<${entity.name}Ent ${entity.name}Entity entityPrev = this.findById(entity.getId()); <#list (oneToManyRelations) as oneToMany> for (${oneToMany.otherEntityName}Entity item : entityPrev.get${oneToMany.relationshipName?cap_first}()) { - ${oneToMany.otherEntityName}Entity existingItem = ${oneToMany.otherEntityName?lower_case}Repository.getById(item.getId()); + ${oneToMany.otherEntityName}Entity existingItem = ${oneToMany.otherEntityName?lower_case}Repository.getReferenceById(item.getId()); existingItem.set${oneToMany.otherEntityRelationshipName?cap_first}(null); this.${oneToMany.otherEntityName?lower_case}Repository.save(existingItem); } @@ -94,13 +94,13 @@ public class ${entity.name}Service implements ServiceInterface<${entity.name}Ent <#list (oneToManyRelations) as oneToMany> if (${oneToMany.relationshipName}ToSave != null && !${oneToMany.relationshipName}ToSave.isEmpty()) { for (${oneToMany.otherEntityName}Entity item : ${oneToMany.relationshipName}ToSave) { - ${oneToMany.otherEntityName}Entity newItem = ${oneToMany.otherEntityName?lower_case}Repository.getById(item.getId()); + ${oneToMany.otherEntityName}Entity newItem = ${oneToMany.otherEntityName?lower_case}Repository.getReferenceById(item.getId()); newItem.set${oneToMany.otherEntityRelationshipName?cap_first}(entity); ${oneToMany.otherEntityName?lower_case}Repository.save(newItem); } } - return this.getRepository().getById(entity.getId()); + return this.getRepository().getReferenceById(entity.getId()); } } diff --git a/reacthookspring/pom.xml b/reacthookspring/pom.xml index 7dc64cb..871a5a7 100644 --- a/reacthookspring/pom.xml +++ b/reacthookspring/pom.xml @@ -1,10 +1,12 @@ - + 4.0.0 org.springframework.boot spring-boot-starter-parent - 3.1.1 + 3.1.3 de.starwit @@ -16,8 +18,8 @@ UTF-8 UTF-8 - 3.1.1 - 6.0.1 + 3.1.3 + 6.0.11 2.1.0 2.7.4 @@ -213,4 +215,4 @@ - + \ No newline at end of file From 5cb7c64facd8caa3a2ef36caca8f5963ddcbf824 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 13:29:05 +0200 Subject: [PATCH 2/8] remove repository annotation --- generator-templates/persistence/EntityRepository.ftl | 1 - 1 file changed, 1 deletion(-) diff --git a/generator-templates/persistence/EntityRepository.ftl b/generator-templates/persistence/EntityRepository.ftl index be9b7ae..c936508 100755 --- a/generator-templates/persistence/EntityRepository.ftl +++ b/generator-templates/persistence/EntityRepository.ftl @@ -21,7 +21,6 @@ import de.${app.packageName?lower_case}.persistence.entity.${entity.name}Entity; /** * ${entity.name} Repository class */ -@Repository public interface ${entity.name}Repository extends JpaRepository<${entity.name}Entity, Long> { <#if entity.relationships??> From 61a1e78558e4f9bebc5236768f9ca64c04e03543 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 13:33:20 +0200 Subject: [PATCH 3/8] remove import for repository annotation --- generator-templates/persistence/EntityRepository.ftl | 1 - 1 file changed, 1 deletion(-) diff --git a/generator-templates/persistence/EntityRepository.ftl b/generator-templates/persistence/EntityRepository.ftl index c936508..e50ad24 100755 --- a/generator-templates/persistence/EntityRepository.ftl +++ b/generator-templates/persistence/EntityRepository.ftl @@ -15,7 +15,6 @@ import org.springframework.data.jpa.repository.JpaRepository; <#if additionalQueries> import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; import de.${app.packageName?lower_case}.persistence.entity.${entity.name}Entity; /** From 9fe69faf7fffe10bfc10f16e9230363590b61a63 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 13:36:43 +0200 Subject: [PATCH 4/8] delete entityManager from test --- generator-templates/persistence/EntityRepositoryTest.ftl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/generator-templates/persistence/EntityRepositoryTest.ftl b/generator-templates/persistence/EntityRepositoryTest.ftl index 06e5f6a..f8bdde7 100755 --- a/generator-templates/persistence/EntityRepositoryTest.ftl +++ b/generator-templates/persistence/EntityRepositoryTest.ftl @@ -8,7 +8,6 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; /** * Tests for ${entity.name}Repository @@ -16,9 +15,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; @DataJpaTest public class ${entity.name}RepositoryTest { - @Autowired - private TestEntityManager entityManager; - @Autowired private ${entity.name}Repository repository; From 9ce888776f6dea485cdcc328f3a89aa04c329859 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 14:23:04 +0200 Subject: [PATCH 5/8] corrected scripts --- .../.github/workflows/buildpublish.yml | 47 +++++++------ .../.github/workflows/codeql-analysis.yml | 70 ------------------- .../.github/workflows/createRelease.yml | 20 +++--- reacthookspring/README.MD | 4 ++ 4 files changed, 43 insertions(+), 98 deletions(-) delete mode 100644 reacthookspring/.github/workflows/codeql-analysis.yml diff --git a/reacthookspring/.github/workflows/buildpublish.yml b/reacthookspring/.github/workflows/buildpublish.yml index 4fce7e7..4ab2c65 100644 --- a/reacthookspring/.github/workflows/buildpublish.yml +++ b/reacthookspring/.github/workflows/buildpublish.yml @@ -2,7 +2,7 @@ name: Build and Publish on: pull_request: - branches: [ develop ] + branches: [ main ] workflow_dispatch: env: @@ -21,6 +21,12 @@ jobs: with: distribution: 'zulu' java-version: 17 + - name: setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + - run: npm --version + - run: node --version - name: npm install run: | if [ -d "webclient/app" ]; then @@ -36,24 +42,25 @@ jobs: with: name: artifact path: application/target/application-0.0.1-SNAPSHOT.jar - - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - github-token: ${{ secrets.GITHUB_TOKEN }} + # - name: Log in to the Container registry + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + # with: + # registry: ${{ env.REGISTRY }} + # username: ${{ github.actor }} + # password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + # - name: Extract metadata (tags, labels) for Docker + # id: meta + # uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + # with: + # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # github-token: ${{ secrets.GITHUB_TOKEN }} + + # - name: Build and push Docker image + # uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + # with: + # context: . + # push: true + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} diff --git a/reacthookspring/.github/workflows/codeql-analysis.yml b/reacthookspring/.github/workflows/codeql-analysis.yml deleted file mode 100644 index a90147c..0000000 --- a/reacthookspring/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ develop] - pull_request: - # The branches below must be a subset of the branches above - branches: [ develop ] - schedule: - - cron: '23 22 * * 2' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java', 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/reacthookspring/.github/workflows/createRelease.yml b/reacthookspring/.github/workflows/createRelease.yml index ef74841..b6ed569 100644 --- a/reacthookspring/.github/workflows/createRelease.yml +++ b/reacthookspring/.github/workflows/createRelease.yml @@ -1,9 +1,6 @@ - name: Create release and tag on: - push: - branches: [ main ] workflow_dispatch: inputs: release-type: # id of input @@ -13,7 +10,7 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + IMAGE_NAME: reacthookspring release-type: ${{ github.event.inputs.release-type }} jobs: @@ -61,6 +58,12 @@ jobs: with: distribution: 'zulu' java-version: 17 + - name: setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + - run: npm --version + - run: node --version - name: npm install run: | if [ -d "webclient/app" ]; then @@ -68,7 +71,7 @@ jobs: npm install --legacy-peer-deps fi - name: Build with Maven - run: mvn -B package -P frontend --file pom.xml + run: mvn clean -B package -P frontend --file pom.xml env: CI: false - name: Upload Maven build artifact @@ -94,9 +97,10 @@ jobs: - name: Build docker image with tag version and push to dockerhub uses: docker/build-push-action@v1 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: starwitorg/reacthookspring + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: ghcr.io/reacthookspring tags: ${{ steps.publish_tag.outputs.tag_name }} path: . dockerfile: ./Dockerfile + diff --git a/reacthookspring/README.MD b/reacthookspring/README.MD index cdcabf7..b77dee8 100755 --- a/reacthookspring/README.MD +++ b/reacthookspring/README.MD @@ -92,3 +92,7 @@ Start the database without keycloak: cd deployment docker-compose -f mysqllocal-docker-compose.yml up ``` + +### Changelog + +During development, you can add commits to change log by using this syntax: https://www.conventionalcommits.org/en/v1.0.0/#examples \ No newline at end of file From fd06cde64362a1bcb9cdcc30dc97fd10f8448e01 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sat, 26 Aug 2023 15:40:52 +0200 Subject: [PATCH 6/8] add new version of react-starwit --- reacthookspring/.github/dependapot.yaml | 22 ++++++++++++++++++++++ reacthookspring/webclient/app/package.json | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 reacthookspring/.github/dependapot.yaml diff --git a/reacthookspring/.github/dependapot.yaml b/reacthookspring/.github/dependapot.yaml new file mode 100644 index 0000000..49ca5af --- /dev/null +++ b/reacthookspring/.github/dependapot.yaml @@ -0,0 +1,22 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "maven" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + target-branch: versionupgrade + - package-ecosystem: "npm" # See documentation for possible values + directory: "/webclient/app" # Location of package manifests + schedule: + interval: "weekly" + target-branch: versionupgrade + - package-ecosystem: "docker" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + target-branch: versionupgrade diff --git a/reacthookspring/webclient/app/package.json b/reacthookspring/webclient/app/package.json index 60b0a2a..bab01fa 100644 --- a/reacthookspring/webclient/app/package.json +++ b/reacthookspring/webclient/app/package.json @@ -9,7 +9,7 @@ "@mui/lab": "^5.0.0-alpha.63", "@mui/material": "^5.0.0", "@mui/styles": "^5.0.0", - "@starwit/react-starwit": "1.0.3", + "@starwit/react-starwit": "1.0.6", "axios": "^0.24.0", "i18next": "^21.0.1", "i18next-browser-languagedetector": "^6.1.2", @@ -55,4 +55,4 @@ "eslint-plugin-react": "^7.29.4", "prop-types": "^15.7.2" } -} +} \ No newline at end of file From 7af004dbabe5a24111a4ed8f3a749d448f8a8ce3 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sun, 27 Aug 2023 14:53:29 +0200 Subject: [PATCH 7/8] changed formatting --- reacthookspring/webclient/app/src/app/App.jsx | 12 +++---- .../app/src/app/assets/themes/ColorTheme.js | 3 +- .../app/src/app/assets/themes/MainTheme.jsx | 2 +- .../src/app/commons/navigation/Navigation.jsx | 14 ++++---- .../navigation/appHeader/AppHeader.jsx | 17 +++++++--- .../sidebarNavigation/SidebarNavigation.jsx | 33 +++++++++---------- reacthookspring/webclient/app/src/index.js | 16 ++++----- 7 files changed, 48 insertions(+), 49 deletions(-) diff --git a/reacthookspring/webclient/app/src/app/App.jsx b/reacthookspring/webclient/app/src/app/App.jsx index f315477..1b95b13 100644 --- a/reacthookspring/webclient/app/src/app/App.jsx +++ b/reacthookspring/webclient/app/src/app/App.jsx @@ -1,13 +1,11 @@ -import React from "react"; -import MainContentRouter from "./MainContentRouter"; import {CssBaseline} from "@mui/material"; import {ErrorHandler} from "@starwit/react-starwit"; -import AppHeader from "./commons/appHeader/AppHeader"; +import React from "react"; import {useTranslation} from "react-i18next"; import {appItems} from "./AppConfig"; -import Navigation from "./commons/navigation/Navigation"; +import MainContentRouter from "./MainContentRouter"; import logo from "./assets/images/logo-white.png"; - +import Navigation from "./commons/navigation/Navigation"; function App() { const {t} = useTranslation(); @@ -16,8 +14,8 @@ function App() { - - + + diff --git a/reacthookspring/webclient/app/src/app/assets/themes/ColorTheme.js b/reacthookspring/webclient/app/src/app/assets/themes/ColorTheme.js index af0f288..e2b78ad 100644 --- a/reacthookspring/webclient/app/src/app/assets/themes/ColorTheme.js +++ b/reacthookspring/webclient/app/src/app/assets/themes/ColorTheme.js @@ -57,7 +57,6 @@ const ColorTheme = createTheme({ overrides: {} - -}) +}); export default ColorTheme; diff --git a/reacthookspring/webclient/app/src/app/assets/themes/MainTheme.jsx b/reacthookspring/webclient/app/src/app/assets/themes/MainTheme.jsx index 4d0c5f4..1e82bf0 100644 --- a/reacthookspring/webclient/app/src/app/assets/themes/MainTheme.jsx +++ b/reacthookspring/webclient/app/src/app/assets/themes/MainTheme.jsx @@ -7,7 +7,7 @@ function MainTheme(props) { {props.children} - ) + ); } export default MainTheme; diff --git a/reacthookspring/webclient/app/src/app/commons/navigation/Navigation.jsx b/reacthookspring/webclient/app/src/app/commons/navigation/Navigation.jsx index 7e347a2..47f8567 100644 --- a/reacthookspring/webclient/app/src/app/commons/navigation/Navigation.jsx +++ b/reacthookspring/webclient/app/src/app/commons/navigation/Navigation.jsx @@ -7,7 +7,6 @@ function Navigation(props) { const {menuItems, switchLength, title, logo} = props; const navigationStyles = NavigationStyles(); - function renderCorrectNavigation() { if (menuItems.length > switchLength) { return ( @@ -16,23 +15,22 @@ function Navigation(props) { {props.children} - ) + ); } return ( <> - + {props.children} - ) + ); } - return( + return (
{renderCorrectNavigation()}
- ) - + ); } Navigation.defaultProps = { @@ -40,6 +38,6 @@ Navigation.defaultProps = { title: "New App", menuItems: [] -} +}; export default Navigation; diff --git a/reacthookspring/webclient/app/src/app/commons/navigation/appHeader/AppHeader.jsx b/reacthookspring/webclient/app/src/app/commons/navigation/appHeader/AppHeader.jsx index 85b16ee..4794394 100644 --- a/reacthookspring/webclient/app/src/app/commons/navigation/appHeader/AppHeader.jsx +++ b/reacthookspring/webclient/app/src/app/commons/navigation/appHeader/AppHeader.jsx @@ -16,20 +16,27 @@ function AppHeader(props) { <> - Logo of lirejarp + Logo of lirejarp {title} -
+
{menuItems.map(item => ( ))} - window.location.href = window.location.origin + window.location.pathname + "logout"}> + + window.location.href = window.location.origin + window.location.pathname + "logout"} + > + + -
+
); } diff --git a/reacthookspring/webclient/app/src/app/commons/navigation/sidebarNavigation/SidebarNavigation.jsx b/reacthookspring/webclient/app/src/app/commons/navigation/sidebarNavigation/SidebarNavigation.jsx index 1407d07..83fcc50 100644 --- a/reacthookspring/webclient/app/src/app/commons/navigation/sidebarNavigation/SidebarNavigation.jsx +++ b/reacthookspring/webclient/app/src/app/commons/navigation/sidebarNavigation/SidebarNavigation.jsx @@ -9,7 +9,6 @@ import { ListItem, ListItemButton, ListItemText, - Stack, Toolbar, Typography } from "@mui/material"; @@ -19,25 +18,23 @@ import {useTranslation} from "react-i18next"; import {useHistory} from "react-router-dom"; function SidebarNavigation(props) { - const headerStyles = HeaderStyles(); const drawerWidth = 240; const {t} = useTranslation(); const history = useHistory(); - return ( - - - theme.zIndex.drawer + 1}}> + + + theme.zIndex.drawer + 1}}> - Logo of lirejarp - - {props.title} - -
+ Logo of lirejarp + + {props.title} + +
history.push("/logout")}> + onClick={() => history.push("/logout")}> - - + + {props.menuItems.map((menuItem, index) => ( history.push(menuItem.link)}> - + ))} @@ -62,11 +59,11 @@ function SidebarNavigation(props) { - + {props.children} - ) + ); } export default SidebarNavigation; diff --git a/reacthookspring/webclient/app/src/index.js b/reacthookspring/webclient/app/src/index.js index ea42528..3c5b7df 100755 --- a/reacthookspring/webclient/app/src/index.js +++ b/reacthookspring/webclient/app/src/index.js @@ -9,14 +9,14 @@ import {SnackbarProvider} from "notistack"; import MainTheme from "./app/assets/themes/MainTheme"; ReactDOM.render(( - - - - - - - - ), + + + + + + + +), document.getElementById("root") ); From 07a840fd09c0b10968aef7be62f4f20ce057efe7 Mon Sep 17 00:00:00 2001 From: witchpou Date: Sun, 27 Aug 2023 15:13:58 +0200 Subject: [PATCH 8/8] supress warnings --- .../application/config/SecurityConfig.java | 76 +++++++++++-------- .../rest/controller/UserController.java | 5 -- reacthookspring/service/pom.xml | 4 +- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/reacthookspring/application/src/main/java/de/starwit/application/config/SecurityConfig.java b/reacthookspring/application/src/main/java/de/starwit/application/config/SecurityConfig.java index 3a3811d..85a23ff 100644 --- a/reacthookspring/application/src/main/java/de/starwit/application/config/SecurityConfig.java +++ b/reacthookspring/application/src/main/java/de/starwit/application/config/SecurityConfig.java @@ -1,10 +1,13 @@ package de.starwit.application.config; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Supplier; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,17 +27,22 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.security.web.csrf.*; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.security.web.csrf.CsrfToken; +import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler; +import org.springframework.security.web.csrf.CsrfTokenRequestHandler; +import org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.filter.OncePerRequestFilter; -import java.io.IOException; -import java.util.*; -import java.util.function.Supplier; - +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; @Profile("auth") @Configuration @@ -47,8 +55,8 @@ public class SecurityConfig { private ClientRegistrationRepository clientRegistrationRepository; LogoutSuccessHandler oidcLogoutSuccessHandler() { - OidcClientInitiatedLogoutSuccessHandler oidcLogoutSuccessHandler = - new OidcClientInitiatedLogoutSuccessHandler(this.clientRegistrationRepository); + OidcClientInitiatedLogoutSuccessHandler oidcLogoutSuccessHandler = new OidcClientInitiatedLogoutSuccessHandler( + this.clientRegistrationRepository); // Sets the location that the End-User's User Agent will be redirected to // after the logout has been performed at the Provider @@ -69,30 +77,30 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { })) .csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) - .csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler()) - ) + .csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler())) .addFilterAfter(new CsrfCookieFilter(), BasicAuthenticationFilter.class) .authorizeHttpRequests(authorize -> authorize .requestMatchers("/**").hasAnyRole("admin", "user", "reader") - .anyRequest().authenticated() - ) - .logout((logout) -> logout + .anyRequest().authenticated()) + .logout(logout -> logout .logoutSuccessHandler(oidcLogoutSuccessHandler()) - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - ) - // Maybe https://stackoverflow.com/questions/74939220/classnotfoundexception-org-springframework-security-oauth2-server-resource-web + .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))) + // Maybe + // https://stackoverflow.com/questions/74939220/classnotfoundexception-org-springframework-security-oauth2-server-resource-web .oauth2Login(Customizer.withDefaults()); return http.build(); } - - // Taken from https://stackoverflow.com/questions/74939220/classnotfoundexception-org-springframework-security-oauth2-server-resource-web + // Taken from + // https://stackoverflow.com/questions/74939220/classnotfoundexception-org-springframework-security-oauth2-server-resource-web @Component @RequiredArgsConstructor static class GrantedAuthoritiesMapperImpl implements GrantedAuthoritiesMapper { + @SuppressWarnings("unchecked") @Override - public Collection mapAuthorities(Collection authorities) { + public Collection mapAuthorities( + Collection authorities) { Set mappedAuthorities = new HashSet<>(); authorities.forEach(authority -> { @@ -106,11 +114,13 @@ public Collection mapAuthorities(Collection> realmAccess = (Map>) userAttributes.get("realm_access"); + final Map> realmAccess = (Map>) userAttributes + .get("realm_access"); final List roles = realmAccess.get("roles"); mappedAuthorities.addAll(roles.stream().map(SimpleGrantedAuthority::new).toList()); @@ -122,10 +132,10 @@ public Collection mapAuthorities(Collection csrfToken) { /* - * Always use XorCsrfTokenRequestAttributeHandler to provide BREACH protection of + * Always use XorCsrfTokenRequestAttributeHandler to provide BREACH protection + * of * the CsrfToken when it is rendered in the response body. */ this.delegate.handle(request, response, csrfToken); @@ -142,9 +153,12 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Sup @Override public String resolveCsrfTokenValue(HttpServletRequest request, CsrfToken csrfToken) { /* - * If the request contains a request header, use CsrfTokenRequestAttributeHandler - * to resolve the CsrfToken. This applies when a single-page application includes - * the header value automatically, which was obtained via a cookie containing the + * If the request contains a request header, use + * CsrfTokenRequestAttributeHandler + * to resolve the CsrfToken. This applies when a single-page application + * includes + * the header value automatically, which was obtained via a cookie containing + * the * raw CsrfToken. */ if (StringUtils.hasText(request.getHeader(csrfToken.getHeaderName()))) { diff --git a/reacthookspring/rest/src/main/java/de/starwit/rest/controller/UserController.java b/reacthookspring/rest/src/main/java/de/starwit/rest/controller/UserController.java index 6824664..55d67ec 100644 --- a/reacthookspring/rest/src/main/java/de/starwit/rest/controller/UserController.java +++ b/reacthookspring/rest/src/main/java/de/starwit/rest/controller/UserController.java @@ -5,9 +5,6 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,8 +13,6 @@ @RequestMapping("${rest.base-path}/user") public class UserController { - private Logger log = LoggerFactory.getLogger(this.getClass()); - @GetMapping(value = "/logout") public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String contextPath = request.getContextPath(); diff --git a/reacthookspring/service/pom.xml b/reacthookspring/service/pom.xml index 7a70252..523713d 100644 --- a/reacthookspring/service/pom.xml +++ b/reacthookspring/service/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 de.starwit