Skip to content

Commit 99bc18c

Browse files
leorabaAzher2Ali
andauthored
SpringBoot 3 migration (#689)
* Update to Spring Boot 2.7 * Update to Spring Boot 3.0.5 * order Spring security filters * use JDK 17 docker image * spring migration * Spring migration --------- Co-authored-by: Azher2Ali <[email protected]>
1 parent 140c081 commit 99bc18c

File tree

91 files changed

+1244
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1244
-1151
lines changed

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
FROM adoptopenjdk/openjdk11:jdk-11.0.6_10-alpine-slim as builder
1+
FROM eclipse-temurin:17.0.6_10-jdk-focal as builder
22
WORKDIR /usr/src/app
33
ADD . .
44
RUN ./mvnw package -Dmaven.test.skip=true
55

66
#####################################################
77

8-
FROM adoptopenjdk/openjdk11:jre-11.0.6_10-alpine
8+
FROM eclipse-temurin:17.0.6_10-jre-focal
99
COPY --from=builder /usr/src/app/target/ego-*-exec.jar /usr/bin/ego.jar
1010
ENV EGO_USER ego
1111
ENV EGO_USER_ID 9999
1212
ENV EGO_GROUP_ID 9999
1313
ENV EGO_DIR /target
14-
RUN addgroup -S -g $EGO_GROUP_ID $EGO_USER \
15-
&& adduser -S -u $EGO_USER_ID -G $EGO_USER $EGO_USER \
14+
RUN addgroup --system --gid $EGO_GROUP_ID $EGO_USER \
15+
&& adduser --system --uid $EGO_USER_ID --ingroup $EGO_USER $EGO_USER \
1616
&& mkdir -p $EGO_DIR \
1717
&& chown -R $EGO_USER $EGO_DIR
1818
USER $EGO_USER_ID

Jenkinsfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ spec:
1212
- name: maven
1313
command: ['cat']
1414
tty: true
15-
image: maven:3.6.3-openjdk-11
15+
image: maven:3.8.5-openjdk-17
1616
- name: jdk
1717
tty: true
18-
image: adoptopenjdk/openjdk11:jdk-11.0.7_10-alpine-slim
18+
image: eclipse-temurin:17.0.6_10-jdk-focal
1919
env:
2020
- name: DOCKER_HOST
2121
value: tcp://localhost:2375
@@ -128,7 +128,6 @@ spec:
128128
when {
129129
anyOf {
130130
branch 'develop'
131-
branch 'feature/develop-passport'
132131
branch 'main'
133132
expression { return params.PUBLISH_IMAGE }
134133
}

pom.xml

+44-34
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
<parent>
1414
<groupId>org.springframework.boot</groupId>
1515
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>2.5.12</version>
16+
<version>3.0.5</version>
1717
<relativePath/> <!-- lookup parent from repository -->
1818
</parent>
1919

2020
<properties>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23-
<java.version>11</java.version>
23+
<java.version>17</java.version>
2424
<mapstruct.version>1.2.0.Final</mapstruct.version>
25-
<grpc.version>1.34.1</grpc.version>
25+
<grpc.version>1.54.0</grpc.version><!-- WIP -->
26+
<!-- Spring security version compatible with Spring boot 3.0.x -->
27+
<spring-security.version>6.0.3</spring-security.version>
2628
</properties>
2729

2830
<dependencies>
@@ -34,6 +36,14 @@
3436
<groupId>org.springframework.boot</groupId>
3537
<artifactId>spring-boot-starter-actuator</artifactId>
3638
</dependency>
39+
40+
<!-- Moving authorization-server before of starter-security to solve conflicts with JwtEncoder, V1.x compatible with Spring boot 3.0.x -->
41+
<dependency>
42+
<groupId>org.springframework.security</groupId>
43+
<artifactId>spring-security-oauth2-authorization-server</artifactId>
44+
<version>1.0.1</version>
45+
</dependency>
46+
3747
<dependency>
3848
<groupId>org.springframework.boot</groupId>
3949
<artifactId>spring-boot-starter-security</artifactId>
@@ -52,8 +62,8 @@
5262

5363
<dependency>
5464
<groupId>org.springframework.security</groupId>
55-
<artifactId>spring-security-oauth2-authorization-server</artifactId>
56-
<version>0.2.1</version>
65+
<artifactId>spring-security-oauth2-client</artifactId>
66+
<version>6.0.3</version>
5767
</dependency>
5868

5969
<dependency>
@@ -68,27 +78,15 @@
6878
<dependency>
6979
<groupId>org.projectlombok</groupId>
7080
<artifactId>lombok</artifactId>
71-
<version>1.18.16</version>
81+
<!-- compatible with JDK17 -->
82+
<version>1.18.22</version>
7283
<optional>true</optional>
7384
</dependency>
74-
85+
<!-- API documentation. replacement of springfox-swagger2, compatible with Springboot 3.x -->
7586
<dependency>
76-
<groupId>io.springfox</groupId>
77-
<artifactId>springfox-swagger2</artifactId>
78-
<version>2.9.2</version>
79-
<scope>compile</scope>
80-
<exclusions>
81-
<exclusion>
82-
<groupId>org.mapstruct</groupId>
83-
<artifactId>mapstruct</artifactId>
84-
</exclusion>
85-
</exclusions>
86-
</dependency>
87-
<dependency>
88-
<groupId>io.springfox</groupId>
89-
<artifactId>springfox-swagger-ui</artifactId>
90-
<version>2.9.2</version>
91-
<scope>compile</scope>
87+
<groupId>org.springdoc</groupId>
88+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
89+
<version>2.1.0</version>
9290
</dependency>
9391
<dependency>
9492
<groupId>org.springframework.boot</groupId>
@@ -135,25 +133,25 @@
135133
<!-- https://vladmihalcea.com/the-best-way-to-map-an-enum-type-with-jpa-and-hibernate/ -->
136134
<dependency>
137135
<groupId>com.vladmihalcea</groupId>
138-
<artifactId>hibernate-types-52</artifactId>
139-
<version>2.2.2</version>
136+
<artifactId>hibernate-types-60</artifactId>
137+
<version>2.21.1</version>
140138
</dependency>
141139

142140
<!-- TestContainers (for testing) -->
143141
<dependency>
144142
<groupId>org.testcontainers</groupId>
145143
<artifactId>testcontainers</artifactId>
146-
<version>1.15.1</version>
144+
<version>1.18.0</version>
147145
</dependency>
148146
<dependency>
149147
<groupId>org.testcontainers</groupId>
150148
<artifactId>jdbc</artifactId>
151-
<version>1.15.1</version>
149+
<version>1.18.0</version>
152150
</dependency>
153151
<dependency>
154152
<groupId>org.testcontainers</groupId>
155153
<artifactId>postgresql</artifactId>
156-
<version>1.15.1</version>
154+
<version>1.18.0</version>
157155
</dependency>
158156
<dependency>
159157
<groupId>commons-io</groupId>
@@ -166,11 +164,11 @@
166164
<version>2.6</version>
167165
</dependency>
168166

169-
<!-- Flyway, for testcontainers -->
167+
<!-- Flyway, for testcontainers V9 compatible with SpringBoot 3 -->
170168
<dependency>
171169
<groupId>org.flywaydb</groupId>
172170
<artifactId>flyway-core</artifactId>
173-
<version>5.2.4</version>
171+
<version>9.16.3</version>
174172
</dependency>
175173

176174

@@ -304,6 +302,13 @@
304302
<scope>test</scope>
305303
</dependency>
306304

305+
<!-- Compatibility with Grpc proto generated annotation -->
306+
<dependency>
307+
<groupId>javax.annotation</groupId>
308+
<artifactId>javax.annotation-api</artifactId>
309+
<version>1.3.2</version>
310+
</dependency>
311+
307312
<dependency>
308313
<groupId>org.junit.vintage</groupId>
309314
<artifactId>junit-vintage-engine</artifactId>
@@ -356,7 +361,7 @@
356361
<artifactId>spring-boot-maven-plugin</artifactId>
357362
<configuration>
358363
<classifier>exec</classifier>
359-
<fork>true</fork>
364+
<!-- <fork>true</fork>-->
360365
</configuration>
361366
<executions>
362367
<execution>
@@ -389,12 +394,16 @@
389394
<plugin>
390395
<groupId>org.xolstice.maven.plugins</groupId>
391396
<artifactId>protobuf-maven-plugin</artifactId>
392-
<version>0.5.1</version>
397+
<version>0.6.1</version>
393398
<configuration>
394399
<protocArtifact>com.google.protobuf:protoc:3.12.0:exe:${os.detected.classifier}</protocArtifact>
400+
<!-- for Mac OS compatibility -->
401+
<!--<protocArtifact>com.google.protobuf:protoc:3.21.7:exe:osx-x86_64</protocArtifact>-->
395402
<protoSourceRoot>${basedir}/src/main/proto</protoSourceRoot>
396403
<pluginId>grpc-java</pluginId>
397-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.34.1:exe:${os.detected.classifier}</pluginArtifact>
404+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.54.0:exe:${os.detected.classifier}</pluginArtifact>
405+
<!-- for Mac Os compatibility -->
406+
<!--<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:osx-x86_64</pluginArtifact>-->
398407
</configuration>
399408
<executions>
400409
<execution>
@@ -434,7 +443,8 @@
434443
<dependency>
435444
<groupId>org.springframework.cloud</groupId>
436445
<artifactId>spring-cloud-dependencies</artifactId>
437-
<version>2020.0.4</version>
446+
<!-- version compatible with Spring boot 2.7.x -->
447+
<version>2021.0.5</version>
438448
<type>pom</type>
439449
<scope>import</scope>
440450
</dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2017. The Ontario Institute for Cancer Research. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bio.overture.ego.config;
18+
19+
import bio.overture.ego.security.*;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.autoconfigure.security.SecurityProperties;
22+
import org.springframework.context.annotation.*;
23+
import org.springframework.core.annotation.Order;
24+
import org.springframework.http.HttpMethod;
25+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
26+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
27+
import org.springframework.security.config.http.SessionCreationPolicy;
28+
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
29+
import org.springframework.security.web.SecurityFilterChain;
30+
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
31+
32+
@Configuration
33+
@EnableWebSecurity
34+
@Import(OAuth2ClientConfig.class)
35+
@Profile("auth")
36+
public class AppSecureServerConfig {
37+
38+
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
39+
new OAuth2AuthorizationServerConfigurer();
40+
@Autowired JWTAuthorizationFilter authorizationFilter;
41+
42+
@Bean
43+
@Order(SecurityProperties.BASIC_AUTH_ORDER - 6)
44+
public SecurityFilterChain appFilterChain(HttpSecurity http) throws Exception {
45+
return http.csrf()
46+
.disable()
47+
.apply(authorizationServerConfigurer)
48+
.and()
49+
.securityMatcher(
50+
"/",
51+
"/favicon.ico",
52+
"/swagger-ui/**",
53+
"/v3/api-docs/**",
54+
"/swagger-resources/**",
55+
"/configuration/ui",
56+
"/configuration/**",
57+
"/v2/api**",
58+
"/webjars/**",
59+
"/actuator/**",
60+
"/o/**",
61+
"/oauth/token",
62+
"/oauth/token/verify",
63+
"/oauth/token/public_key")
64+
.authorizeRequests()
65+
.requestMatchers(
66+
"/",
67+
"/favicon.ico",
68+
"/swagger-ui/**",
69+
"/v3/api-docs/**",
70+
"/swagger-resources/**",
71+
"/configuration/ui",
72+
"/configuration/**",
73+
"/v2/api**",
74+
"/webjars/**",
75+
"/actuator/**",
76+
"/oauth/token/verify",
77+
"/oauth/token/public_key")
78+
.permitAll()
79+
.requestMatchers(HttpMethod.OPTIONS, "/**")
80+
.permitAll()
81+
.anyRequest()
82+
.authenticated()
83+
.and()
84+
.addFilterBefore(authorizationFilter, BasicAuthenticationFilter.class)
85+
.sessionManagement()
86+
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
87+
.and()
88+
.build();
89+
}
90+
}

src/main/java/bio/overture/ego/config/AuthorizationServerConfig.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.springframework.context.annotation.Configuration;
1717
import org.springframework.security.oauth2.jwt.JwtDecoder;
1818
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
19-
import org.springframework.security.oauth2.server.authorization.config.ProviderSettings;
19+
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
2020

2121
@Configuration
2222
public class AuthorizationServerConfig {
@@ -48,7 +48,11 @@ public JwtDecoder jwtDecoder(@Autowired TokenSigner tokenSigner) {
4848
}
4949

5050
@Bean
51-
public ProviderSettings providerSettings(@Value("${token.issuer}") String issuer) {
52-
return ProviderSettings.builder().tokenEndpoint("/oauth/token").issuer(issuer).build();
51+
public AuthorizationServerSettings providerSettings(@Value("${token.issuer}") String issuer) {
52+
53+
return AuthorizationServerSettings.builder()
54+
.tokenEndpoint("/oauth/token")
55+
.issuer(issuer)
56+
.build();
5357
}
5458
}

src/main/java/bio/overture/ego/config/InitializationConfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package bio.overture.ego.config;
22

33
import bio.overture.ego.model.enums.ApplicationType;
4+
import jakarta.validation.constraints.NotBlank;
5+
import jakarta.validation.constraints.NotNull;
6+
import jakarta.validation.constraints.Size;
47
import java.util.ArrayList;
58
import java.util.List;
6-
import javax.validation.constraints.NotBlank;
7-
import javax.validation.constraints.NotNull;
8-
import javax.validation.constraints.Size;
99
import lombok.AllArgsConstructor;
1010
import lombok.Builder;
1111
import lombok.Getter;

0 commit comments

Comments
 (0)