use of org.springframework.mock.web.MockHttpSession in project spring-security-oauth by spring-projects.
the class HttpSessionOAuthRememberMeServicesTests method testEmptySession.
@Test
public void testEmptySession() {
MockHttpSession mockHttpSession = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setSession(mockHttpSession);
HttpSessionOAuthRememberMeServices oAuthRememberMeService = new HttpSessionOAuthRememberMeServices();
Map<String, OAuthConsumerToken> tokens = oAuthRememberMeService.loadRememberedTokens(request, response);
Assert.assertNull(tokens);
}
use of org.springframework.mock.web.MockHttpSession in project spring-security-oauth by spring-projects.
the class HttpSessionOAuthRememberMeServicesTests method testStoreEverything.
@Test
public void testStoreEverything() {
MockHttpSession mockHttpSession = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setSession(mockHttpSession);
HttpSessionOAuthRememberMeServices oAuthRememberMeService = new HttpSessionOAuthRememberMeServices();
Map<String, OAuthConsumerToken> tokens = new HashMap<String, OAuthConsumerToken>();
{
OAuthConsumerToken token = new OAuthConsumerToken();
token.setAccessToken(false);
tokens.put("resourceID1", token);
}
{
OAuthConsumerToken token = new OAuthConsumerToken();
token.setAccessToken(true);
tokens.put("resourceID2", token);
}
oAuthRememberMeService.rememberTokens(tokens, request, response);
Assert.assertEquals(1, oAuthRememberMeService.loadRememberedTokens(request, response).size());
}
use of org.springframework.mock.web.MockHttpSession in project spring-security-oauth by spring-projects.
the class HttpSessionOAuthRememberMeServicesTests method testStoreRequestTokensOnly.
@Test
public void testStoreRequestTokensOnly() {
MockHttpSession mockHttpSession = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setSession(mockHttpSession);
HttpSessionOAuthRememberMeServices oAuthRememberMeService = new HttpSessionOAuthRememberMeServices();
Map<String, OAuthConsumerToken> tokens = new HashMap<String, OAuthConsumerToken>();
{
OAuthConsumerToken token = new OAuthConsumerToken();
token.setAccessToken(false);
tokens.put("resourceID1", token);
}
{
OAuthConsumerToken token = new OAuthConsumerToken();
token.setAccessToken(true);
tokens.put("resourceID2", token);
}
oAuthRememberMeService.rememberTokens(tokens, request, response);
Map<String, OAuthConsumerToken> storedTokens = oAuthRememberMeService.loadRememberedTokens(request, response);
Assert.assertEquals(1, storedTokens.size());
Assert.assertNotNull(storedTokens.get("resourceID1"));
}
use of org.springframework.mock.web.MockHttpSession in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests method setUp.
@Before
public void setUp() {
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
}
use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.
the class ConcurrentSessionManagementTests method maxConcurrentLoginsValueIsRespected.
@Test
public void maxConcurrentLoginsValueIsRespected() throws Exception {
final MockHttpSession session1 = new MockHttpSession();
final MockHttpSession session2 = new MockHttpSession();
MockMvc mockMvc = createMockMvc("classpath:/spring/http-security-concurrency.xml", "classpath:/spring/in-memory-provider.xml", "classpath:/spring/testapp-servlet.xml");
mockMvc.perform(get("secure/index").session(session1)).andExpect(status().is3xxRedirection());
MockHttpServletRequestBuilder login1 = login().session(session1);
mockMvc.perform(login1).andExpect(authenticated().withUsername("jimi"));
MockHttpServletRequestBuilder login2 = login().session(session2);
mockMvc.perform(login2).andExpect(redirectedUrl("/login.jsp?login_error=true"));
Exception exception = (Exception) session2.getAttribute("SPRING_SECURITY_LAST_EXCEPTION");
assertThat(exception).isNotNull();
assertThat(exception.getMessage()).contains("Maximum sessions of 1 for this principal exceeded");
// Now logout to kill first session
mockMvc.perform(post("/logout").with(csrf())).andExpect(status().is3xxRedirection()).andDo(new ResultHandler() {
@SuppressWarnings("serial")
@Override
public void handle(MvcResult result) throws Exception {
context.publishEvent(new SessionDestroyedEvent(session1) {
@Override
public List<SecurityContext> getSecurityContexts() {
return Collections.emptyList();
}
@Override
public String getId() {
return session1.getId();
}
});
}
});
// Try second session again
login2 = login().session(session2);
mockMvc.perform(login2).andExpect(authenticated().withUsername("jimi"));
mockMvc.perform(get("/secure/index").session(session2)).andExpect(content().string(containsString("A Secure Page")));
}
Aggregations