Search in sources :

Example 1 with DefaultWebSessionManager

use of org.springframework.web.server.session.DefaultWebSessionManager in project spring-session by spring-projects.

the class SpringWebSessionConfigurationTests method providedSessionIdResolverShouldBePickedUpAutomatically.

@Test
public void providedSessionIdResolverShouldBePickedUpAutomatically() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(OverrideSessionIdResolver.class);
    this.context.refresh();
    DefaultWebSessionManager manager = this.context.getBean(DefaultWebSessionManager.class);
    assertThat(manager.getSessionIdResolver().getClass()).isAssignableFrom(HeaderWebSessionIdResolver.class);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Test(org.junit.Test)

Example 2 with DefaultWebSessionManager

use of org.springframework.web.server.session.DefaultWebSessionManager in project spring-session by spring-projects.

the class SpringWebSessionConfigurationTests method defaultSessionIdResolverShouldBeCookieBased.

@Test
public void defaultSessionIdResolverShouldBeCookieBased() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(GoodConfig.class);
    this.context.refresh();
    DefaultWebSessionManager manager = this.context.getBean(DefaultWebSessionManager.class);
    assertThat(manager.getSessionIdResolver().getClass()).isAssignableFrom(CookieWebSessionIdResolver.class);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Test(org.junit.Test)

Example 3 with DefaultWebSessionManager

use of org.springframework.web.server.session.DefaultWebSessionManager in project spring-security by spring-projects.

the class PathMatcherServerWebExchangeMatcherTests method setup.

@BeforeEach
public void setup() {
    MockServerHttpRequest request = MockServerHttpRequest.post("/path").build();
    MockServerHttpResponse response = new MockServerHttpResponse();
    DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
    this.exchange = MockServerWebExchange.from(request);
    this.path = "/path";
    this.matcher = new PathPatternParserServerWebExchangeMatcher(this.pattern);
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) MockServerHttpResponse(org.springframework.mock.http.server.reactive.MockServerHttpResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with DefaultWebSessionManager

use of org.springframework.web.server.session.DefaultWebSessionManager in project spring-framework by spring-projects.

the class FreeMarkerViewTests method subscribeWithoutDemand.

// gh-22754
@Test
public void subscribeWithoutDemand() {
    ZeroDemandResponse response = new ZeroDemandResponse();
    ServerWebExchange exchange = new DefaultServerWebExchange(MockServerHttpRequest.get("/path").build(), response, new DefaultWebSessionManager(), ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
    FreeMarkerView view = new FreeMarkerView();
    view.setApplicationContext(this.context);
    view.setConfiguration(this.freeMarkerConfig);
    view.setUrl("test.ftl");
    ModelMap model = new ExtendedModelMap();
    model.addAttribute("hello", "hi FreeMarker");
    view.render(model, null, exchange).subscribe();
    response.cancelWrite();
    response.checkForLeaks();
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ZeroDemandResponse(org.springframework.web.reactive.result.view.ZeroDemandResponse) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ModelMap(org.springframework.ui.ModelMap) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultWebSessionManager

use of org.springframework.web.server.session.DefaultWebSessionManager in project spring-session by spring-projects.

the class SpringWebSessionConfiguration method webSessionManager.

/**
 * Configure a {@link WebSessionManager} using a provided {@link ReactiveSessionRepository}.
 *
 * @param repository a bean that implements {@link ReactiveSessionRepository}.
 * @return a configured {@link WebSessionManager} registered with a preconfigured name.
 */
@Bean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME)
public WebSessionManager webSessionManager(ReactiveSessionRepository<? extends Session> repository) {
    SpringSessionWebSessionStore<? extends Session> sessionStore = new SpringSessionWebSessionStore<>(repository);
    DefaultWebSessionManager manager = new DefaultWebSessionManager();
    manager.setSessionStore(sessionStore);
    if (this.webSessionIdResolver != null) {
        manager.setSessionIdResolver(this.webSessionIdResolver);
    }
    return manager;
}
Also used : SpringSessionWebSessionStore(org.springframework.session.web.server.session.SpringSessionWebSessionStore) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultWebSessionManager (org.springframework.web.server.session.DefaultWebSessionManager)6 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ZeroDemandResponse (org.springframework.web.reactive.result.view.ZeroDemandResponse)2 ServerWebExchange (org.springframework.web.server.ServerWebExchange)2 DefaultServerWebExchange (org.springframework.web.server.adapter.DefaultServerWebExchange)2 AcceptHeaderLocaleContextResolver (org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)2 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)2 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Bean (org.springframework.context.annotation.Bean)1 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)1 MockServerHttpResponse (org.springframework.mock.http.server.reactive.MockServerHttpResponse)1 SpringSessionWebSessionStore (org.springframework.session.web.server.session.SpringSessionWebSessionStore)1 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)1 ModelMap (org.springframework.ui.ModelMap)1