use of org.springframework.web.server.WebSession in project spring-security by spring-projects.
the class WebSessionServerCsrfTokenRepositoryTests method saveTokenChangeSessionId.
@Test
public void saveTokenChangeSessionId() {
String originalSessionId = this.exchange.getSession().block().getId();
this.repository.saveToken(this.exchange, null).block();
WebSession session = this.exchange.getSession().block();
assertThat(session.getId()).isNotEqualTo(originalSessionId);
}
use of org.springframework.web.server.WebSession in project spring-security by spring-projects.
the class WebSessionServerCsrfTokenRepositoryTests method saveTokenWhenDefaultThenAddsToSession.
@Test
public void saveTokenWhenDefaultThenAddsToSession() {
Mono<CsrfToken> result = this.repository.generateToken(this.exchange).delayUntil((t) -> this.repository.saveToken(this.exchange, t));
result.block();
WebSession session = this.exchange.getSession().block();
Map<String, Object> attributes = session.getAttributes();
assertThat(session.isStarted()).isTrue();
assertThat(attributes).hasSize(1);
assertThat(attributes.values().iterator().next()).isInstanceOf(CsrfToken.class);
}
use of org.springframework.web.server.WebSession in project spring-security by spring-projects.
the class WebSessionServerSecurityContextRepositoryTests method saveAndLoadWhenCustomAttributeThenFound.
@Test
public void saveAndLoadWhenCustomAttributeThenFound() {
String attrName = "attr";
this.repository.setSpringSecurityContextAttrName(attrName);
SecurityContext expected = new SecurityContextImpl();
this.repository.save(this.exchange, expected).block();
WebSession session = this.exchange.getSession().block();
assertThat(session.<SecurityContext>getAttribute(attrName)).isEqualTo(expected);
SecurityContext actual = this.repository.load(this.exchange).block();
assertThat(actual).isEqualTo(expected);
}
Aggregations