Search in sources :

Example 1 with SecurityContextPersistenceFilter

use of org.springframework.security.web.context.SecurityContextPersistenceFilter in project motech by motech.

the class SecurityRuleBuilder method addSecurityContextPersistenceFilter.

private void addSecurityContextPersistenceFilter(List<Filter> filters, SecurityContextRepository contextRepository) {
    SecurityContextPersistenceFilter securityContextFilter = new SecurityContextPersistenceFilter(contextRepository);
    filters.add(securityContextFilter);
}
Also used : SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter)

Example 2 with SecurityContextPersistenceFilter

use of org.springframework.security.web.context.SecurityContextPersistenceFilter in project spring-security by spring-projects.

the class SecurityContextConfigurer method configure.

@Override
@SuppressWarnings("unchecked")
public void configure(H http) {
    SecurityContextRepository securityContextRepository = http.getSharedObject(SecurityContextRepository.class);
    if (securityContextRepository == null) {
        securityContextRepository = new HttpSessionSecurityContextRepository();
    }
    SecurityContextPersistenceFilter securityContextFilter = new SecurityContextPersistenceFilter(securityContextRepository);
    SessionManagementConfigurer<?> sessionManagement = http.getConfigurer(SessionManagementConfigurer.class);
    SessionCreationPolicy sessionCreationPolicy = (sessionManagement != null) ? sessionManagement.getSessionCreationPolicy() : null;
    if (SessionCreationPolicy.ALWAYS == sessionCreationPolicy) {
        securityContextFilter.setForceEagerSessionCreation(true);
    }
    securityContextFilter = postProcess(securityContextFilter);
    http.addFilter(securityContextFilter);
}
Also used : SessionCreationPolicy(org.springframework.security.config.http.SessionCreationPolicy) HttpSessionSecurityContextRepository(org.springframework.security.web.context.HttpSessionSecurityContextRepository) SecurityContextRepository(org.springframework.security.web.context.SecurityContextRepository) HttpSessionSecurityContextRepository(org.springframework.security.web.context.HttpSessionSecurityContextRepository) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter)

Example 3 with SecurityContextPersistenceFilter

use of org.springframework.security.web.context.SecurityContextPersistenceFilter in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsJwtTests method setup.

@BeforeEach
public void setup() {
    SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(this.repository);
    MockServletContext servletContext = new MockServletContext();
    servletContext.setAttribute(BeanIds.SPRING_SECURITY_FILTER_CHAIN, new FilterChainProxy(new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, filter)));
    this.request = new MockHttpServletRequest(servletContext);
    WebTestUtils.setSecurityContextRepository(this.request, this.repository);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SecurityContextPersistenceFilter (org.springframework.security.web.context.SecurityContextPersistenceFilter)3 BeforeEach (org.junit.jupiter.api.BeforeEach)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 SessionCreationPolicy (org.springframework.security.config.http.SessionCreationPolicy)1 DefaultSecurityFilterChain (org.springframework.security.web.DefaultSecurityFilterChain)1 FilterChainProxy (org.springframework.security.web.FilterChainProxy)1 HttpSessionSecurityContextRepository (org.springframework.security.web.context.HttpSessionSecurityContextRepository)1 SecurityContextRepository (org.springframework.security.web.context.SecurityContextRepository)1