Search in sources :

Example 1 with RequestCache

use of org.springframework.security.web.savedrequest.RequestCache in project spring-security by spring-projects.

the class RequestCacheConfigurer method getRequestCache.

/**
	 * Gets the {@link RequestCache} to use. If one is defined using
	 * {@link #requestCache(org.springframework.security.web.savedrequest.RequestCache)},
	 * then it is used. Otherwise, an attempt to find a {@link RequestCache} shared object
	 * is made. If that fails, an {@link HttpSessionRequestCache} is used
	 *
	 * @param http the {@link HttpSecurity} to attempt to fined the shared object
	 * @return the {@link RequestCache} to use
	 */
private RequestCache getRequestCache(H http) {
    RequestCache result = http.getSharedObject(RequestCache.class);
    if (result != null) {
        return result;
    }
    HttpSessionRequestCache defaultCache = new HttpSessionRequestCache();
    defaultCache.setRequestMatcher(createDefaultSavedRequestMatcher(http));
    return defaultCache;
}
Also used : RequestCache(org.springframework.security.web.savedrequest.RequestCache) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache)

Example 2 with RequestCache

use of org.springframework.security.web.savedrequest.RequestCache in project spring-security by spring-projects.

the class SessionManagementConfigurer method init.

@Override
public void init(H http) throws Exception {
    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());
}
Also used : HttpSessionSecurityContextRepository(org.springframework.security.web.context.HttpSessionSecurityContextRepository) NullSecurityContextRepository(org.springframework.security.web.context.NullSecurityContextRepository) RequestCache(org.springframework.security.web.savedrequest.RequestCache) NullRequestCache(org.springframework.security.web.savedrequest.NullRequestCache) AuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver) NullSecurityContextRepository(org.springframework.security.web.context.NullSecurityContextRepository) HttpSessionSecurityContextRepository(org.springframework.security.web.context.HttpSessionSecurityContextRepository) SecurityContextRepository(org.springframework.security.web.context.SecurityContextRepository) NullRequestCache(org.springframework.security.web.savedrequest.NullRequestCache)

Example 3 with RequestCache

use of org.springframework.security.web.savedrequest.RequestCache in project spring-security by spring-projects.

the class RequestCacheConfigurer method configure.

@Override
public void configure(H http) throws Exception {
    RequestCache requestCache = getRequestCache(http);
    RequestCacheAwareFilter requestCacheFilter = new RequestCacheAwareFilter(requestCache);
    requestCacheFilter = postProcess(requestCacheFilter);
    http.addFilter(requestCacheFilter);
}
Also used : RequestCache(org.springframework.security.web.savedrequest.RequestCache) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) RequestCacheAwareFilter(org.springframework.security.web.savedrequest.RequestCacheAwareFilter)

Example 4 with RequestCache

use of org.springframework.security.web.savedrequest.RequestCache in project spring-security by spring-projects.

the class SavedRequestAwareAuthenticationSuccessHandlerTests method onAuthenticationSuccessHasSavedRequest.

@Test
public void onAuthenticationSuccessHasSavedRequest() throws Exception {
    String redirectUrl = "http://localhost/appcontext/page";
    RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
    RequestCache requestCache = mock(RequestCache.class);
    SavedRequest savedRequest = mock(SavedRequest.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    when(savedRequest.getRedirectUrl()).thenReturn(redirectUrl);
    when(requestCache.getRequest(request, response)).thenReturn(savedRequest);
    SavedRequestAwareAuthenticationSuccessHandler handler = new SavedRequestAwareAuthenticationSuccessHandler();
    handler.setRequestCache(requestCache);
    handler.setRedirectStrategy(redirectStrategy);
    handler.onAuthenticationSuccess(request, response, mock(Authentication.class));
    verify(redirectStrategy).sendRedirect(request, response, redirectUrl);
}
Also used : RequestCache(org.springframework.security.web.savedrequest.RequestCache) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.springframework.security.core.Authentication) RedirectStrategy(org.springframework.security.web.RedirectStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest) Test(org.junit.Test)

Aggregations

RequestCache (org.springframework.security.web.savedrequest.RequestCache)4 HttpSessionRequestCache (org.springframework.security.web.savedrequest.HttpSessionRequestCache)2 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AuthenticationTrustResolver (org.springframework.security.authentication.AuthenticationTrustResolver)1 Authentication (org.springframework.security.core.Authentication)1 RedirectStrategy (org.springframework.security.web.RedirectStrategy)1 HttpSessionSecurityContextRepository (org.springframework.security.web.context.HttpSessionSecurityContextRepository)1 NullSecurityContextRepository (org.springframework.security.web.context.NullSecurityContextRepository)1 SecurityContextRepository (org.springframework.security.web.context.SecurityContextRepository)1 NullRequestCache (org.springframework.security.web.savedrequest.NullRequestCache)1 RequestCacheAwareFilter (org.springframework.security.web.savedrequest.RequestCacheAwareFilter)1 SavedRequest (org.springframework.security.web.savedrequest.SavedRequest)1