WebfluxX509Application.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2002-2019 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package sample;
  17. import org.springframework.boot.SpringApplication;
  18. import org.springframework.boot.autoconfigure.SpringBootApplication;
  19. import org.springframework.context.annotation.Bean;
  20. import org.springframework.security.config.web.server.ServerHttpSecurity;
  21. import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
  22. import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
  23. import org.springframework.security.core.userdetails.User;
  24. import org.springframework.security.web.server.SecurityWebFilterChain;
  25. import static org.springframework.security.config.Customizer.withDefaults;
  26. /**
  27. * @author Alexey Nesterov
  28. * @since 5.2
  29. */
  30. @SpringBootApplication
  31. public class WebfluxX509Application {
  32. @Bean
  33. public ReactiveUserDetailsService reactiveUserDetailsService() {
  34. return new MapReactiveUserDetailsService(
  35. User.withUsername("client").password("").authorities("ROLE_USER").build()
  36. );
  37. }
  38. @Bean
  39. public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
  40. // @formatter:off
  41. http
  42. .x509(withDefaults())
  43. .authorizeExchange((exchanges) ->
  44. exchanges
  45. .anyExchange().authenticated()
  46. );
  47. // @formatter:on
  48. return http.build();
  49. }
  50. public static void main(String[] args) {
  51. SpringApplication.run(WebfluxX509Application.class);
  52. }
  53. }