use of org.springframework.security.web.context.HttpSessionSecurityContextRepository in project motech by motech.
the class SecurityRuleBuilder method addFilters.
private List<Filter> addFilters(MotechURLSecurityRule securityRule) throws ServletException {
List<Filter> filters = new ArrayList<>();
SecurityContextRepository contextRepository = new HttpSessionSecurityContextRepository();
RequestCache requestCache = new HttpSessionRequestCache();
addSecureChannel(filters, securityRule.getProtocol());
addSecurityContextPersistenceFilter(filters, contextRepository);
addLogoutFilter(filters, securityRule);
addAuthenticationFilters(filters, securityRule);
addRequestCacheFilter(filters, requestCache);
addSecurityContextHolderAwareRequestFilter(filters);
addAnonymousAuthenticationFilter(filters);
addSessionManagementFilter(filters, contextRepository);
addExceptionTranslationFilter(filters, requestCache, securityRule.isRest());
addFilterSecurityInterceptor(filters, securityRule);
return filters;
}
use of org.springframework.security.web.context.HttpSessionSecurityContextRepository 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);
}
use of org.springframework.security.web.context.HttpSessionSecurityContextRepository in project spring-security by spring-projects.
the class SessionManagementConfigurer method init.
@Override
public void init(H http) {
SecurityContextRepository securityContextRepository = http.getSharedObject(SecurityContextRepository.class);
boolean stateless = isStateless();
if (securityContextRepository == null) {
if (stateless) {
http.setSharedObject(SecurityContextRepository.class, new NullSecurityContextRepository());
} else {
HttpSessionSecurityContextRepository httpSecurityRepository = new HttpSessionSecurityContextRepository();
httpSecurityRepository.setDisableUrlRewriting(!this.enableSessionUrlRewriting);
httpSecurityRepository.setAllowSessionCreation(isAllowSessionCreation());
AuthenticationTrustResolver trustResolver = http.getSharedObject(AuthenticationTrustResolver.class);
if (trustResolver != null) {
httpSecurityRepository.setTrustResolver(trustResolver);
}
http.setSharedObject(SecurityContextRepository.class, httpSecurityRepository);
}
}
RequestCache requestCache = http.getSharedObject(RequestCache.class);
if (requestCache == null) {
if (stateless) {
http.setSharedObject(RequestCache.class, new NullRequestCache());
}
}
http.setSharedObject(SessionAuthenticationStrategy.class, getSessionAuthenticationStrategy(http));
http.setSharedObject(InvalidSessionStrategy.class, getInvalidSessionStrategy());
}
use of org.springframework.security.web.context.HttpSessionSecurityContextRepository in project spring-security by spring-projects.
the class SessionManagementConfigServlet31Tests method login.
private void login(Authentication auth) {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(this.request, this.response);
repo.loadContext(requestResponseHolder);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(auth);
repo.saveContext(securityContextImpl, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
}
use of org.springframework.security.web.context.HttpSessionSecurityContextRepository in project spring-security by spring-projects.
the class SessionManagementConfigurerServlet31Tests method login.
private void login(Authentication auth) {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(this.request, this.response);
repo.loadContext(requestResponseHolder);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(auth);
repo.saveContext(securityContextImpl, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
}
Aggregations