|
109 | 109 | import org.springframework.web.server.i18n.FixedLocaleContextResolver;
|
110 | 110 | import org.springframework.web.server.i18n.LocaleContextResolver;
|
111 | 111 | import org.springframework.web.server.session.CookieWebSessionIdResolver;
|
| 112 | +import org.springframework.web.server.session.DefaultWebSessionManager; |
| 113 | +import org.springframework.web.server.session.InMemoryWebSessionStore; |
112 | 114 | import org.springframework.web.server.session.WebSessionIdResolver;
|
113 | 115 | import org.springframework.web.server.session.WebSessionManager;
|
| 116 | +import org.springframework.web.server.session.WebSessionStore; |
114 | 117 | import org.springframework.web.util.pattern.PathPattern;
|
115 | 118 |
|
116 | 119 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -622,6 +625,20 @@ void customSessionTimeoutConfigurationShouldBeApplied() {
|
622 | 625 | })));
|
623 | 626 | }
|
624 | 627 |
|
| 628 | + @Test |
| 629 | + void customSessionMaxSessionsConfigurationShouldBeApplied() { |
| 630 | + this.contextRunner.withPropertyValues("server.reactive.session.max-sessions:123") |
| 631 | + .run((context) -> assertMaxSessionsWithWebSession(123)); |
| 632 | + } |
| 633 | + |
| 634 | + @Test |
| 635 | + void defaultSessionMaxSessionsConfigurationShouldBeInSync() { |
| 636 | + this.contextRunner.run((context) -> { |
| 637 | + int defaultMaxSessions = new InMemoryWebSessionStore().getMaxSessions(); |
| 638 | + assertMaxSessionsWithWebSession(defaultMaxSessions); |
| 639 | + }); |
| 640 | + } |
| 641 | + |
625 | 642 | @Test
|
626 | 643 | void customSessionCookieConfigurationShouldBeApplied() {
|
627 | 644 | this.contextRunner.withPropertyValues("server.reactive.session.cookie.name:JSESSIONID",
|
@@ -753,6 +770,16 @@ private ContextConsumer<ReactiveWebApplicationContext> assertSessionTimeoutWithW
|
753 | 770 | };
|
754 | 771 | }
|
755 | 772 |
|
| 773 | + private ContextConsumer<ReactiveWebApplicationContext> assertMaxSessionsWithWebSession(int maxSessions) { |
| 774 | + return (context) -> { |
| 775 | + WebSessionManager sessionManager = context.getBean(WebSessionManager.class); |
| 776 | + assertThat(sessionManager).isInstanceOf(DefaultWebSessionManager.class); |
| 777 | + WebSessionStore sessionStore = ((DefaultWebSessionManager) sessionManager).getSessionStore(); |
| 778 | + assertThat(sessionStore).isInstanceOf(InMemoryWebSessionStore.class); |
| 779 | + assertThat(((InMemoryWebSessionStore) sessionStore).getMaxSessions()).isEqualTo(maxSessions); |
| 780 | + }; |
| 781 | + } |
| 782 | + |
756 | 783 | private Map<PathPattern, Object> getHandlerMap(ApplicationContext context) {
|
757 | 784 | HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
|
758 | 785 | if (mapping instanceof SimpleUrlHandlerMapping simpleMapping) {
|
|
0 commit comments