Skip to content

Commit 320e496

Browse files
committed
Upgrade to Spring Boot 2.0.0.RC1
...along with Spring Cloud Finchley.M6, and Spring Cloud Stream Elmhurst.M4 * Update Spring Security policy settings as well as default dummy accounts using new APIs, and new reactive APIs. * Update custom Thymeleaf authorization processor to find SecurityContext inside the exchange. (Still no thymeleaf-extras-springsecurity5 WebFlux support) * Replace custom Spring Cloud Gateway filter with comment because code was contributed to the project. * Patch some unit tests that broke due to constructor settings for Selenium.
1 parent e937067 commit 320e496

File tree

74 files changed

+240
-280
lines changed

Some content is hidden

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

74 files changed

+240
-280
lines changed

1/part1/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// tag::buildscript[]
22
buildscript {
33
ext {
4-
springBootVersion = '2.0.0.M5'
4+
springBootVersion = '2.0.0.RC1'
55
}
66
repositories {
77
mavenCentral()

10/part1/chat/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// tag::propdeps-plugin-1[]
22
buildscript {
33
ext {
4-
springBootVersion = '2.0.0.M5'
5-
springCloudVersion = 'Finchley.M3'
6-
springCloudStreamVersion = 'Elmhurst.M2'
4+
springBootVersion = '2.0.0.RC1'
5+
springCloudVersion = 'Finchley.M6'
6+
springCloudStreamVersion = 'Elmhurst.M4'
77
}
88
repositories {
99
mavenCentral()
@@ -71,7 +71,7 @@ dependencies {
7171
compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
7272
compile('org.springframework.cloud:spring-cloud-starter-config')
7373

74-
compile('org.springframework.boot:spring-boot-starter-security-reactive')
74+
compile('org.springframework.boot:spring-boot-starter-security')
7575

7676
compile('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
7777

10/part1/chat/src/main/java/com/greglturnquist/learningspringboot/chat/GatewayConfig.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,17 @@
1515
*/
1616
package com.greglturnquist.learningspringboot.chat;
1717

18-
import org.slf4j.Logger;
19-
import org.slf4j.LoggerFactory;
20-
import org.springframework.cloud.gateway.filter.GatewayFilter;
21-
import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory;
22-
import org.springframework.context.annotation.Bean;
23-
import org.springframework.context.annotation.Configuration;
24-
import org.springframework.tuple.Tuple;
25-
import org.springframework.web.server.WebSession;
26-
2718
/**
2819
* @author Greg Turnquist
2920
*/
3021
// tag::code[]
31-
@Configuration
3222
public class GatewayConfig {
3323

34-
private static final Logger log =
35-
LoggerFactory.getLogger(GatewayConfig.class);
36-
3724
/**
38-
* Force the current WebSession to get saved
25+
* Code originally written here was contributed to
26+
* Spring Cloud Gateway via https://github.com/spring-cloud/spring-cloud-gateway/pull/166
27+
* and thus removed from this book.
3928
*/
40-
static class SaveSessionGatewayFilterFactory
41-
implements GatewayFilterFactory {
42-
@Override
43-
public GatewayFilter apply(Tuple args) {
44-
return (exchange, chain) -> exchange.getSession()
45-
.map(webSession -> {
46-
log.debug("Session id: " + webSession.getId());
47-
webSession.getAttributes().entrySet()
48-
.forEach(entry ->
49-
log.debug(entry.getKey() + " => " +
50-
entry.getValue()));
51-
return webSession;
52-
})
53-
.map(WebSession::save)
54-
.then(chain.filter(exchange));
55-
}
56-
}
5729

58-
@Bean
59-
SaveSessionGatewayFilterFactory saveSessionWebFilterFactory() {
60-
return new SaveSessionGatewayFilterFactory();
61-
}
6230
}
6331
// end::code[]

10/part1/chat/src/main/java/com/greglturnquist/learningspringboot/chat/SecurityConfiguration.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
import org.springframework.context.annotation.Bean;
1919
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
20-
import org.springframework.security.config.web.server.HttpSecurity;
20+
import org.springframework.security.config.web.server.ServerHttpSecurity;
2121
import org.springframework.security.web.server.SecurityWebFilterChain;
22+
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
2223

2324
/**
2425
* @author Greg Turnquist
@@ -29,11 +30,15 @@ public class SecurityConfiguration {
2930

3031
// tag::security-filter-chain[]
3132
@Bean
32-
SecurityWebFilterChain springWebFilterChain(HttpSecurity http) {
33+
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
3334
return http
3435
.authorizeExchange()
35-
.pathMatchers("/**").authenticated()
36-
.and()
36+
.pathMatchers("/**").authenticated()
37+
.and()
38+
.httpBasic()
39+
.securityContextRepository(new WebSessionServerSecurityContextRepository())
40+
.and()
41+
.csrf().disable()
3742
.build();
3843
}
3944
// end::security-filter-chain[]

10/part1/chat/src/main/java/com/greglturnquist/learningspringboot/chat/SpringDataUserDetailsRepository.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
package com.greglturnquist.learningspringboot.chat;
1717

1818
import reactor.core.publisher.Mono;
19-
import org.springframework.security.core.authority.AuthorityUtils;
19+
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
2020
import org.springframework.security.core.userdetails.User;
2121
import org.springframework.security.core.userdetails.UserDetails;
22-
import org.springframework.security.core.userdetails.UserDetailsRepository;
2322
import org.springframework.stereotype.Component;
2423

2524
/**
2625
* @author Greg Turnquist
2726
*/
2827
// tag::code[]
2928
@Component
30-
public class SpringDataUserDetailsRepository implements UserDetailsRepository {
29+
public class SpringDataUserDetailsRepository implements ReactiveUserDetailsService {
3130

3231
private final UserRepository repository;
3332

@@ -39,11 +38,11 @@ public SpringDataUserDetailsRepository(UserRepository repository)
3938
@Override
4039
public Mono<UserDetails> findByUsername(String username) {
4140
return repository.findByUsername(username)
42-
.map(user -> new User(
43-
user.getUsername(),
44-
user.getPassword(),
45-
AuthorityUtils.createAuthorityList(user.getRoles())
46-
));
41+
.map(user -> User.withDefaultPasswordEncoder()
42+
.username(user.getUsername())
43+
.password(user.getPassword())
44+
.authorities(user.getRoles())
45+
.build());
4746
}
4847
}
4948
// end::code[]

10/part1/comments/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
buildscript {
22
ext {
3-
springBootVersion = '2.0.0.M5'
4-
springCloudVersion = 'Finchley.M3'
5-
springCloudStreamVersion = 'Elmhurst.M2'
3+
springBootVersion = '2.0.0.RC1'
4+
springCloudVersion = 'Finchley.M6'
5+
springCloudStreamVersion = 'Elmhurst.M4'
66
}
77
repositories {
88
mavenCentral()
@@ -57,7 +57,7 @@ dependencies {
5757
compile('org.springframework.cloud:spring-cloud-starter-config')
5858
compile('org.projectlombok:lombok')
5959

60-
compile('org.springframework.boot:spring-boot-starter-security-reactive')
60+
compile('org.springframework.boot:spring-boot-starter-security')
6161
compile('org.springframework.session:spring-session-data-mongodb')
6262

6363
testCompile('org.springframework.boot:spring-boot-starter-test')

10/part1/comments/src/main/java/com/greglturnquist/learningspringboot/comments/SecurityConfiguration.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import org.springframework.context.annotation.Bean;
1919
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
2020
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
21-
import org.springframework.security.config.web.server.HttpSecurity;
21+
import org.springframework.security.config.web.server.ServerHttpSecurity;
2222
import org.springframework.security.web.server.SecurityWebFilterChain;
23-
import org.springframework.security.web.server.context.WebSessionSecurityContextRepository;
23+
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
2424

2525
/**
2626
* @author Greg Turnquist
@@ -31,12 +31,13 @@
3131
public class SecurityConfiguration {
3232

3333
@Bean
34-
SecurityWebFilterChain springWebFilterChain() {
35-
return HttpSecurity.http()
36-
.securityContextRepository(new WebSessionSecurityContextRepository())
34+
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
35+
return http
36+
.securityContextRepository(new WebSessionServerSecurityContextRepository())
3737
.authorizeExchange()
38-
.anyExchange().authenticated()
39-
.and()
38+
.anyExchange().authenticated()
39+
.and()
40+
.csrf().disable()
4041
.build();
4142
}
4243
}

10/part1/config-server/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
3-
springBootVersion = '2.0.0.M5'
4-
springCloudVersion = 'Finchley.M3'
3+
springBootVersion = '2.0.0.RC1'
4+
springCloudVersion = 'Finchley.M6'
55
}
66
repositories {
77
mavenCentral()

10/part1/config-server/src/main/java/com/greglturnquist/learningspringboot/LearningSpringBootConfigServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static void main(String[] args) {
3939
@Bean
4040
UserDetailsService userDetailsService() {
4141
return new InMemoryUserDetailsManager(
42-
User
43-
.withUsername("user")
42+
User.withDefaultPasswordEncoder()
43+
.username("user")
4444
.password("password")
4545
.roles("USER").build());
4646
}

10/part1/eureka-server/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
3-
springBootVersion = '2.0.0.M5'
4-
springCloudVersion = 'Finchley.M3'
3+
springBootVersion = '2.0.0.RC1'
4+
springCloudVersion = 'Finchley.M6'
55
}
66
repositories {
77
mavenCentral()

0 commit comments

Comments
 (0)