Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
fc0438ed
Commit
fc0438ed
authored
May 31, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow direct use of exposed WebSessionIdResolver bean"
See gh-26437
parent
65ce1454
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
28 deletions
+33
-28
WebFluxAutoConfiguration.java
.../autoconfigure/web/reactive/WebFluxAutoConfiguration.java
+12
-9
WebFluxAutoConfigurationTests.java
...configure/web/reactive/WebFluxAutoConfigurationTests.java
+21
-19
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java
View file @
fc0438ed
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
reactive
;
import
java.time.Duration
;
import
java.util.function.Supplier
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
...
...
@@ -308,19 +309,21 @@ public class WebFluxAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
name
=
WebHttpHandlerBuilder
.
WEB_SESSION_MANAGER_BEAN_NAME
)
public
WebSessionManager
webSessionManager
(
ObjectProvider
<
WebSessionIdResolver
>
webSessionIdResolver
s
)
{
public
WebSessionManager
webSessionManager
(
ObjectProvider
<
WebSessionIdResolver
>
webSessionIdResolver
)
{
DefaultWebSessionManager
webSessionManager
=
new
DefaultWebSessionManager
();
if
(
webSessionIdResolvers
.
getIfAvailable
()
!=
null
)
{
webSessionManager
.
setSessionIdResolver
(
webSessionIdResolvers
.
getIfAvailable
());
return
webSessionManager
;
}
CookieWebSessionIdResolver
cookieWebSessionIdResolver
=
new
CookieWebSessionIdResolver
();
cookieWebSessionIdResolver
.
addCookieInitializer
((
cookie
)
->
cookie
.
sameSite
(
this
.
webFluxProperties
.
getSession
().
getCookie
().
getSameSite
().
attribute
()));
webSessionManager
.
setSessionIdResolver
(
cookieWebSessionIdResolver
);
webSessionManager
.
setSessionIdResolver
(
webSessionIdResolver
.
getIfAvailable
(
cookieWebSessionIdResolver
()));
return
webSessionManager
;
}
private
Supplier
<
WebSessionIdResolver
>
cookieWebSessionIdResolver
()
{
return
()
->
{
CookieWebSessionIdResolver
webSessionIdResolver
=
new
CookieWebSessionIdResolver
();
webSessionIdResolver
.
addCookieInitializer
((
cookie
)
->
cookie
.
sameSite
(
this
.
webFluxProperties
.
getSession
().
getCookie
().
getSameSite
().
attribute
()));
return
webSessionIdResolver
;
};
}
}
@Configuration
(
proxyBeanMethods
=
false
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java
View file @
fc0438ed
...
...
@@ -28,6 +28,7 @@ import java.util.List;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Consumer
;
import
javax.validation.ValidatorFactory
;
...
...
@@ -40,8 +41,10 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.autoconfigure.validation.ValidatorAdapter
;
import
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext
;
import
org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -566,29 +569,28 @@ class WebFluxAutoConfigurationTests {
@Test
void
customWebSessionIdResolverShouldBeApplied
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomWebSessionIdResolvers
.
class
).
run
((
context
)
->
{
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
MockServerWebExchange
exchange
=
MockServerWebExchange
.
from
(
request
);
WebSessionManager
webSessionManager
=
context
.
getBean
(
WebSessionManager
.
class
);
WebSession
webSession
=
webSessionManager
.
getSession
(
exchange
).
block
();
webSession
.
start
();
exchange
.
getResponse
().
setComplete
().
block
();
assertThat
(
exchange
.
getResponse
().
getCookies
().
get
(
"JSESSIONID"
)).
isNotEmpty
();
});
this
.
contextRunner
.
withUserConfiguration
(
CustomWebSessionIdResolver
.
class
).
run
(
assertExchangeWithSession
(
(
exchange
)
->
assertThat
(
exchange
.
getResponse
().
getCookies
().
get
(
"TEST"
)).
isNotEmpty
()));
}
@Test
void
customSameSteConfigurationShouldBeApplied
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.webflux.session.cookie.same-site:strict"
).
run
((
context
)
->
{
void
customSameSiteConfigurationShouldBeApplied
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.webflux.session.cookie.same-site:strict"
).
run
(
assertExchangeWithSession
((
exchange
)
->
assertThat
(
exchange
.
getResponse
().
getCookies
().
get
(
"SESSION"
))
.
isNotEmpty
().
allMatch
((
cookie
)
->
cookie
.
getSameSite
().
equals
(
"Strict"
))));
}
private
ContextConsumer
<
ReactiveWebApplicationContext
>
assertExchangeWithSession
(
Consumer
<
MockServerWebExchange
>
exchange
)
{
return
(
context
)
->
{
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
MockServerWebExchange
e
xchange
=
MockServerWebExchange
.
from
(
request
);
MockServerWebExchange
webE
xchange
=
MockServerWebExchange
.
from
(
request
);
WebSessionManager
webSessionManager
=
context
.
getBean
(
WebSessionManager
.
class
);
WebSession
webSession
=
webSessionManager
.
getSession
(
e
xchange
).
block
();
WebSession
webSession
=
webSessionManager
.
getSession
(
webE
xchange
).
block
();
webSession
.
start
();
exchange
.
getResponse
().
setComplete
().
block
();
assertThat
(
exchange
.
getResponse
().
getCookies
().
get
(
"SESSION"
)).
isNotEmpty
()
.
allMatch
((
cookie
)
->
cookie
.
getSameSite
().
equals
(
"Strict"
));
});
webExchange
.
getResponse
().
setComplete
().
block
();
exchange
.
accept
(
webExchange
);
};
}
private
Map
<
PathPattern
,
Object
>
getHandlerMap
(
ApplicationContext
context
)
{
...
...
@@ -600,12 +602,12 @@ class WebFluxAutoConfigurationTests {
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
CustomWebSessionIdResolver
s
{
static
class
CustomWebSessionIdResolver
{
@Bean
WebSessionIdResolver
webSessionIdResolver
()
{
CookieWebSessionIdResolver
resolver
=
new
CookieWebSessionIdResolver
();
resolver
.
setCookieName
(
"
JSESSIONID
"
);
resolver
.
setCookieName
(
"
TEST
"
);
return
resolver
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment