本文整理汇总了Java中org.springframework.security.web.context.HttpRequestResponseHolder类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestResponseHolder类的具体用法?Java HttpRequestResponseHolder怎么用?Java HttpRequestResponseHolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestResponseHolder类属于org.springframework.security.web.context包,在下文中一共展示了HttpRequestResponseHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSuccessfulAuthentication
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Override
protected void onSuccessfulAuthentication(HttpServletRequest request,
HttpServletResponse response, Authentication authResult) {
Object user=authResult.getPrincipal();
Assert.notNull(user,"通过Remember Me方式登录成功后未获取到用户信息");
HttpSession session=ContextHolder.getHttpSession();
IUser loginUser=null;
if(user instanceof IUser){
loginUser=(IUser)user;
}else if(user instanceof String){
loginUser=(IUser)userService.loadUserByUsername((String)user);
}else{
throw new RuntimeException("Unsupport current principal["+user+"]");
}
if(loginUser instanceof DefaultUser){
DefaultUser u=(DefaultUser)loginUser;
u.setDepts(deptService.loadUserDepts(u.getUsername()));
u.setPositions(positionService.loadUserPositions(u.getUsername()));
u.setGroups(groupService.loadUserGroups(u.getUsername()));
}
session.setAttribute(ContextHolder.USER_LOGIN_WAY_KEY, "rememberMe");
session.setAttribute(ContextHolder.LOGIN_USER_SESSION_KEY, loginUser);
this.doInterceptor(InterceptorType.success, new HttpRequestResponseHolder(request,response));
}
示例2: 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;
}
示例3: returnsSecurityContextWithAuthenticationForAuthenticatedRequest
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void returnsSecurityContextWithAuthenticationForAuthenticatedRequest() throws Exception {
TokenEncryption tokenEncryption = createJwtEncryption();
AuthenticationSerializer authenticationSerializer = new JsonAuthenticationSerializer();
CookieSecurityContextRepository repository = createCookieSecurityContextRepository(tokenEncryption, authenticationSerializer);
UserDetails userDetails = new User("username", "password", Collections.emptyList());
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, Collections.emptyList());
String serializedAuthentication = authenticationSerializer.serialize(authentication);
String payload = tokenEncryption.encryptAndSign(serializedAuthentication);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setCookies(new Cookie(AUTHENTICATION_COOKIE_NAME, payload));
MockHttpServletResponse response = new MockHttpServletResponse();
SecurityContext securityContext = repository.loadContext(new HttpRequestResponseHolder(request, response));
assertThat(securityContext.getAuthentication(), notNullValue());
UserDetails authenticatedUserDetails = (UserDetails) securityContext.getAuthentication().getPrincipal();
assertThat(authenticatedUserDetails.getUsername(), equalTo(userDetails.getUsername()));
}
示例4: 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());
}
示例5: expireAuthenticationCookieForEmptySecurityContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void expireAuthenticationCookieForEmptySecurityContext() throws Exception {
CookieSecurityContextRepository repository = createCookieSecurityContextRepository();
SecurityContext emptySecurityContext = SecurityContextHolder.createEmptyContext();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
repository.saveContext(emptySecurityContext, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
Cookie authenticationCookie = response.getCookie(AUTHENTICATION_COOKIE_NAME);
assertThat(authenticationCookie.getMaxAge(), equalTo(0));
assertThat(authenticationCookie.getValue(), isEmptyString());
assertTrue(authenticationCookie.getSecure());
assertTrue(authenticationCookie.isHttpOnly());
}
示例6: returnsSecurityContextWithAuthenticationForAuthenticatedRequest
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void returnsSecurityContextWithAuthenticationForAuthenticatedRequest() throws Exception {
CookieBasedSecurityContextRepository repository = createCookieBasedSecurityContextRepository();
JwtClientSerializer jwtClientSerializer = createJwtClientSerializer();
Client client = new Client("clientId", "familyName", "customerId", true, true, "unitId", "serviceId", "appointmentTypeId", true);
String payload = jwtClientSerializer.serialize(client);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setCookies(new Cookie(SecurityContextSerializer.COOKIE_NAME,payload));
MockHttpServletResponse response = new MockHttpServletResponse();
SecurityContext securityContext = repository.loadContext(new HttpRequestResponseHolder(request, response));
assertThat(securityContext.getAuthentication(), notNullValue());
Client authenticatedClient = (Client) securityContext.getAuthentication().getPrincipal();
assertThat(authenticatedClient.getClientId(), equalTo(client.getClientId()));
}
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:17,代码来源:CookieBasedSecurityContextRepositoryTest.java
示例7: 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
示例8: addSessionCookieOnResponseForNonEmptySecurityContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void addSessionCookieOnResponseForNonEmptySecurityContext() throws Exception {
CookieBasedSecurityContextRepository repository = createCookieBasedSecurityContextRepository();
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
Client client = new Client("clientId", "familyName", "customerId", true, true, "unitId", "serviceId", "appointmentTypeId", true);
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken(client, null, Collections.emptyList()));
String payload = createJwtClientSerializer().serialize(client);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
request.setCookies(new Cookie(SecurityContextSerializer.COOKIE_NAME,payload));
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
repository.saveContext(securityContext, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
Cookie sessionCookie = response.getCookie(SecurityContextSerializer.COOKIE_NAME);
assertThat(sessionCookie.getMaxAge(), equalTo(1800));
assertThat(sessionCookie.getValue().length(), greaterThan(0));
assertTrue(sessionCookie.getSecure());
assertTrue(sessionCookie.isHttpOnly());
}
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:24,代码来源:CookieBasedSecurityContextRepositoryTest.java
示例9: addCsrfCookieOnResponseForNonEmptySecurityContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void addCsrfCookieOnResponseForNonEmptySecurityContext() throws Exception {
CookieBasedSecurityContextRepository repository = createCookieBasedSecurityContextRepository();
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
Client client = new Client("clientId", "familyName", "customerId", true, true, "unitId", "serviceId", "appointmentTypeId", true);
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken(client, null, Collections.emptyList()));
String payload = createJwtClientSerializer().serialize(client);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
request.setCookies(new Cookie(SecurityContextSerializer.COOKIE_NAME, payload));
request.setCookies(new Cookie(CookieBasedCsrfTokenRepository.CSRF_COOKIE_AND_PARAMETER_NAME, "csrfTokenValue"));
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
repository.saveContext(securityContext, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
Cookie csrfCookie = response.getCookie(CookieBasedCsrfTokenRepository.CSRF_COOKIE_AND_PARAMETER_NAME);
assertThat(csrfCookie.getMaxAge(), equalTo(1800));
assertThat(csrfCookie.getValue(), equalTo("csrfTokenValue"));
assertTrue(csrfCookie.getSecure());
assertTrue(csrfCookie.isHttpOnly());
}
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:25,代码来源:CookieBasedSecurityContextRepositoryTest.java
示例10: expireSessionCookieForEmptySecurityContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Test
public void expireSessionCookieForEmptySecurityContext() throws Exception {
CookieBasedSecurityContextRepository repository = createCookieBasedSecurityContextRepository();
SecurityContext emptySecurityContext = SecurityContextHolder.createEmptyContext();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSecure(true);
MockHttpServletResponse response = new MockHttpServletResponse();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repository.loadContext(requestResponseHolder);
repository.saveContext(emptySecurityContext, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
Cookie sessionCookie = response.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
示例11: login
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public
@ResponseBody
User login(@RequestBody User user, HttpServletRequest request, HttpServletResponse response) {
User loginedUser = userService.sign(user.getUsername(), user.getPassword());
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(loginedUser, user.getPassword(), loginedUser.getAuthorities());
auth.setDetails(loginedUser.getId());
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(auth);
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
sessionSecurityContextRepository.saveContext(context, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
Long notification_count = notificationRepository.countByInbox(loginedUser.getInbox());
loginedUser.setNotificationCount(notification_count);
return loginedUser;
}
示例12: loadContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
String token = authStore.getToken(requestResponseHolder.getRequest(), authHeaderName);
if(logger.isDebugEnabled()){
logger.debug("load context user token : {}", token);
}
if(StringUtils.isBlank(token)){
return SecurityContextHolder.createEmptyContext();
}
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = null;
try {
authentication = jwtTokenService.createAuthentication(token);
} catch(CredentialsExpiredException e){
cookieStorer.clear(requestResponseHolder.getRequest(), requestResponseHolder.getResponse(), authHeaderName);
}
if(authentication!=null){
context.setAuthentication(authentication);
}
return context;
}
示例13: 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;
}
示例14: loadContext
import org.springframework.security.web.context.HttpRequestResponseHolder; //导入依赖的package包/类
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
wrapResponse(requestResponseHolder);
LOGGER.debug("Trying to load security context from request.");
Cookie securityCookie = getCookieForName(requestResponseHolder.getRequest().getCookies(),
cookieName);
if (securityCookie == null) {
LOGGER.debug("No security cookie found in request. Returning empty context.");
return createNewContext();
}
LOGGER.debug("Security cookie found, trying to deserialize");
SecurityCookie cookie = securityCookieMarshaller.getSecurityCookie(securityCookie.getValue());
if (cookie == null || !cookie.isValid()) {
LOGGER.debug("Security cookie was not valid. Returning empty context.");
requestResponseHolder.getResponse().addCookie(createRemovalCookie());
return createNewContext();
}
LOGGER.debug("Returning context from cookie.");
SecurityContext context = cookie.getSecurityContext();
renewContext(context, requestResponseHolder);
return context;
}
示例15: 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);
}