Merge branch '6.2.x'

This commit is contained in:
Marcus Hert Da Coregio
2024-01-17 12:03:17 -03:00
38 changed files with 205 additions and 119 deletions

View File

@@ -83,7 +83,7 @@ public class WebfluxX509ApplicationITest {
// @formatter:on
HttpClient httpClient = HttpClient.create()
.secure((sslContextSpec) -> sslContextSpec.sslContext(sslContextBuilder));
.secure((sslContextSpec) -> sslContextSpec.sslContext(sslContextBuilder));
ClientHttpConnector httpConnector = new ReactorClientHttpConnector(httpClient);
// @formatter:off

View File

@@ -34,8 +34,9 @@ public class MeController {
@GetMapping("/me")
public Mono<String> me() {
return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication)
.map((authentication) -> "Hello, " + authentication.getName());
return ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map((authentication) -> "Hello, " + authentication.getName());
}
}

View File

@@ -63,12 +63,21 @@ public class SecurityConfig {
@Bean
ReactiveUserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder().username("admin").password("password").roles("ADMIN")
.build();
UserDetails unlimitedSessions = User.withDefaultPasswordEncoder().username("unlimited").password("password")
.roles("UNLIMITED_SESSIONS").build();
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("password")
.roles("ADMIN")
.build();
UserDetails unlimitedSessions = User.withDefaultPasswordEncoder()
.username("unlimited")
.password("password")
.roles("UNLIMITED_SESSIONS")
.build();
return new MapReactiveUserDetailsService(user, admin, unlimitedSessions);
}

View File

@@ -93,13 +93,20 @@ class MaximumSessionsApplicationPreventLoginTests {
}
private ResponseCookie loginReturningCookie(MultiValueMap<String, String> data) {
return login(data).expectCookie().exists("SESSION").returnResult(Void.class).getResponseCookies()
.getFirst("SESSION");
return login(data).expectCookie()
.exists("SESSION")
.returnResult(Void.class)
.getResponseCookies()
.getFirst("SESSION");
}
private WebTestClient.ResponseSpec login(MultiValueMap<String, String> data) {
return this.client.mutateWith(csrf()).post().uri("/login").contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromFormData(data)).exchange();
return this.client.mutateWith(csrf())
.post()
.uri("/login")
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromFormData(data))
.exchange();
}
}

View File

@@ -94,13 +94,20 @@ class MaximumSessionsApplicationTests {
}
private ResponseCookie loginReturningCookie(MultiValueMap<String, String> data) {
return login(data).expectCookie().exists("SESSION").returnResult(Void.class).getResponseCookies()
.getFirst("SESSION");
return login(data).expectCookie()
.exists("SESSION")
.returnResult(Void.class)
.getResponseCookies()
.getFirst("SESSION");
}
private WebTestClient.ResponseSpec login(MultiValueMap<String, String> data) {
return this.client.mutateWith(csrf()).post().uri("/login").contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromFormData(data)).exchange();
return this.client.mutateWith(csrf())
.post()
.uri("/login")
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromFormData(data))
.exchange();
}
}