use of org.springframework.security.web.PortMapper in project spring-security by spring-projects.
the class HttpsRedirectSpecTests method getWhenInsecureAndUsingCustomPortMapperThenRespondsWithRedirectToSecurePort.
@Test
public void getWhenInsecureAndUsingCustomPortMapperThenRespondsWithRedirectToSecurePort() {
this.spring.register(RedirectToHttpsViaCustomPortsConfig.class).autowire();
PortMapper portMapper = this.spring.getContext().getBean(PortMapper.class);
given(portMapper.lookupHttpsPort(4080)).willReturn(4443);
// @formatter:off
this.client.get().uri("http://localhost:4080").exchange().expectStatus().isFound().expectHeader().valueEquals(HttpHeaders.LOCATION, "https://localhost:4443");
// @formatter:on
}
use of org.springframework.security.web.PortMapper in project spring-security by spring-projects.
the class AbstractAuthenticationFilterConfigurer method configure.
@Override
public void configure(B http) throws Exception {
PortMapper portMapper = http.getSharedObject(PortMapper.class);
if (portMapper != null) {
this.authenticationEntryPoint.setPortMapper(portMapper);
}
RequestCache requestCache = http.getSharedObject(RequestCache.class);
if (requestCache != null) {
this.defaultSuccessHandler.setRequestCache(requestCache);
}
this.authFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
this.authFilter.setAuthenticationSuccessHandler(this.successHandler);
this.authFilter.setAuthenticationFailureHandler(this.failureHandler);
if (this.authenticationDetailsSource != null) {
this.authFilter.setAuthenticationDetailsSource(this.authenticationDetailsSource);
}
SessionAuthenticationStrategy sessionAuthenticationStrategy = http.getSharedObject(SessionAuthenticationStrategy.class);
if (sessionAuthenticationStrategy != null) {
this.authFilter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy);
}
RememberMeServices rememberMeServices = http.getSharedObject(RememberMeServices.class);
if (rememberMeServices != null) {
this.authFilter.setRememberMeServices(rememberMeServices);
}
F filter = postProcess(this.authFilter);
http.addFilter(filter);
}
use of org.springframework.security.web.PortMapper in project spring-security by spring-projects.
the class ChannelSecurityConfigurer method getChannelProcessors.
private List<ChannelProcessor> getChannelProcessors(H http) {
if (this.channelProcessors != null) {
return this.channelProcessors;
}
InsecureChannelProcessor insecureChannelProcessor = new InsecureChannelProcessor();
SecureChannelProcessor secureChannelProcessor = new SecureChannelProcessor();
PortMapper portMapper = http.getSharedObject(PortMapper.class);
if (portMapper != null) {
RetryWithHttpEntryPoint httpEntryPoint = new RetryWithHttpEntryPoint();
httpEntryPoint.setPortMapper(portMapper);
httpEntryPoint.setRedirectStrategy(this.redirectStrategy);
insecureChannelProcessor.setEntryPoint(httpEntryPoint);
RetryWithHttpsEntryPoint httpsEntryPoint = new RetryWithHttpsEntryPoint();
httpsEntryPoint.setPortMapper(portMapper);
httpsEntryPoint.setRedirectStrategy(this.redirectStrategy);
secureChannelProcessor.setEntryPoint(httpsEntryPoint);
}
insecureChannelProcessor = postProcess(insecureChannelProcessor);
secureChannelProcessor = postProcess(secureChannelProcessor);
return Arrays.asList(insecureChannelProcessor, secureChannelProcessor);
}
use of org.springframework.security.web.PortMapper in project spring-security by spring-projects.
the class HttpsRedirectSpecTests method getWhenInsecureAndUsingCustomPortMapperInLambdaThenRespondsWithRedirectToSecurePort.
@Test
public void getWhenInsecureAndUsingCustomPortMapperInLambdaThenRespondsWithRedirectToSecurePort() {
this.spring.register(RedirectToHttpsViaCustomPortsInLambdaConfig.class).autowire();
PortMapper portMapper = this.spring.getContext().getBean(PortMapper.class);
given(portMapper.lookupHttpsPort(4080)).willReturn(4443);
// @formatter:off
this.client.get().uri("http://localhost:4080").exchange().expectStatus().isFound().expectHeader().valueEquals(HttpHeaders.LOCATION, "https://localhost:4443");
// @formatter:on
}
use of org.springframework.security.web.PortMapper in project spring-security by spring-projects.
the class HttpsRedirectWebFilterTests method filterWhenRequestIsInsecureThenPortMapperRemapsPort.
@Test
public void filterWhenRequestIsInsecureThenPortMapperRemapsPort() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
PortMapper portMapper = mock(PortMapper.class);
given(portMapper.lookupHttpsPort(314)).willReturn(159);
this.filter.setPortMapper(portMapper);
ServerWebExchange exchange = get("http://localhost:314");
this.filter.filter(exchange, this.chain).block();
assertThat(statusCode(exchange)).isEqualTo(302);
assertThat(redirectedUrl(exchange)).isEqualTo("https://localhost:159");
verify(portMapper).lookupHttpsPort(314);
}
Aggregations