本文整理汇总了Java中org.springframework.security.web.context.HttpRequestResponseHolder.getResponse方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestResponseHolder.getResponse方法的具体用法?Java HttpRequestResponseHolder.getResponse怎么用?Java HttpRequestResponseHolder.getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.web.context.HttpRequestResponseHolder
的用法示例。
在下文中一共展示了HttpRequestResponseHolder.getResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
/**
* Obtains the security context for the supplied request. For an unauthenticated user, an empty context
* implementation should be returned. This method should not return null.
* <p>
* The use of the <tt>HttpRequestResponseHolder</tt> parameter allows implementations to return wrapped versions of
* the request or response (or both), allowing them to access implementation-specific state for the request.
* The values obtained from the holder will be passed on to the filter chain and also to the <tt>saveContext</tt>
* method when it is finally called. Implementations may wish to return a subclass of
* {@link SaveContextOnUpdateOrErrorResponseWrapper} as the response object, which guarantees that the context is
* persisted when an error or redirect occurs.
*
* @param requestResponseHolder holder for the current request and response for which the context should be loaded.
*
* @return The security context which should be used for the current request, never null.
*/
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
HttpServletRequest request = requestResponseHolder.getRequest();
HttpServletResponse response = requestResponseHolder.getResponse();
requestResponseHolder.setResponse(new SaveToCookieResponseWrapper(request, response));
Cookie authenticationCookie = getAuthenticationCookie(request);
if (authenticationCookie == null) {
return SecurityContextHolder.createEmptyContext();
}
String serialisedAuthentication = tokenEncryption.decryptAndVerify(authenticationCookie.getValue());
if (serialisedAuthentication == null) {
response.addCookie(createExpireAuthenticationCookie(request));
return SecurityContextHolder.createEmptyContext();
}
Authentication authentication = authenticationSerializer.deserialize(serialisedAuthentication);
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
securityContext.setAuthentication(authentication);
return securityContext;
}
示例2: expireAuthenticationCookieForExpiredAuthToken
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
@Test
public void expireAuthenticationCookieForExpiredAuthToken() throws Exception {
CookieSecurityContextRepository repository = createCookieSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
request.setCookies(new Cookie(AUTHENTICATION_COOKIE_NAME, "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..v3OyQykgTQI5U7gP.dKsmMKX1MHGoMx2rXrCCWOCbyax-J8JS6gu63OBXEDm7Ab926OwlwlZcvoOZGW5nO7ZR95h2pe8pQs8s8cqWJUO4L4dGI9jTj4jK_Lsy9cPWDY4BMzs2bVBuasn88OQYjC-3zuZyvPKfQHrSVS9OjTaMLeMBwMfKP-k3IysOUfUtWUNcRb86v7VCnOd0ATljXUN8DekK8iZ0wD5AtBJVaOQLbaNWiXGY2pnA2eOW9cI_vPbCqqn4ZW-r7sEy6UzHgXYgRAr4bKb7abVtRvO1Xg3CcpquE597Om0bKJIk-VVCz7fVzpz5rkp16vzN-RKBJBs2MK-UsXKD9Lkgedh5w--Q4muiWrAqA5_Tx36mvkESlzR5pbsKu84ZweE5dfen47q_BWaZguVb8jFJB1pofpEgNiZ1C1K8aKIO03CIR-cOOfvoPrsdte-0M4F5bq4KwLna8fYm9D3OeJN3sai3Ba2KKPtLsfz-F5jJlCOV44JE-F9Pqa1xfdpD_S5UenWFi9IUsM912BoCTX4ouEMP6ZUVHwKgTeFjInJXe6iJVqvhPfrWUeVUBmBURy_8XGrzW12GqN_Qp_-275gQ_jlQfyMsdtkLdMp9YxpIbPb4Whq0ey5eKvy924Z4aWKQcw6SrVPAhFjXbvtwGVJYv2lzQ2vQIDE9g1dxqPpRvAG_qb_4M3Xfhtjo2W1Md-U1Oo5cfDsrbqeeegeYDH_AA5t5tJxLDB7TtR8xtjFb52WNItxcKeMnb6jegAwWlEjAkAqY.1d7Z0BNKOegXeUI_fY8yQg"));
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
ServletResponseWrapper responseWrapper = (ServletResponseWrapper) requestResponseHolder.getResponse();
MockHttpServletResponse wrappedResponse = (MockHttpServletResponse) responseWrapper.getResponse();
Cookie authenticationCookie = wrappedResponse.getCookie(AUTHENTICATION_COOKIE_NAME);
assertThat(authenticationCookie.getMaxAge(), equalTo(0));
assertThat(authenticationCookie.getValue(), isEmptyString());
assertTrue(authenticationCookie.getSecure());
assertTrue(authenticationCookie.isHttpOnly());
}
示例3: expireSessionCookieForExpiredAuthToken
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
@Test
public void expireSessionCookieForExpiredAuthToken() throws Exception {
CookieBasedSecurityContextRepository repository = createCookieBasedSecurityContextRepository();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
request.setCookies(new Cookie(SecurityContextSerializer.COOKIE_NAME, "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..v3OyQykgTQI5U7gP.dKsmMKX1MHGoMx2rXrCCWOCbyax-J8JS6gu63OBXEDm7Ab926OwlwlZcvoOZGW5nO7ZR95h2pe8pQs8s8cqWJUO4L4dGI9jTj4jK_Lsy9cPWDY4BMzs2bVBuasn88OQYjC-3zuZyvPKfQHrSVS9OjTaMLeMBwMfKP-k3IysOUfUtWUNcRb86v7VCnOd0ATljXUN8DekK8iZ0wD5AtBJVaOQLbaNWiXGY2pnA2eOW9cI_vPbCqqn4ZW-r7sEy6UzHgXYgRAr4bKb7abVtRvO1Xg3CcpquE597Om0bKJIk-VVCz7fVzpz5rkp16vzN-RKBJBs2MK-UsXKD9Lkgedh5w--Q4muiWrAqA5_Tx36mvkESlzR5pbsKu84ZweE5dfen47q_BWaZguVb8jFJB1pofpEgNiZ1C1K8aKIO03CIR-cOOfvoPrsdte-0M4F5bq4KwLna8fYm9D3OeJN3sai3Ba2KKPtLsfz-F5jJlCOV44JE-F9Pqa1xfdpD_S5UenWFi9IUsM912BoCTX4ouEMP6ZUVHwKgTeFjInJXe6iJVqvhPfrWUeVUBmBURy_8XGrzW12GqN_Qp_-275gQ_jlQfyMsdtkLdMp9YxpIbPb4Whq0ey5eKvy924Z4aWKQcw6SrVPAhFjXbvtwGVJYv2lzQ2vQIDE9g1dxqPpRvAG_qb_4M3Xfhtjo2W1Md-U1Oo5cfDsrbqeeegeYDH_AA5t5tJxLDB7TtR8xtjFb52WNItxcKeMnb6jegAwWlEjAkAqY.1d7Z0BNKOegXeUI_fY8yQg"));
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
ServletResponseWrapper responseWrapper = (ServletResponseWrapper) requestResponseHolder.getResponse();
MockHttpServletResponse wrappedResponse = (MockHttpServletResponse) responseWrapper.getResponse();
Cookie sessionCookie = wrappedResponse.getCookie(SecurityContextSerializer.COOKIE_NAME);
assertThat(sessionCookie.getMaxAge(), equalTo(0));
assertThat(sessionCookie.getValue(), isEmptyString());
assertTrue(sessionCookie.getSecure());
assertTrue(sessionCookie.isHttpOnly());
}
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:20,代码来源:CookieBasedSecurityContextRepositoryTest.java
示例4: loadContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
HttpServletRequest request = requestResponseHolder.getRequest();
HttpServletResponse response = requestResponseHolder.getResponse();
HttpSession httpSession = request.getSession(false);
String sid = this.getSessionId(request, true);
SecurityContext context = readSecurityContextFromSession(request);
if (context == null) {
context = SecurityContextHolder.createEmptyContext();
}
SaveToSessionResponseWrapper wrappedResponse = new SaveToSessionResponseWrapper(
response, request, httpSession != null, context, sid);
requestResponseHolder.setResponse(wrappedResponse);
if (isServlet3) {
requestResponseHolder.setRequest(new Servlet3SaveToSessionRequestWrapper(request, wrappedResponse));
}
return context;
}
示例5: save
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
final void save(SecurityContext securityContext, HttpServletRequest request) {
HttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
this.repository.loadContext(requestResponseHolder);
request = requestResponseHolder.getRequest();
response = requestResponseHolder.getResponse();
this.repository.saveContext(securityContext, request, response);
}
示例6: save
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
final void save(SecurityContext securityContext, HttpServletRequest request) {
HttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
this.repository.loadContext(requestResponseHolder);
request = requestResponseHolder.getRequest();
response = requestResponseHolder.getResponse();
this.repository.saveContext(securityContext, request, response);
}
示例7: save
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
final void save(SecurityContext securityContext, HttpServletRequest request) {
HttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
request = requestResponseHolder.getRequest();
response = requestResponseHolder.getResponse();
repository.saveContext(securityContext, request, response);
}
示例8: loadContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入方法依赖的package包/类
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
SaveToCookieResponseWrapper responseWrapper = new SaveToCookieResponseWrapper(requestResponseHolder.getRequest(), requestResponseHolder.getResponse(), true);
requestResponseHolder.setResponse(responseWrapper);
return securityContextSerializer.deserialize(requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
}
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:7,代码来源:CookieBasedSecurityContextRepository.java