JAVA-26572 :- Upgrade Spring Cloud – Bootstrapping to Spring Cloud latest versions (#16014)

This commit is contained in:
Amit Pandey 2024-03-12 16:43:56 +05:30 committed by GitHub
parent 7d0f28cf03
commit b43f720788
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 75 additions and 89 deletions

View File

@ -805,6 +805,7 @@
<module>spring-cloud-modules/spring-cloud-security</module>
<!--<module>spring-cloud-modules/spring-cloud-stream-starters</module>--><!-- failing after upgrading to jdk17-->
<module>spring-cloud-modules/spring-cloud-zuul-eureka-integration</module>
<module>spring-cloud-modules/spring-cloud-bootstrap</module>
<module>spring-core-2</module>
<module>spring-core-3</module>
<module>spring-core-4</module>
@ -1052,6 +1053,7 @@
<module>spring-cloud-modules/spring-cloud-security</module>
<!--<module>spring-cloud-modules/spring-cloud-stream-starters</module>--><!-- failing after upgrading to jdk17-->
<module>spring-cloud-modules/spring-cloud-zuul-eureka-integration</module>
<module>spring-cloud-modules/spring-cloud-bootstrap</module>
<module>spring-core-2</module>
<module>spring-core-3</module>
<module>spring-core-4</module>

View File

@ -22,7 +22,8 @@
<!--Please uncomment when spring-cloud-modules is moved to JDK9+ profile-->
<!--<module>spring-cloud-eureka</module>-->
<module>spring-cloud-hystrix</module>
<module>spring-cloud-bootstrap</module>
<!--Please uncomment when spring-cloud-modules is moved to JDK9+ profile-->
<!--<module>spring-cloud-bootstrap</module> -->
<module>spring-cloud-ribbon-client</module>
<module>spring-cloud-zookeeper</module>
<module>spring-cloud-gateway</module>

View File

@ -9,9 +9,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencyManagement>
@ -42,7 +42,7 @@
</dependencies>
<properties>
<spring-cloud-dependencies.version>2021.0.7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2022.0.4</spring-cloud-dependencies.version>
</properties>
</project>

View File

@ -11,9 +11,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencies>

View File

@ -9,9 +9,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencyManagement>
@ -54,7 +54,7 @@
</dependencies>
<properties>
<spring-cloud-dependencies.version>2021.0.7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2022.0.3</spring-cloud-dependencies.version>
</properties>
</project>

View File

@ -4,41 +4,38 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
@Configuration
@EnableWebSecurity
@Order(1)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public class SecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("discUser").password("{noop}discPassword").roles("SYSTEM");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS).and().requestMatchers().antMatchers("/eureka/**").and().authorizeRequests().antMatchers("/eureka/**").hasRole("SYSTEM").anyRequest().denyAll().and().httpBasic().and().csrf()
.disable();
http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.ALWAYS)).authorizeHttpRequests(auth -> auth.requestMatchers("/eureka/**")).authorizeRequests(auth -> auth.requestMatchers("/eureka/**").hasRole("SYSTEM").anyRequest().denyAll()).httpBasic(
Customizer.withDefaults()).csrf(csrf -> csrf.disable());
}
@Configuration
// no order tag means this is the last security filter to be evaluated
public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
public static class AdminSecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER).and().httpBasic().disable().authorizeRequests().antMatchers(HttpMethod.GET, "/").hasRole("ADMIN").antMatchers("/info", "/health").authenticated().anyRequest().denyAll()
.and().csrf().disable();
http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.NEVER)).httpBasic(basic -> basic.disable()).authorizeRequests().requestMatchers(HttpMethod.GET, "/").hasRole("ADMIN").requestMatchers("/info", "/health").authenticated().anyRequest().denyAll()
.and().csrf(csrf -> csrf.disable());
}
}
}

View File

@ -9,9 +9,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencyManagement>
@ -55,18 +55,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -105,7 +103,8 @@
</build>
<properties>
<spring-cloud-dependencies.version>2021.0.7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2022.0.4</spring-cloud-dependencies.version>
<rest-assured.version>5.4.0</rest-assured.version>
</properties>
</project>

View File

@ -20,6 +20,16 @@
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<lombok.version>1.18.30</lombok.version>
</properties>
</project>

View File

@ -11,9 +11,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<modules>
@ -81,16 +81,6 @@
<classifier>exec</classifier>
</configuration>
</execution>
<execution>
<id>start-application</id>
<configuration>
<mainClass>com.baeldung.orderservice.OrderApplication</mainClass>
<classesDirectory>../order-server/target/classes</classesDirectory>
</configuration>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
@ -116,6 +106,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<orderservice.mainclass>com.baeldung.orderservice.OrderApplication</orderservice.mainclass>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
</project>

View File

@ -25,4 +25,8 @@
<module>order-service</module>
</modules>
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>
</project>

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencyManagement>
@ -65,18 +65,10 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
</dependencies>
<properties>
<spring-cloud-dependencies.version>2021.0.7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2022.0.3</spring-cloud-dependencies.version>
</properties>
</project>

View File

@ -20,18 +20,17 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests((auth) -> auth.antMatchers(HttpMethod.GET, "/books")
return http.authorizeHttpRequests((auth) -> auth.requestMatchers(HttpMethod.GET, "/books")
.permitAll()
.antMatchers(HttpMethod.GET, "/books/*")
.requestMatchers(HttpMethod.GET, "/books/*")
.permitAll()
.antMatchers(HttpMethod.POST, "/books")
.requestMatchers(HttpMethod.POST, "/books")
.hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/books/*")
.requestMatchers(HttpMethod.PATCH, "/books/*")
.hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/books/*")
.requestMatchers(HttpMethod.DELETE, "/books/*")
.hasRole("ADMIN"))
.csrf()
.disable()
.csrf(csrf -> csrf.disable())
.build();
}
}

View File

@ -2,10 +2,10 @@ package com.baeldung.spring.cloud.bootstrap.svcbook.book;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
<relativePath>../../../parent-boot-3</relativePath>
</parent>
<dependencyManagement>
@ -68,14 +68,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -84,7 +76,7 @@
</dependencies>
<properties>
<spring-cloud-dependencies.version>2021.0.7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2022.0.3</spring-cloud-dependencies.version>
</properties>
</project>

View File

@ -3,6 +3,7 @@ package com.baeldung.spring.cloud.bootstrap.svcrating;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
@ -20,22 +21,20 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity.authorizeHttpRequests((auth) -> auth.regexMatchers("^/ratings\\?bookId.*$")
return httpSecurity.authorizeHttpRequests((auth) -> auth.requestMatchers("^/ratings\\?bookId.*$")
.authenticated()
.antMatchers(HttpMethod.POST, "/ratings")
.requestMatchers(HttpMethod.POST, "/ratings")
.authenticated()
.antMatchers(HttpMethod.PATCH, "/ratings/*")
.requestMatchers(HttpMethod.PATCH, "/ratings/*")
.hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/ratings/*")
.requestMatchers(HttpMethod.DELETE, "/ratings/*")
.hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/ratings")
.requestMatchers(HttpMethod.GET, "/ratings")
.hasRole("ADMIN")
.anyRequest()
.authenticated())
.httpBasic()
.and()
.csrf()
.disable()
.httpBasic(Customizer.withDefaults())
.csrf(csrf -> csrf.disable())
.build();
}
}

View File

@ -2,11 +2,11 @@ package com.baeldung.spring.cloud.bootstrap.svcrating.rating;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;