Search in sources :

Example 11 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project spring-security-oauth by spring-projects.

the class HttpSessionOAuthRememberMeServicesTests method testNoTokensRemembered.

@Test
public void testNoTokensRemembered() {
    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>();
    oAuthRememberMeService.rememberTokens(tokens, request, response);
    Assert.assertEquals(0, oAuthRememberMeService.loadRememberedTokens(request, response).size());
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) OAuthConsumerToken(org.springframework.security.oauth.consumer.OAuthConsumerToken) Test(org.junit.Test)

Example 12 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.

the class HttpNamespaceWithMultipleInterceptorsTests method createAuthenticatedSession.

public HttpSession createAuthenticatedSession(String... roles) {
    MockHttpSession session = new MockHttpSession();
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
    SecurityContextHolder.clearContext();
    return session;
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 13 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.

the class HttpPathParameterStrippingTests method createAuthenticatedSession.

public HttpSession createAuthenticatedSession(String... roles) {
    MockHttpSession session = new MockHttpSession();
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
    SecurityContextHolder.clearContext();
    return session;
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 14 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.

the class FilterChainPerformanceTests method createAuthenticatedSession.

@Before
public void createAuthenticatedSession() {
    session = new MockHttpSession();
    SecurityContextHolder.getContext().setAuthentication(user);
    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
    SecurityContextHolder.clearContext();
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession)

Example 15 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.

the class HttpSessionEventPublisherTests method sessionCreatedNullApplicationContext.

// SEC-2599
@Test(expected = IllegalStateException.class)
public void sessionCreatedNullApplicationContext() {
    HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
    MockServletContext servletContext = new MockServletContext();
    MockHttpSession session = new MockHttpSession(servletContext);
    HttpSessionEvent event = new HttpSessionEvent(session);
    publisher.sessionCreated(event);
}
Also used : HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

MockHttpSession (org.springframework.mock.web.MockHttpSession)106 Test (org.junit.Test)84 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)34 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)23 HashMap (java.util.HashMap)13 AbstractWebApiTest (org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)13 MockFilterChain (org.springframework.mock.web.MockFilterChain)12 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)11 ModelAndView (org.springframework.web.servlet.ModelAndView)11 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)9 FilterChain (javax.servlet.FilterChain)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 SessionRegistry (org.springframework.security.core.session.SessionRegistry)8 ConcurrentSessionFilter (org.springframework.security.web.session.ConcurrentSessionFilter)8 Principal (org.apereo.cas.authentication.principal.Principal)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 CasProfile (org.pac4j.cas.profile.CasProfile)7 InputStream (java.io.InputStream)6 Before (org.junit.Before)6