use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class DefaultSessionAuthenticationStrategyTests method newSessionShouldNotBeCreatedIfNoSessionExistsAndAlwaysCreateIsFalse.
@Test
public void newSessionShouldNotBeCreatedIfNoSessionExistsAndAlwaysCreateIsFalse() {
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
HttpServletRequest request = new MockHttpServletRequest();
strategy.onAuthentication(mock(Authentication.class), request, new MockHttpServletResponse());
assertThat(request.getSession(false)).isNull();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class DefaultSessionAuthenticationStrategyTests method newSessionIsCreatedIfSessionAlreadyExists.
@Test
public void newSessionIsCreatedIfSessionAlreadyExists() {
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
HttpServletRequest request = new MockHttpServletRequest();
String sessionId = request.getSession().getId();
strategy.onAuthentication(mock(Authentication.class), request, new MockHttpServletResponse());
assertThat(sessionId.equals(request.getSession().getId())).isFalse();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class DefaultSessionAuthenticationStrategyTests method onAuthenticationWhenMigrateSessionAttributesTrueThenMaxInactiveIntervalIsMigrated.
@Test
public void onAuthenticationWhenMigrateSessionAttributesTrueThenMaxInactiveIntervalIsMigrated() {
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
HttpServletRequest request = new MockHttpServletRequest();
HttpSession session = request.getSession();
session.setMaxInactiveInterval(1);
Authentication mockAuthentication = mock(Authentication.class);
strategy.onAuthentication(mockAuthentication, request, new MockHttpServletResponse());
assertThat(request.getSession().getMaxInactiveInterval()).isEqualTo(1);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class DefaultSessionAuthenticationStrategyTests method onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalse.
// See SEC-1077
@Test
public void onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalse() {
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
strategy.setMigrateSessionAttributes(false);
HttpServletRequest request = new MockHttpServletRequest();
HttpSession session = request.getSession();
session.setAttribute("blah", "blah");
session.setAttribute("SPRING_SECURITY_SAVED_REQUEST_KEY", "DefaultSavedRequest");
strategy.onAuthentication(mock(Authentication.class), request, new MockHttpServletResponse());
assertThat(request.getSession().getAttribute("blah")).isNull();
assertThat(request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST_KEY")).isNotNull();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.
the class SessionManagementFilterTests method strategyIsInvokedIfUserIsNewlyAuthenticated.
@Test
public void strategyIsInvokedIfUserIsNewlyAuthenticated() throws Exception {
SecurityContextRepository repo = mock(SecurityContextRepository.class);
// repo will return false to containsContext()
SessionAuthenticationStrategy strategy = mock(SessionAuthenticationStrategy.class);
SessionManagementFilter filter = new SessionManagementFilter(repo, strategy);
HttpServletRequest request = new MockHttpServletRequest();
authenticateUser();
filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
verify(strategy).onAuthentication(any(Authentication.class), any(HttpServletRequest.class), any(HttpServletResponse.class));
// Check that it is only applied once to the request
filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
verifyNoMoreInteractions(strategy);
}
Aggregations