Skip to content

Commit 7c83d36

Browse files
committed
add Springboot4 to CI workflow
1 parent 54d3dc6 commit 7c83d36

File tree

14 files changed

+205
-46
lines changed

14 files changed

+205
-46
lines changed

.github/workflows/continuous-integration-workflow.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ jobs:
8282
- name: Build with Spring Boot 3.3.x
8383
run: ./gha_build.sh springboot3 false false -Dspringboot.version=3.3.6 -Dspring.version=6.1.15 -Dspringsecurity.version=6.3.5 -Ddependency-check.skip=true
8484

85+
build_springboot4:
86+
name: Build and test SpringBoot 4
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: actions/checkout@v3
90+
- name: Set up JDK 17
91+
uses: actions/setup-java@v3
92+
with:
93+
distribution: 'corretto'
94+
java-version: 17
95+
- name: Build latest
96+
run: ./gha_build.sh springboot4 true true
8597
# temporarily disabled as Struts is not released at the moment
8698
# build_struts2:
8799
# name: Build and test Struts

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,22 @@ private List<String> getHeaderValues(String key) {
607607

608608
if (request.getRequestSource() == RequestSource.API_GATEWAY) {
609609
if ("referer".equals(key.toLowerCase(Locale.ENGLISH))) {
610-
values.add(request.getRequestContext().getIdentity().getCaller());
611-
return values;
610+
if (request.getRequestContext() != null && request.getRequestContext().getIdentity() != null) {
611+
String caller = request.getRequestContext().getIdentity().getCaller();
612+
if (caller != null) {
613+
values.add(caller);
614+
return values;
615+
}
616+
}
612617
}
613618
if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
614-
values.add(request.getRequestContext().getIdentity().getUserAgent());
615-
return values;
619+
if (request.getRequestContext() != null && request.getRequestContext().getIdentity() != null) {
620+
String userAgent = request.getRequestContext().getIdentity().getUserAgent();
621+
if (userAgent != null) {
622+
values.add(userAgent);
623+
return values;
624+
}
625+
}
616626
}
617627
}
618628

aws-serverless-java-container-springboot4/pom.xml

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,126 @@
7676
<version>${spring.version}</version>
7777
<optional>true</optional>
7878
</dependency>
79+
80+
<!-- Jakarta Servlet API for Spring Boot 4.0 -->
81+
<dependency>
82+
<groupId>jakarta.servlet</groupId>
83+
<artifactId>jakarta.servlet-api</artifactId>
84+
<version>6.1.0</version>
85+
<scope>provided</scope>
86+
</dependency>
87+
88+
<!-- Test dependencies -->
89+
<dependency>
90+
<groupId>org.springframework.boot</groupId>
91+
<artifactId>spring-boot-starter</artifactId>
92+
<version>${springboot.version}</version>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.springframework.boot</groupId>
97+
<artifactId>spring-boot-starter-webmvc</artifactId>
98+
<version>${springboot.version}</version>
99+
<scope>test</scope>
100+
</dependency>
101+
102+
<dependency>
103+
<groupId>org.springframework.boot</groupId>
104+
<artifactId>spring-boot-starter-webflux</artifactId>
105+
<version>${springboot.version}</version>
106+
<scope>test</scope>
107+
<exclusions>
108+
<exclusion>
109+
<groupId>org.springframework.boot</groupId>
110+
<artifactId>spring-boot-starter-reactor-netty</artifactId>
111+
</exclusion>
112+
</exclusions>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.springframework.boot</groupId>
116+
<artifactId>spring-boot-starter-data-jpa</artifactId>
117+
<version>${springboot.version}</version>
118+
<scope>test</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.springframework.boot</groupId>
122+
<artifactId>spring-boot-starter-validation</artifactId>
123+
<version>${springboot.version}</version>
124+
<scope>test</scope>
125+
</dependency>
126+
127+
<dependency>
128+
<groupId>org.springframework.boot</groupId>
129+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
130+
<version>${springboot.version}</version>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>com.h2database</groupId>
135+
<artifactId>h2</artifactId>
136+
<version>2.3.232</version>
137+
<scope>test</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>org.springframework.boot</groupId>
141+
<artifactId>spring-boot-starter-security</artifactId>
142+
<version>${springboot.version}</version>
143+
<scope>test</scope>
144+
</dependency>
145+
<dependency>
146+
<groupId>org.springframework.security</groupId>
147+
<artifactId>spring-security-web</artifactId>
148+
<version>${springsecurity.version}</version>
149+
<scope>test</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.springframework.security</groupId>
153+
<artifactId>spring-security-config</artifactId>
154+
<version>${springsecurity.version}</version>
155+
<scope>test</scope>
156+
</dependency>
79157
</dependencies>
80158

159+
<profiles>
160+
<profile>
161+
<id>security-tests</id>
162+
<activation>
163+
<property>
164+
<name>test</name>
165+
<value>SecurityAppTest</value>
166+
</property>
167+
</activation>
168+
<dependencies>
169+
<dependency>
170+
<groupId>org.springframework.boot</groupId>
171+
<artifactId>spring-boot-starter-security</artifactId>
172+
<version>${springboot.version}</version>
173+
<scope>test</scope>
174+
</dependency>
175+
<dependency>
176+
<groupId>org.springframework.security</groupId>
177+
<artifactId>spring-security-web</artifactId>
178+
<version>${springsecurity.version}</version>
179+
<scope>test</scope>
180+
</dependency>
181+
<dependency>
182+
<groupId>org.springframework.security</groupId>
183+
<artifactId>spring-security-config</artifactId>
184+
<version>${springsecurity.version}</version>
185+
<scope>test</scope>
186+
</dependency>
187+
</dependencies>
188+
</profile>
189+
</profiles>
190+
81191
<build>
82192
<plugins>
83193
<plugin>
84194
<groupId>org.apache.maven.plugins</groupId>
85195
<artifactId>maven-compiler-plugin</artifactId>
86196
<configuration>
87-
<source>25</source>
88-
<target>25</target>
197+
<source>17</source>
198+
<target>17</target>
89199
</configuration>
90200
</plugin>
91201
</plugins>

aws-serverless-java-container-springboot4/src/main/java/com/amazonaws/serverless/proxy/spring/SpringBootLambdaContainerHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.slf4j.LoggerFactory;
1919
import org.springframework.boot.WebApplicationType;
2020
import org.springframework.boot.builder.SpringApplicationBuilder;
21-
import org.springframework.boot.web.context.servlet.AnnotationConfigServletWebApplicationContext;
21+
import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext;
2222
import org.springframework.context.ConfigurableApplicationContext;
2323

2424
import com.amazonaws.serverless.exceptions.ContainerInitializationException;
@@ -197,7 +197,7 @@ public void initialize()
197197
}
198198
applicationContext = builder.run();
199199
if (springWebApplicationType == WebApplicationType.SERVLET) {
200-
((AnnotationConfigServletWebApplicationContext)applicationContext).setServletContext(getServletContext());
200+
((AnnotationConfigServletWebServerApplicationContext)applicationContext).setServletContext(getServletContext());
201201
AwsServletRegistration reg = (AwsServletRegistration)getServletContext().getServletRegistration(DISPATCHER_SERVLET_REGISTRATION_NAME);
202202
if (reg != null) {
203203
reg.setLoadOnStartup(1);

aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/AwsSpringHttpProcessingUtilsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.junit.jupiter.params.provider.MethodSource;
1313
import org.springframework.boot.SpringApplication;
1414
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
15-
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
15+
import org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext;
1616
import org.springframework.cloud.function.serverless.web.ServerlessMVC;
1717
import org.springframework.cloud.function.serverless.web.ServerlessServletContext;
1818
import org.springframework.context.ConfigurableApplicationContext;

aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/jpaapp/JpaApplication.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Import;
99

10-
@SpringBootApplication(exclude = {
11-
org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration.class,
12-
org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration.class,
13-
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration.class,
14-
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
15-
})
10+
@SpringBootApplication
1611
@Import(MessageController.class)
1712
public class JpaApplication {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.amazonaws.serverless.proxy.spring.jpaapp;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.web.SecurityFilterChain;
7+
8+
@Configuration
9+
public class SecurityConfig {
10+
11+
@Bean
12+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
13+
http.authorizeHttpRequests(authz -> authz.anyRequest().permitAll())
14+
.csrf(csrf -> csrf.disable());
15+
return http.build();
16+
}
17+
}

aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/securityapp/SecurityApplication.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
77
import org.springframework.web.reactive.config.EnableWebFlux;
88

9-
@SpringBootApplication(exclude = {
10-
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class,
11-
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.class
12-
})
9+
@SpringBootApplication
1310
@EnableWebFluxSecurity
1411
@EnableWebFlux
1512
@Import(SecurityConfig.class)

aws-serverless-java-container-springboot4/src/test/java/com/amazonaws/serverless/proxy/spring/securityapp/SecurityConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ public class SecurityConfig
2121
@Bean
2222
public SecurityWebFilterChain securitygWebFilterChain(
2323
ServerHttpSecurity http) {
24-
return http.authorizeExchange()
25-
.anyExchange().authenticated().and().csrf().disable()
26-
.httpBasic()
27-
.and().build();
24+
return http.authorizeExchange(exchanges -> exchanges
25+
.anyExchange().authenticated())
26+
.csrf(csrf -> csrf.disable())
27+
.httpBasic(httpBasic -> {})
28+
.build();
2829
}
2930

3031
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.amazonaws.serverless.proxy.spring.servletapp;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.web.SecurityFilterChain;
7+
8+
@Configuration
9+
public class SecurityConfig {
10+
11+
@Bean
12+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
13+
http.authorizeHttpRequests(authz -> authz.anyRequest().permitAll())
14+
.csrf(csrf -> csrf.disable());
15+
return http.build();
16+
}
17+
}

0 commit comments

Comments
 (0)