From d3755984d9b0369161ae55618dfc4f04f9444df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Mon, 30 Sep 2024 09:08:16 +0200 Subject: [PATCH] PMT-9: Move Template to Config Bean, so it can be reused by Generated Code --- src/main/java/de/hmmh/pmt/Config.java | 13 +++++++++++++ src/main/java/de/hmmh/pmt/auth/JWT.java | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hmmh/pmt/Config.java diff --git a/src/main/java/de/hmmh/pmt/Config.java b/src/main/java/de/hmmh/pmt/Config.java new file mode 100644 index 0000000..392d80a --- /dev/null +++ b/src/main/java/de/hmmh/pmt/Config.java @@ -0,0 +1,13 @@ +package de.hmmh.pmt; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class Config { + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/src/main/java/de/hmmh/pmt/auth/JWT.java b/src/main/java/de/hmmh/pmt/auth/JWT.java index 5360d62..a1f26c3 100644 --- a/src/main/java/de/hmmh/pmt/auth/JWT.java +++ b/src/main/java/de/hmmh/pmt/auth/JWT.java @@ -2,6 +2,7 @@ package de.hmmh.pmt.auth; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -25,7 +26,8 @@ public class JWT implements LogoutHandler { private static final String OIDC_LOGOUT_ROUTE = "/protocol/openid-connect/logout"; private static final String OIDC_TOKEN_HINT_QUERY_PARAMETER = "id_token_hin"; - private final RestTemplate template = new RestTemplate(); + @Autowired + private RestTemplate template; @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {