From 194cd5039cec7185e2f6eecff96ebbb04df25766 Mon Sep 17 00:00:00 2001 From: jmpavlec Date: Tue, 21 Mar 2023 12:34:10 +0100 Subject: [PATCH] Update spring boot to 3.x and java to 17 --- .circleci/config.yml | 2 +- pom.xml | 7 +++- .../config/ResourceGatewayConfig.java | 29 +++++++------ .../service/DeviceApiRequestService.java | 14 +++---- .../TokenIntrospectionRequestExecutor.java | 22 ++++------ .../TokenIntrospectionService.java | 6 +-- .../web/ResourcesController.java | 42 ++++++------------- .../resourcegateway/SpringContextTest.java | 10 ++--- 8 files changed, 53 insertions(+), 79 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c44cbb..e1707cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ orbs: context: dev-context executor: name: onegini-build/maven-builder - tag: "11.0" + tag: "17.0-browsers" .component-type-application: &component-type-application component_type: application diff --git a/pom.xml b/pom.xml index c35c6fd..c5eb86c 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ onegini example-resource-gateway - 11 + 17 UTF-8 @@ -38,7 +38,7 @@ 3.2.1 3.2.2 2.0 - 2.7.9 + 3.0.4 @@ -191,6 +191,9 @@ com.google.cloud.tools jib-maven-plugin + + gcr.io/distroless/java17-debian11:nonroot + snapshot.onegini.com/${docker.groupName}/${docker.imageName} ${project.version},${git.commit.id.describe} diff --git a/src/main/java/com/onegini/examples/resourcegateway/config/ResourceGatewayConfig.java b/src/main/java/com/onegini/examples/resourcegateway/config/ResourceGatewayConfig.java index 5ea5ff5..74f4e3d 100644 --- a/src/main/java/com/onegini/examples/resourcegateway/config/ResourceGatewayConfig.java +++ b/src/main/java/com/onegini/examples/resourcegateway/config/ResourceGatewayConfig.java @@ -1,29 +1,28 @@ package com.onegini.examples.resourcegateway.config; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.PropertyNamingStrategy; - @Configuration public class ResourceGatewayConfig { - @Bean - public Jackson2ObjectMapperBuilder jacksonBuilder() { - final Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder(); - b.propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) - .serializationInclusion(JsonInclude.Include.NON_NULL); - return b; - } + @Bean + public Jackson2ObjectMapperBuilder jacksonBuilder() { + final Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder(); + b.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) + .serializationInclusion(JsonInclude.Include.NON_NULL); + return b; + } - @Bean - public RestTemplate restTemplate(final RestTemplateBuilder builder) { - return builder - .build(); - } + @Bean + public RestTemplate restTemplate(final RestTemplateBuilder builder) { + return builder + .build(); + } } diff --git a/src/main/java/com/onegini/examples/resourcegateway/service/DeviceApiRequestService.java b/src/main/java/com/onegini/examples/resourcegateway/service/DeviceApiRequestService.java index be5b2e4..c165738 100644 --- a/src/main/java/com/onegini/examples/resourcegateway/service/DeviceApiRequestService.java +++ b/src/main/java/com/onegini/examples/resourcegateway/service/DeviceApiRequestService.java @@ -1,10 +1,9 @@ package com.onegini.examples.resourcegateway.service; -import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import static org.springframework.http.HttpStatus.OK; - -import javax.annotation.Resource; - +import com.onegini.examples.resourcegateway.config.DeviceApiConfig; +import com.onegini.examples.resourcegateway.model.DeviceList; +import com.onegini.examples.resourcegateway.util.BasicAuthenticationHeaderBuilder; +import jakarta.annotation.Resource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -12,9 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import com.onegini.examples.resourcegateway.config.DeviceApiConfig; -import com.onegini.examples.resourcegateway.model.DeviceList; -import com.onegini.examples.resourcegateway.util.BasicAuthenticationHeaderBuilder; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import static org.springframework.http.HttpStatus.OK; @Service public class DeviceApiRequestService { diff --git a/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionRequestExecutor.java b/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionRequestExecutor.java index a31f4fc..57bce00 100644 --- a/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionRequestExecutor.java +++ b/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionRequestExecutor.java @@ -1,25 +1,19 @@ package com.onegini.examples.resourcegateway.service.tokenintrospection; -import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; - -import javax.annotation.Resource; - -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import com.onegini.examples.resourcegateway.config.TokenServerConfig; +import com.onegini.examples.resourcegateway.model.TokenIntrospectionResult; +import com.onegini.examples.resourcegateway.model.exception.TokenServerException; +import com.onegini.examples.resourcegateway.util.BasicAuthenticationHeaderBuilder; +import jakarta.annotation.Resource; +import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import com.onegini.examples.resourcegateway.config.TokenServerConfig; -import com.onegini.examples.resourcegateway.model.TokenIntrospectionResult; -import com.onegini.examples.resourcegateway.model.exception.TokenServerException; -import com.onegini.examples.resourcegateway.util.BasicAuthenticationHeaderBuilder; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; @Service public class TokenIntrospectionRequestExecutor { diff --git a/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionService.java b/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionService.java index 01f7c7a..8004e4a 100644 --- a/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionService.java +++ b/src/main/java/com/onegini/examples/resourcegateway/service/tokenintrospection/TokenIntrospectionService.java @@ -1,12 +1,10 @@ package com.onegini.examples.resourcegateway.service.tokenintrospection; -import javax.annotation.Resource; - -import org.springframework.stereotype.Service; - import com.onegini.examples.resourcegateway.model.TokenIntrospectionResult; import com.onegini.examples.resourcegateway.model.exception.InvalidAccessTokenException; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; @Service public class TokenIntrospectionService { diff --git a/src/main/java/com/onegini/examples/resourcegateway/web/ResourcesController.java b/src/main/java/com/onegini/examples/resourcegateway/web/ResourcesController.java index fbd2a56..7859916 100644 --- a/src/main/java/com/onegini/examples/resourcegateway/web/ResourcesController.java +++ b/src/main/java/com/onegini/examples/resourcegateway/web/ResourcesController.java @@ -1,43 +1,27 @@ package com.onegini.examples.resourcegateway.web; -import static com.onegini.examples.resourcegateway.service.ScopeValidationService.SCOPE_APPLICATION_DETAILS; -import static com.onegini.examples.resourcegateway.service.ScopeValidationService.SCOPE_READ; -import static com.onegini.examples.resourcegateway.service.ScopeValidationService.SCOPE_WRITE; -import static org.springframework.http.HttpHeaders.AUTHORIZATION; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.web.bind.annotation.RequestMethod.GET; -import static org.springframework.web.bind.annotation.RequestMethod.POST; - -import com.onegini.examples.resourcegateway.model.ApplicationDetails; -import com.onegini.examples.resourcegateway.model.DecoratedUser; -import com.onegini.examples.resourcegateway.model.DeviceList; -import com.onegini.examples.resourcegateway.model.FormDataWithFiles; -import com.onegini.examples.resourcegateway.model.MultipartResponse; -import com.onegini.examples.resourcegateway.model.TokenIntrospectionResult; -import com.onegini.examples.resourcegateway.service.AccessTokenExtractor; -import com.onegini.examples.resourcegateway.service.DeviceApiRequestService; -import com.onegini.examples.resourcegateway.service.MultipartService; -import com.onegini.examples.resourcegateway.service.ScopeValidationService; -import com.onegini.examples.resourcegateway.service.TokenTypeValidationService; +import com.onegini.examples.resourcegateway.model.*; +import com.onegini.examples.resourcegateway.service.*; import com.onegini.examples.resourcegateway.service.tokenintrospection.TokenIntrospectionService; import com.onegini.examples.resourcegateway.util.DecoratedUserIdBuilder; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import static com.onegini.examples.resourcegateway.service.ScopeValidationService.*; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + @Slf4j @RestController @RequestMapping(value = "/resources") diff --git a/src/test/java/com/onegini/examples/resourcegateway/SpringContextTest.java b/src/test/java/com/onegini/examples/resourcegateway/SpringContextTest.java index b78cd17..94450e6 100644 --- a/src/test/java/com/onegini/examples/resourcegateway/SpringContextTest.java +++ b/src/test/java/com/onegini/examples/resourcegateway/SpringContextTest.java @@ -1,17 +1,15 @@ package com.onegini.examples.resourcegateway; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; - -import javax.annotation.Resource; - +import com.onegini.examples.resourcegateway.web.ResourcesController; +import jakarta.annotation.Resource; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; -import com.onegini.examples.resourcegateway.web.ResourcesController; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; @ExtendWith(SpringExtension.class) @DirtiesContext(classMode = AFTER_CLASS)