Allow configuration of requires channel through nested builder

Issue: gh-5557
This commit is contained in:
Eleftheria Stein
2019-07-04 16:55:38 -04:00
parent ae8e12f049
commit 1ad9f15e19
3 changed files with 81 additions and 9 deletions

View File

@@ -135,4 +135,27 @@ public class ChannelSecurityConfigurerTests {
// @formatter:on
}
}
@Test
public void requestWhenRequiresChannelConfiguredInLambdaThenRedirectsToHttps() throws Exception {
this.spring.register(RequiresChannelInLambdaConfig.class).autowire();
mvc.perform(get("/"))
.andExpect(redirectedUrl("https://localhost/"));
}
@EnableWebSecurity
static class RequiresChannelInLambdaConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.requiresChannel(requiresChannel ->
requiresChannel
.anyRequest().requiresSecure()
);
// @formatter:on
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,9 +79,10 @@ public class PortMapperConfigurerTests {
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.requiresChannel()
.requiresChannel(requiresChannel ->
requiresChannel
.anyRequest().requiresSecure()
.and()
)
.portMapper(portMapper ->
portMapper
.http(543).mapsTo(123)
@@ -106,9 +107,10 @@ public class PortMapperConfigurerTests {
customPortMapper.setPortMappings(Collections.singletonMap("543", "123"));
// @formatter:off
http
.requiresChannel()
.anyRequest().requiresSecure()
.and()
.requiresChannel(requiresChannel ->
requiresChannel
.anyRequest().requiresSecure()
)
.portMapper(portMapper ->
portMapper
.portMapper(customPortMapper)