Search in sources :

Example 11 with PortMapperImpl

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

the class LoginUrlAuthenticationEntryPointTests method testGettersSetters.

@Test
public void testGettersSetters() {
    LoginUrlAuthenticationEntryPoint ep = new LoginUrlAuthenticationEntryPoint("/hello");
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(8080, 8443));
    assertThat(ep.getLoginFormUrl()).isEqualTo("/hello");
    assertThat(ep.getPortMapper() != null).isTrue();
    assertThat(ep.getPortResolver() != null).isTrue();
    ep.setForceHttps(false);
    assertThat(ep.isForceHttps()).isFalse();
    ep.setForceHttps(true);
    assertThat(ep.isForceHttps()).isTrue();
    assertThat(ep.isUseForward()).isFalse();
    ep.setUseForward(true);
    assertThat(ep.isUseForward()).isTrue();
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) Test(org.junit.Test)

Example 12 with PortMapperImpl

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

the class RetryWithHttpsEntryPointTests method testOperationWithNonStandardPort.

@Test
public void testOperationWithNonStandardPort() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp/hello/pathInfo.html");
    request.setQueryString("open=true");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setServerPort(8888);
    MockHttpServletResponse response = new MockHttpServletResponse();
    PortMapperImpl portMapper = new PortMapperImpl();
    Map<String, String> map = new HashMap<String, String>();
    map.put("8888", "9999");
    portMapper.setPortMappings(map);
    RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
    ep.setPortResolver(new MockPortResolver(8888, 9999));
    ep.setPortMapper(portMapper);
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("https://www.example.com:9999/bigWebApp/hello/pathInfo.html?open=true");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RetryWithHttpsEntryPoint(org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 13 with PortMapperImpl

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

the class RetryWithHttpsEntryPointTests method testNormalOperation.

@Test
public void testNormalOperation() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp/hello/pathInfo.html");
    request.setQueryString("open=true");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setServerPort(80);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(80, 443));
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("https://www.example.com/bigWebApp/hello/pathInfo.html?open=true");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RetryWithHttpsEntryPoint(org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 14 with PortMapperImpl

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

the class RetryWithHttpsEntryPointTests method testNormalOperationWithNullQueryString.

@Test
public void testNormalOperationWithNullQueryString() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp/hello");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setServerPort(80);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(80, 443));
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("https://www.example.com/bigWebApp/hello");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RetryWithHttpsEntryPoint(org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

PortMapperImpl (org.springframework.security.web.PortMapperImpl)14 Test (org.junit.Test)13 MockPortResolver (org.springframework.security.MockPortResolver)13 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)11 RetryWithHttpsEntryPoint (org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint)5 HashMap (java.util.HashMap)2