@Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext result = getContext(requestResponseHolder.getRequest()); // always load from the delegate to ensure the request/response in the holder are updated // remember the SecurityContextRepository is used in many different locations SecurityContext delegateResult = delegate.loadContext(requestResponseHolder); return result == null ? delegateResult : result; }
/** * Saves the {@link SecurityContext} using the {@link SecurityContextRepository} * * @param securityContext the {@link SecurityContext} to save * @param request the {@link HttpServletRequest} to use */ final void save(SecurityContext securityContext, HttpServletRequest request) { SecurityContextRepository securityContextRepository = WebTestUtils.getSecurityContextRepository(request); boolean isTestRepository = securityContextRepository instanceof TestSecurityContextRepository; if (!isTestRepository) { securityContextRepository = new TestSecurityContextRepository(securityContextRepository); WebTestUtils.setSecurityContextRepository(request, securityContextRepository); } HttpServletResponse response = new MockHttpServletResponse(); HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response); securityContextRepository.loadContext(requestResponseHolder); request = requestResponseHolder.getRequest(); response = requestResponseHolder.getResponse(); securityContextRepository.saveContext(securityContext, request, response); }