mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-31 06:38:42 +00:00 
			
		
		
		
	Update WebFlux samples to use Spring Boot
Fixes: gh-5411
This commit is contained in:
		
							parent
							
								
									1ee3c765f6
								
							
						
					
					
						commit
						a9e6d7606e
					
				| @ -0,0 +1,12 @@ | |||||||
|  | apply plugin: 'io.spring.convention.spring-sample-boot' | ||||||
|  | 
 | ||||||
|  | dependencies { | ||||||
|  | 	compile project(':spring-security-core') | ||||||
|  | 	compile project(':spring-security-config') | ||||||
|  | 	compile project(':spring-security-web') | ||||||
|  | 	compile 'org.springframework.boot:spring-boot-starter-webflux' | ||||||
|  | 
 | ||||||
|  | 	testCompile project(':spring-security-test') | ||||||
|  | 	testCompile 'io.projectreactor:reactor-test' | ||||||
|  | 	testCompile 'org.springframework.boot:spring-boot-starter-test' | ||||||
|  | } | ||||||
| @ -15,75 +15,65 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import org.junit.Before; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| import org.springframework.beans.factory.annotation.Value; |  | ||||||
| import org.springframework.http.HttpStatus; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.TestPropertySource; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; |  | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; |  | ||||||
| 
 | 
 | ||||||
| import java.nio.charset.Charset; |  | ||||||
| import java.time.Duration; |  | ||||||
| import java.util.Base64; |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
| 
 | 
 | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | import org.junit.Test; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | import org.junit.runner.RunWith; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
|  | import org.springframework.http.HttpStatus; | ||||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
|  | import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxMethodApplication.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||||||
| @TestPropertySource(properties = "server.port=0") |  | ||||||
| public class HelloWebfluxMethodApplicationITests { | public class HelloWebfluxMethodApplicationITests { | ||||||
| 	@Value("#{@nettyContext.address().getPort()}") |  | ||||||
| 	int port; |  | ||||||
| 
 | 
 | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setRest(WebTestClient rest) { | ||||||
| 		this.rest = WebTestClient.bindToServer() | 		this.rest = rest | ||||||
| 				.filter(basicAuthentication()) | 				.mutateWith((b, h, c) -> b.filter(ExchangeFilterFunctions.basicAuthentication())); | ||||||
| 				.responseTimeout(Duration.ofDays(1)) |  | ||||||
| 				.baseUrl("http://localhost:" + this.port) |  | ||||||
| 				.build(); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void messageWhenNotAuthenticated() throws Exception { | 	public void messageWhenNotAuthenticated() throws Exception { | ||||||
| 		this.rest | 		this.rest | ||||||
| 			.get() | 				.get() | ||||||
| 			.uri("/message") | 				.uri("/message") | ||||||
| 			.exchange() | 				.exchange() | ||||||
| 			.expectStatus().isUnauthorized(); | 				.expectStatus().isUnauthorized(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void messageWhenUserThenForbidden() throws Exception { | 	public void messageWhenUserThenForbidden() throws Exception { | ||||||
| 		this.rest | 		this.rest | ||||||
| 			.get() | 				.get() | ||||||
| 			.uri("/message") | 				.uri("/message") | ||||||
| 			.attributes(robsCredentials()) | 				.attributes(robsCredentials()) | ||||||
| 			.exchange() | 				.exchange() | ||||||
| 			.expectStatus().isEqualTo(HttpStatus.FORBIDDEN); | 				.expectStatus().isEqualTo(HttpStatus.FORBIDDEN); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void messageWhenAdminThenOk() throws Exception { | 	public void messageWhenAdminThenOk() throws Exception { | ||||||
| 		this.rest | 		this.rest | ||||||
| 			.get() | 				.get() | ||||||
| 			.uri("/message") | 				.uri("/message") | ||||||
| 			.attributes(adminCredentials()) | 				.attributes(adminCredentials()) | ||||||
| 			.exchange() | 				.exchange() | ||||||
| 			.expectStatus().isOk() | 				.expectStatus().isOk() | ||||||
| 			.expectBody(String.class).isEqualTo("Hello World!"); | 				.expectBody(String.class).isEqualTo("Hello World!"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private Consumer<Map<String, Object>> robsCredentials() { | 	private Consumer<Map<String, Object>> robsCredentials() { | ||||||
| @ -93,8 +83,5 @@ public class HelloWebfluxMethodApplicationITests { | |||||||
| 	private Consumer<Map<String, Object>> adminCredentials() { | 	private Consumer<Map<String, Object>> adminCredentials() { | ||||||
| 		return basicAuthenticationCredentials("admin", "admin"); | 		return basicAuthenticationCredentials("admin", "admin"); | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	private String base64Encode(String value) { |  | ||||||
| 		return Base64.getEncoder().encodeToString(value.getBytes(Charset.defaultCharset())); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  | 
 | ||||||
| @ -0,0 +1,32 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright 2002-2017 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. | ||||||
|  |  * You may obtain a copy of the License at | ||||||
|  |  * | ||||||
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  |  * | ||||||
|  |  * Unless required by applicable law or agreed to in writing, software | ||||||
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  |  * See the License for the specific language governing permissions and | ||||||
|  |  * limitations under the License. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | package sample; | ||||||
|  | 
 | ||||||
|  | import org.springframework.boot.SpringApplication; | ||||||
|  | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author Rob Winch | ||||||
|  |  * @since 5.0 | ||||||
|  |  */ | ||||||
|  | @SpringBootApplication | ||||||
|  | public class HelloWebfluxMethodApplication { | ||||||
|  | 
 | ||||||
|  | 	public static void main(String[] args) { | ||||||
|  | 		SpringApplication.run(HelloWebfluxMethodApplication.class, args); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -15,48 +15,41 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import java.util.Map; |  | ||||||
| import java.util.function.Consumer; |  | ||||||
| 
 |  | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.http.HttpStatus; |  | ||||||
| import org.springframework.security.test.context.support.WithMockUser; |  | ||||||
| import org.springframework.test.context.ActiveProfiles; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; |  | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; |  | ||||||
| 
 |  | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.function.Consumer; | ||||||
|  | 
 | ||||||
|  | import org.junit.Test; | ||||||
|  | import org.junit.runner.RunWith; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
|  | import org.springframework.context.ApplicationContext; | ||||||
|  | import org.springframework.http.HttpStatus; | ||||||
|  | import org.springframework.security.test.context.support.WithMockUser; | ||||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxMethodApplication.class) | @SpringBootTest | ||||||
| @ActiveProfiles("test") |  | ||||||
| public class HelloWebfluxMethodApplicationTests { | public class HelloWebfluxMethodApplicationTests { | ||||||
| 	@Autowired |  | ||||||
| 	ApplicationContext context; |  | ||||||
| 
 |  | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setup(ApplicationContext context) { | ||||||
| 		this.rest = WebTestClient | 		this.rest = WebTestClient | ||||||
| 			.bindToApplicationContext(this.context) | 				.bindToApplicationContext(context) | ||||||
| 			.apply(springSecurity()) | 				.apply(springSecurity()) | ||||||
| 			.configureClient() | 				.configureClient() | ||||||
| 			.filter(basicAuthentication()) | 				.filter(basicAuthentication()) | ||||||
| 			.build(); | 				.build(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -19,10 +19,9 @@ package sample; | |||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
| import org.springframework.security.access.AccessDeniedException; | import org.springframework.security.access.AccessDeniedException; | ||||||
| import org.springframework.security.test.context.support.WithMockUser; | import org.springframework.security.test.context.support.WithMockUser; | ||||||
| import org.springframework.test.context.ActiveProfiles; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; | import org.springframework.test.context.junit4.SpringRunner; | ||||||
| import reactor.test.StepVerifier; | import reactor.test.StepVerifier; | ||||||
| 
 | 
 | ||||||
| @ -31,8 +30,7 @@ import reactor.test.StepVerifier; | |||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxMethodApplication.class) | @SpringBootTest | ||||||
| @ActiveProfiles("test") |  | ||||||
| public class HelloWorldMessageServiceTests { | public class HelloWorldMessageServiceTests { | ||||||
| 	@Autowired | 	@Autowired | ||||||
| 	HelloWorldMessageService messages; | 	HelloWorldMessageService messages; | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | apply plugin: 'io.spring.convention.spring-sample-boot' | ||||||
|  | 
 | ||||||
|  | dependencies { | ||||||
|  | 	compile project(':spring-security-core') | ||||||
|  | 	compile project(':spring-security-config') | ||||||
|  | 	compile project(':spring-security-web') | ||||||
|  | 	compile 'org.springframework.boot:spring-boot-starter-webflux' | ||||||
|  | 
 | ||||||
|  | 	testCompile project(':spring-security-test') | ||||||
|  | 	testCompile 'org.springframework.boot:spring-boot-starter-test' | ||||||
|  | } | ||||||
| @ -15,46 +15,35 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import java.time.Duration; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
|  | 
 | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
| 
 | 
 | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||||
| 
 | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.boot.test.context.SpringBootTest; | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.TestPropertySource; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; | import org.springframework.test.context.junit4.SpringRunner; | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
| 
 | import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; |  | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxApplication.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||||||
| @TestPropertySource(properties = "server.port=0") |  | ||||||
| public class HelloWebfluxApplicationITests { | public class HelloWebfluxApplicationITests { | ||||||
| 	@Value("#{@nettyContext.address().getPort()}") |  | ||||||
| 	int port; |  | ||||||
| 
 | 
 | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setRest(WebTestClient rest) { | ||||||
| 		this.rest = WebTestClient.bindToServer() | 		this.rest = rest | ||||||
| 				.responseTimeout(Duration.ofDays(1)) | 				.mutateWith((b, h, c) -> b.filter(ExchangeFilterFunctions.basicAuthentication())); | ||||||
| 				.baseUrl("http://localhost:" + this.port) |  | ||||||
| 				.filter(basicAuthentication()) |  | ||||||
| 				.build(); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	@Test | 	@Test | ||||||
| 	public void basicWhenNoCredentialsThenUnauthorized() throws Exception { | 	public void basicWhenNoCredentialsThenUnauthorized() throws Exception { | ||||||
| 		this.rest | 		this.rest | ||||||
| @ -0,0 +1,33 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright 2002-2017 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. | ||||||
|  |  * You may obtain a copy of the License at | ||||||
|  |  * | ||||||
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  |  * | ||||||
|  |  * Unless required by applicable law or agreed to in writing, software | ||||||
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  |  * See the License for the specific language governing permissions and | ||||||
|  |  * limitations under the License. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | package sample; | ||||||
|  | 
 | ||||||
|  | import org.springframework.boot.SpringApplication; | ||||||
|  | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author Rob Winch | ||||||
|  |  * @since 5.0 | ||||||
|  |  */ | ||||||
|  | @SpringBootApplication | ||||||
|  | public class HelloWebfluxApplication { | ||||||
|  | 
 | ||||||
|  | 	public static void main(String[] args) { | ||||||
|  | 		SpringApplication.run(HelloWebfluxApplication.class, args); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -15,47 +15,42 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import java.util.Map; |  | ||||||
| import java.util.function.Consumer; |  | ||||||
| 
 |  | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.security.test.context.support.WithMockUser; |  | ||||||
| import org.springframework.test.context.ActiveProfiles; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; |  | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; |  | ||||||
| 
 |  | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.function.Consumer; | ||||||
|  | 
 | ||||||
|  | import org.junit.Test; | ||||||
|  | import org.junit.runner.RunWith; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
|  | import org.springframework.context.ApplicationContext; | ||||||
|  | import org.springframework.security.test.context.support.WithMockUser; | ||||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxApplication.class) | @SpringBootTest | ||||||
| @ActiveProfiles("test") | @AutoConfigureWebTestClient | ||||||
| public class HelloWebfluxApplicationTests { | public class HelloWebfluxApplicationTests { | ||||||
| 	@Autowired |  | ||||||
| 	ApplicationContext context; |  | ||||||
| 
 |  | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setup(ApplicationContext context) { | ||||||
| 		this.rest = WebTestClient | 		this.rest = WebTestClient | ||||||
| 			.bindToApplicationContext(this.context) | 				.bindToApplicationContext(context) | ||||||
| 			.apply(springSecurity()) | 				.apply(springSecurity()) | ||||||
| 			.configureClient() | 				.configureClient() | ||||||
| 			.filter(basicAuthentication()) | 				.filter(basicAuthentication()) | ||||||
| 			.build(); | 				.build(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | apply plugin: 'io.spring.convention.spring-sample-boot' | ||||||
|  | 
 | ||||||
|  | dependencies { | ||||||
|  | 	compile project(':spring-security-core') | ||||||
|  | 	compile project(':spring-security-config') | ||||||
|  | 	compile project(':spring-security-web') | ||||||
|  | 	compile 'org.springframework.boot:spring-boot-starter-webflux' | ||||||
|  | 
 | ||||||
|  | 	testCompile project(':spring-security-test') | ||||||
|  | 	testCompile 'org.springframework.boot:spring-boot-starter-test' | ||||||
|  | } | ||||||
| @ -15,43 +15,33 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import java.time.Duration; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
|  | 
 | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
| 
 | 
 | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||||
| 
 | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.boot.test.context.SpringBootTest; | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.TestPropertySource; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; | import org.springframework.test.context.junit4.SpringRunner; | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
| 
 | import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; |  | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxFnApplication.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||||||
| @TestPropertySource(properties = "server.port=0") |  | ||||||
| public class HelloWebfluxFnApplicationITests { | public class HelloWebfluxFnApplicationITests { | ||||||
| 	@Value("#{@nettyContext.address().getPort()}") |  | ||||||
| 	int port; |  | ||||||
| 
 | 
 | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setRest(WebTestClient rest) { | ||||||
| 		this.rest = WebTestClient.bindToServer() | 		this.rest = rest | ||||||
| 				.responseTimeout(Duration.ofDays(1)) | 				.mutateWith((b, h, c) -> b.filter(ExchangeFilterFunctions.basicAuthentication())); | ||||||
| 				.baseUrl("http://localhost:" + this.port) |  | ||||||
| 				.filter(basicAuthentication()) |  | ||||||
| 				.build(); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -0,0 +1,44 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright 2002-2017 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. | ||||||
|  |  * You may obtain a copy of the License at | ||||||
|  |  * | ||||||
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  |  * | ||||||
|  |  * Unless required by applicable law or agreed to in writing, software | ||||||
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  |  * See the License for the specific language governing permissions and | ||||||
|  |  * limitations under the License. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | package sample; | ||||||
|  | 
 | ||||||
|  | import static org.springframework.web.reactive.function.server.RequestPredicates.GET; | ||||||
|  | import static org.springframework.web.reactive.function.server.RouterFunctions.route; | ||||||
|  | 
 | ||||||
|  | import org.springframework.boot.SpringApplication; | ||||||
|  | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
|  | import org.springframework.context.annotation.Bean; | ||||||
|  | import org.springframework.web.reactive.function.server.RouterFunction; | ||||||
|  | import org.springframework.web.reactive.function.server.ServerResponse; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author Rob Winch | ||||||
|  |  * @since 5.0 | ||||||
|  |  */ | ||||||
|  | @SpringBootApplication | ||||||
|  | public class HelloWebfluxFnApplication { | ||||||
|  | 
 | ||||||
|  | 	public static void main(String[] args) { | ||||||
|  | 		SpringApplication.run(HelloWebfluxFnApplication.class, args); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	@Bean | ||||||
|  | 	public RouterFunction<ServerResponse> routes(HelloUserController userController) { | ||||||
|  | 		return route( | ||||||
|  | 			GET("/"), userController::hello); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -15,50 +15,43 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import java.util.Map; |  | ||||||
| import java.util.function.Consumer; |  | ||||||
| 
 |  | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| import org.junit.runner.RunWith; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||||
| import org.springframework.security.test.context.support.WithMockUser; |  | ||||||
| import org.springframework.security.web.server.WebFilterChainProxy; |  | ||||||
| import org.springframework.test.context.ActiveProfiles; |  | ||||||
| import org.springframework.test.context.ContextConfiguration; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; |  | ||||||
| import org.springframework.test.web.reactive.server.WebTestClient; |  | ||||||
| import org.springframework.web.reactive.function.server.RouterFunction; |  | ||||||
| 
 |  | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser; | ||||||
| import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; | ||||||
| import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.function.Consumer; | ||||||
|  | 
 | ||||||
|  | import org.junit.Test; | ||||||
|  | import org.junit.runner.RunWith; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||||
|  | import org.springframework.context.ApplicationContext; | ||||||
|  | import org.springframework.security.test.context.support.WithMockUser; | ||||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  | import org.springframework.test.web.reactive.server.WebTestClient; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * @author Rob Winch |  * @author Rob Winch | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = HelloWebfluxFnApplication.class) | @SpringBootTest | ||||||
| @ActiveProfiles("test") | @AutoConfigureWebTestClient | ||||||
| public class HelloWebfluxFnApplicationTests { | public class HelloWebfluxFnApplicationTests { | ||||||
| 	@Autowired |  | ||||||
| 	RouterFunction<?> routerFunction; |  | ||||||
| 	@Autowired WebFilterChainProxy springSecurityFilterChain; |  | ||||||
| 
 | 
 | ||||||
| 	WebTestClient rest; | 	WebTestClient rest; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Autowired | ||||||
| 	public void setup() { | 	public void setup(ApplicationContext context) { | ||||||
| 		this.rest = WebTestClient | 		this.rest = WebTestClient | ||||||
| 			.bindToRouterFunction(this.routerFunction) | 				.bindToApplicationContext(context) | ||||||
| 			.webFilter(this.springSecurityFilterChain) | 				.apply(springSecurity()) | ||||||
| 			.apply(springSecurity()) | 				.configureClient() | ||||||
| 			.configureClient() | 				.filter(basicAuthentication()) | ||||||
| 			.filter(basicAuthentication()) | 				.build(); | ||||||
| 			.build(); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| @ -14,24 +14,21 @@ | |||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| apply plugin: 'io.spring.convention.spring-sample' | apply plugin: 'io.spring.convention.spring-sample-boot' | ||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
| 	compile project(':spring-security-core') | 	compile project(':spring-security-core') | ||||||
| 	compile project(':spring-security-config') | 	compile project(':spring-security-config') | ||||||
| 	compile project(':spring-security-web') | 	compile project(':spring-security-web') | ||||||
| 	compile 'com.fasterxml.jackson.core:jackson-databind' | 	compile 'org.springframework.boot:spring-boot-starter-thymeleaf' | ||||||
| 	compile 'io.netty:netty-buffer' | 	compile 'org.springframework.boot:spring-boot-starter-webflux' | ||||||
| 	compile 'io.projectreactor.ipc:reactor-netty' |  | ||||||
| 	compile 'org.springframework:spring-context' |  | ||||||
| 	compile 'org.springframework:spring-webflux' |  | ||||||
| 	compile 'org.thymeleaf:thymeleaf-spring5' |  | ||||||
| 	compile slf4jDependencies |  | ||||||
| 
 | 
 | ||||||
| 	testCompile project(':spring-security-test') | 	testCompile project(':spring-security-test') | ||||||
|  | 	testCompile 'org.springframework.boot:spring-boot-starter-test' | ||||||
| 	testCompile 'io.projectreactor:reactor-test' | 	testCompile 'io.projectreactor:reactor-test' | ||||||
| 	testCompile 'org.skyscreamer:jsonassert' | 	testCompile 'org.skyscreamer:jsonassert' | ||||||
| 	testCompile 'org.springframework:spring-test' | 	testCompile 'org.springframework:spring-test' | ||||||
| 
 | 
 | ||||||
| 	integrationTestCompile seleniumDependencies | 	integrationTestCompile seleniumDependencies | ||||||
| } | } | ||||||
|  | 
 | ||||||
| @ -15,16 +15,17 @@ | |||||||
|  */ |  */ | ||||||
| package sample; | package sample; | ||||||
| 
 | 
 | ||||||
| import com.gargoylesoftware.htmlunit.BrowserVersion; |  | ||||||
| import org.junit.Before; | import org.junit.Before; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||||
| import org.openqa.selenium.WebDriver; | import org.openqa.selenium.WebDriver; | ||||||
| import org.openqa.selenium.htmlunit.HtmlUnitDriver; | import org.openqa.selenium.htmlunit.HtmlUnitDriver; | ||||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.boot.test.context.SpringBootTest; | ||||||
| import org.springframework.test.context.ContextConfiguration; | import org.springframework.boot.web.server.LocalServerPort; | ||||||
| import org.springframework.test.context.TestPropertySource; |  | ||||||
| import org.springframework.test.context.junit4.SpringRunner; | import org.springframework.test.context.junit4.SpringRunner; | ||||||
|  | 
 | ||||||
|  | import com.gargoylesoftware.htmlunit.BrowserVersion; | ||||||
|  | 
 | ||||||
| import sample.webdriver.IndexPage; | import sample.webdriver.IndexPage; | ||||||
| import sample.webdriver.LoginPage; | import sample.webdriver.LoginPage; | ||||||
| 
 | 
 | ||||||
| @ -33,12 +34,11 @@ import sample.webdriver.LoginPage; | |||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| @RunWith(SpringRunner.class) | @RunWith(SpringRunner.class) | ||||||
| @ContextConfiguration(classes = WebfluxFormApplication.class) | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||||||
| @TestPropertySource(properties = "server.port=0") |  | ||||||
| public class WebfluxFormApplicationTests { | public class WebfluxFormApplicationTests { | ||||||
| 	WebDriver driver; | 	WebDriver driver; | ||||||
| 
 | 
 | ||||||
| 	@Value("#{@nettyContext.address().getPort()}") | 	@LocalServerPort | ||||||
| 	int port; | 	int port; | ||||||
| 
 | 
 | ||||||
| 	@Before | 	@Before | ||||||
| @ -0,0 +1,32 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright 2002-2017 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. | ||||||
|  |  * You may obtain a copy of the License at | ||||||
|  |  * | ||||||
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  |  * | ||||||
|  |  * Unless required by applicable law or agreed to in writing, software | ||||||
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  |  * See the License for the specific language governing permissions and | ||||||
|  |  * limitations under the License. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | package sample; | ||||||
|  | 
 | ||||||
|  | import org.springframework.boot.SpringApplication; | ||||||
|  | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author Rob Winch | ||||||
|  |  * @since 5.0 | ||||||
|  |  */ | ||||||
|  | @SpringBootApplication | ||||||
|  | public class WebfluxFormApplication { | ||||||
|  | 
 | ||||||
|  | 	public static void main(String[] args) { | ||||||
|  | 		SpringApplication.run(WebfluxFormApplication.class, args); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -1,16 +0,0 @@ | |||||||
| apply plugin: 'io.spring.convention.spring-sample' |  | ||||||
| 
 |  | ||||||
| dependencies { |  | ||||||
| 	compile project(':spring-security-core') |  | ||||||
| 	compile project(':spring-security-config') |  | ||||||
| 	compile project(':spring-security-web') |  | ||||||
| 	compile 'com.fasterxml.jackson.core:jackson-databind' |  | ||||||
| 	compile 'io.projectreactor.ipc:reactor-netty' |  | ||||||
| 	compile 'org.springframework:spring-context' |  | ||||||
| 	compile 'org.springframework:spring-webflux' |  | ||||||
| 
 |  | ||||||
| 	testCompile project(':spring-security-test') |  | ||||||
| 	testCompile 'io.projectreactor:reactor-test' |  | ||||||
| 	testCompile 'org.skyscreamer:jsonassert' |  | ||||||
| 	testCompile 'org.springframework:spring-test' |  | ||||||
| } |  | ||||||
| @ -1,56 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2002-2017 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. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package sample; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Value; |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.context.annotation.*; |  | ||||||
| import org.springframework.http.server.reactive.HttpHandler; |  | ||||||
| import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; |  | ||||||
| import org.springframework.web.reactive.config.EnableWebFlux; |  | ||||||
| import org.springframework.web.server.adapter.WebHttpHandlerBuilder; |  | ||||||
| import reactor.ipc.netty.NettyContext; |  | ||||||
| import reactor.ipc.netty.http.server.HttpServer; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @author Rob Winch |  | ||||||
|  * @since 5.0 |  | ||||||
|  */ |  | ||||||
| @Configuration |  | ||||||
| @EnableWebFlux |  | ||||||
| @ComponentScan |  | ||||||
| public class HelloWebfluxMethodApplication { |  | ||||||
| 	@Value("${server.port:8080}") |  | ||||||
| 	private int port = 8080; |  | ||||||
| 
 |  | ||||||
| 	public static void main(String[] args) throws Exception { |  | ||||||
| 		try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |  | ||||||
| 			HelloWebfluxMethodApplication.class)) { |  | ||||||
| 			context.getBean(NettyContext.class).onClose().block(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Profile("default") |  | ||||||
| 	@Bean |  | ||||||
| 	public NettyContext nettyContext(ApplicationContext context) { |  | ||||||
| 		HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) |  | ||||||
| 			.build(); |  | ||||||
| 		ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); |  | ||||||
| 		HttpServer httpServer = HttpServer.create("localhost", port); |  | ||||||
| 		return httpServer.newHandler(adapter).block(); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,17 +0,0 @@ | |||||||
| apply plugin: 'io.spring.convention.spring-sample' |  | ||||||
| 
 |  | ||||||
| dependencies { |  | ||||||
| 	compile project(':spring-security-core') |  | ||||||
| 	compile project(':spring-security-config') |  | ||||||
| 	compile project(':spring-security-web') |  | ||||||
| 	compile 'com.fasterxml.jackson.core:jackson-databind' |  | ||||||
| 	compile 'io.projectreactor.ipc:reactor-netty' |  | ||||||
| 	compile 'org.springframework:spring-context' |  | ||||||
| 	compile 'org.springframework:spring-webflux' |  | ||||||
| 	compile slf4jDependencies |  | ||||||
| 
 |  | ||||||
| 	testCompile project(':spring-security-test') |  | ||||||
| 	testCompile 'io.projectreactor:reactor-test' |  | ||||||
| 	testCompile 'org.skyscreamer:jsonassert' |  | ||||||
| 	testCompile 'org.springframework:spring-test' |  | ||||||
| } |  | ||||||
| @ -1,55 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2002-2017 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. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package sample; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Value; |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.context.annotation.*; |  | ||||||
| import org.springframework.http.server.reactive.HttpHandler; |  | ||||||
| import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; |  | ||||||
| import org.springframework.web.reactive.config.EnableWebFlux; |  | ||||||
| import org.springframework.web.server.adapter.WebHttpHandlerBuilder; |  | ||||||
| import reactor.ipc.netty.NettyContext; |  | ||||||
| import reactor.ipc.netty.http.server.HttpServer; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @author Rob Winch |  | ||||||
|  * @since 5.0 |  | ||||||
|  */ |  | ||||||
| @Configuration |  | ||||||
| @EnableWebFlux |  | ||||||
| @ComponentScan |  | ||||||
| public class HelloWebfluxApplication { |  | ||||||
| 	@Value("${server.port:8080}") |  | ||||||
| 	private int port = 8080; |  | ||||||
| 
 |  | ||||||
| 	public static void main(String[] args) throws Exception { |  | ||||||
| 		try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HelloWebfluxApplication.class)) { |  | ||||||
| 			context.getBean(NettyContext.class).onClose().block(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Profile("default") |  | ||||||
| 	@Bean |  | ||||||
| 	public NettyContext nettyContext(ApplicationContext context) { |  | ||||||
| 		HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) |  | ||||||
| 			.build(); |  | ||||||
| 		ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); |  | ||||||
| 		HttpServer httpServer = HttpServer.create("localhost", port); |  | ||||||
| 		return httpServer.newHandler(adapter).block(); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,16 +0,0 @@ | |||||||
| apply plugin: 'io.spring.convention.spring-sample' |  | ||||||
| 
 |  | ||||||
| dependencies { |  | ||||||
| 	compile project(':spring-security-core') |  | ||||||
| 	compile project(':spring-security-config') |  | ||||||
| 	compile project(':spring-security-web') |  | ||||||
| 	compile 'com.fasterxml.jackson.core:jackson-databind' |  | ||||||
| 	compile 'io.projectreactor.ipc:reactor-netty' |  | ||||||
| 	compile 'org.springframework:spring-context' |  | ||||||
| 	compile 'org.springframework:spring-webflux' |  | ||||||
| 
 |  | ||||||
| 	testCompile project(':spring-security-test') |  | ||||||
| 	testCompile 'io.projectreactor:reactor-test' |  | ||||||
| 	testCompile 'org.skyscreamer:jsonassert' |  | ||||||
| 	testCompile 'org.springframework:spring-test' |  | ||||||
| } |  | ||||||
| @ -1,75 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2002-2017 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. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package sample; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Value; |  | ||||||
| import org.springframework.context.annotation.*; |  | ||||||
| import org.springframework.http.server.reactive.HttpHandler; |  | ||||||
| import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; |  | ||||||
| import org.springframework.web.reactive.config.EnableWebFlux; |  | ||||||
| import org.springframework.web.reactive.function.server.HandlerStrategies; |  | ||||||
| import org.springframework.web.reactive.function.server.RouterFunction; |  | ||||||
| import org.springframework.web.reactive.function.server.RouterFunctions; |  | ||||||
| import org.springframework.web.reactive.function.server.ServerResponse; |  | ||||||
| import org.springframework.web.server.WebFilter; |  | ||||||
| import reactor.ipc.netty.NettyContext; |  | ||||||
| import reactor.ipc.netty.http.server.HttpServer; |  | ||||||
| 
 |  | ||||||
| import static org.springframework.web.reactive.function.server.RequestPredicates.GET; |  | ||||||
| import static org.springframework.web.reactive.function.server.RouterFunctions.route; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @author Rob Winch |  | ||||||
|  * @since 5.0 |  | ||||||
|  */ |  | ||||||
| @Configuration |  | ||||||
| @EnableWebFlux |  | ||||||
| @ComponentScan |  | ||||||
| public class HelloWebfluxFnApplication { |  | ||||||
| 	@Value("${server.port:8080}") |  | ||||||
| 	private int port = 8080; |  | ||||||
| 
 |  | ||||||
| 	public static void main(String[] args) throws Exception { |  | ||||||
| 		try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HelloWebfluxFnApplication.class)) { |  | ||||||
| 			context.getBean(NettyContext.class).onClose().block(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Profile("default") |  | ||||||
| 	@Bean |  | ||||||
| 	public NettyContext nettyContext(HttpHandler handler) { |  | ||||||
| 		ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); |  | ||||||
| 		HttpServer httpServer = HttpServer.create("localhost", this.port); |  | ||||||
| 		return httpServer.newHandler(adapter).block(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Bean |  | ||||||
| 	public RouterFunction<ServerResponse> routes(HelloUserController userController) { |  | ||||||
| 		return route( |  | ||||||
| 			GET("/"), userController::hello); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Bean |  | ||||||
| 	public HttpHandler httpHandler(RouterFunction<ServerResponse> routes, WebFilter springSecurityFilterChain) { |  | ||||||
| 		HandlerStrategies handlerStrategies = HandlerStrategies.builder() |  | ||||||
| 			.webFilter(springSecurityFilterChain) |  | ||||||
| 			.build(); |  | ||||||
| 
 |  | ||||||
| 		return RouterFunctions.toHttpHandler(routes, handlerStrategies); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| @ -1,76 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2002-2017 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. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package sample; |  | ||||||
| 
 |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.context.annotation.Bean; |  | ||||||
| import org.springframework.context.annotation.Configuration; |  | ||||||
| import org.springframework.web.reactive.config.ViewResolverRegistry; |  | ||||||
| import org.springframework.web.reactive.config.WebFluxConfigurer; |  | ||||||
| import org.thymeleaf.spring5.ISpringWebFluxTemplateEngine; |  | ||||||
| import org.thymeleaf.spring5.SpringWebFluxTemplateEngine; |  | ||||||
| import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; |  | ||||||
| import org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver; |  | ||||||
| import org.thymeleaf.templatemode.TemplateMode; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @author Rob Winch |  | ||||||
|  * @since 5.0 |  | ||||||
|  */ |  | ||||||
| @Configuration |  | ||||||
| public class ThymeleafConfig implements WebFluxConfigurer { |  | ||||||
| 	private ApplicationContext applicationContext; |  | ||||||
| 
 |  | ||||||
| 	public ThymeleafConfig(final ApplicationContext applicationContext) { |  | ||||||
| 		this.applicationContext = applicationContext; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Bean |  | ||||||
| 	public SpringResourceTemplateResolver thymeleafTemplateResolver() { |  | ||||||
| 
 |  | ||||||
| 		SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); |  | ||||||
| 		resolver.setApplicationContext(this.applicationContext); |  | ||||||
| 		resolver.setPrefix("classpath:/templates/"); |  | ||||||
| 		resolver.setSuffix(".html"); |  | ||||||
| 		resolver.setTemplateMode(TemplateMode.HTML); |  | ||||||
| 		resolver.setCacheable(false); |  | ||||||
| 		resolver.setCheckExistence(true); |  | ||||||
| 		return resolver; |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Bean |  | ||||||
| 	public ISpringWebFluxTemplateEngine thymeleafTemplateEngine() { |  | ||||||
| 		SpringWebFluxTemplateEngine templateEngine = new SpringWebFluxTemplateEngine(); |  | ||||||
| 		templateEngine.setTemplateResolver(thymeleafTemplateResolver()); |  | ||||||
| 		return templateEngine; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Bean |  | ||||||
| 	public ThymeleafReactiveViewResolver thymeleafChunkedAndDataDrivenViewResolver() { |  | ||||||
| 		ThymeleafReactiveViewResolver viewResolver = new ThymeleafReactiveViewResolver(); |  | ||||||
| 		viewResolver.setTemplateEngine(thymeleafTemplateEngine()); |  | ||||||
| 		viewResolver.setOrder(1); |  | ||||||
| 		viewResolver.setResponseMaxChunkSizeBytes(8192); // OUTPUT BUFFER size limit |  | ||||||
| 		return viewResolver; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Override |  | ||||||
| 	public void configureViewResolvers(ViewResolverRegistry registry) { |  | ||||||
| 		registry.viewResolver(thymeleafChunkedAndDataDrivenViewResolver()); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,56 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright 2002-2017 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. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package sample; |  | ||||||
| 
 |  | ||||||
| import org.springframework.beans.factory.annotation.Value; |  | ||||||
| import org.springframework.context.ApplicationContext; |  | ||||||
| import org.springframework.context.annotation.*; |  | ||||||
| import org.springframework.http.server.reactive.HttpHandler; |  | ||||||
| import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; |  | ||||||
| import org.springframework.web.reactive.config.EnableWebFlux; |  | ||||||
| import org.springframework.web.server.adapter.WebHttpHandlerBuilder; |  | ||||||
| import reactor.ipc.netty.NettyContext; |  | ||||||
| import reactor.ipc.netty.http.server.HttpServer; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @author Rob Winch |  | ||||||
|  * @since 5.0 |  | ||||||
|  */ |  | ||||||
| @Configuration |  | ||||||
| @EnableWebFlux |  | ||||||
| @ComponentScan |  | ||||||
| public class WebfluxFormApplication { |  | ||||||
| 	@Value("${server.port:8080}") |  | ||||||
| 	private int port = 8080; |  | ||||||
| 
 |  | ||||||
| 	public static void main(String[] args) throws Exception { |  | ||||||
| 		try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |  | ||||||
| 			WebfluxFormApplication.class)) { |  | ||||||
| 			context.getBean(NettyContext.class).onClose().block(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	@Profile("default") |  | ||||||
| 	@Bean |  | ||||||
| 	public NettyContext nettyContext(ApplicationContext context) { |  | ||||||
| 		HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) |  | ||||||
| 			.build(); |  | ||||||
| 		ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); |  | ||||||
| 		HttpServer httpServer = HttpServer.create("localhost", port); |  | ||||||
| 		return httpServer.newHandler(adapter).block(); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user