From de03b20619c8c68d64b82a5b52a4b75fbbc9efe1 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Tue, 6 Feb 2018 13:41:13 +0100 Subject: [PATCH] Upgrade Spring Boot to 2.0.0.RC1 Closes gh-988 --- gradle.properties | 2 +- .../java/sample/config/SecurityConfig.java | 17 +++-------------- .../src/main/resources/application.properties | 1 + .../java/sample/config/SecurityConfig.java | 19 ++++--------------- .../src/main/resources/application.properties | 1 + .../java/sample/config/SecurityConfig.java | 17 +++-------------- .../src/main/resources/application.properties | 1 + .../java/sample/config/SecurityConfig.java | 17 +++-------------- .../src/main/resources/application.properties | 1 + .../java/sample/config/WebSecurityConfig.java | 18 ++++-------------- 10 files changed, 22 insertions(+), 72 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6e2513d8..e9db2ecb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -springBootVersion=2.0.0.M7 +springBootVersion=2.0.0.RC1 version=2.0.2.BUILD-SNAPSHOT diff --git a/samples/boot/findbyusername/src/main/java/sample/config/SecurityConfig.java b/samples/boot/findbyusername/src/main/java/sample/config/SecurityConfig.java index a5a7272b..47b134e0 100644 --- a/samples/boot/findbyusername/src/main/java/sample/config/SecurityConfig.java +++ b/samples/boot/findbyusername/src/main/java/sample/config/SecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -16,14 +16,10 @@ package sample.config; -import org.springframework.boot.autoconfigure.security.StaticResourceRequest; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; /** * Spring Security configuration. @@ -34,20 +30,13 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - @Override - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() - .username("user").password("password").roles("USER").build()); - } - // @formatter:off // tag::config[] @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and() .formLogin() diff --git a/samples/boot/findbyusername/src/main/resources/application.properties b/samples/boot/findbyusername/src/main/resources/application.properties index e69de29b..1b5271b5 100644 --- a/samples/boot/findbyusername/src/main/resources/application.properties +++ b/samples/boot/findbyusername/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.security.user.password=password diff --git a/samples/boot/jdbc/src/main/java/sample/config/SecurityConfig.java b/samples/boot/jdbc/src/main/java/sample/config/SecurityConfig.java index 9077e22b..49cd79ba 100644 --- a/samples/boot/jdbc/src/main/java/sample/config/SecurityConfig.java +++ b/samples/boot/jdbc/src/main/java/sample/config/SecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -16,15 +16,11 @@ package sample.config; -import org.springframework.boot.autoconfigure.security.StaticResourceRequest; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; /** * Spring Security configuration. @@ -35,16 +31,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - @Override - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() - .username("user").password("password").roles("USER").build()); - } - // @formatter:off @Override - public void configure(WebSecurity web) throws Exception { + public void configure(WebSecurity web) { web .ignoring().antMatchers("/h2-console/**"); } @@ -56,7 +45,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and() .formLogin() diff --git a/samples/boot/jdbc/src/main/resources/application.properties b/samples/boot/jdbc/src/main/resources/application.properties index 0db082b8..106d44fb 100644 --- a/samples/boot/jdbc/src/main/resources/application.properties +++ b/samples/boot/jdbc/src/main/resources/application.properties @@ -1 +1,2 @@ +spring.security.user.password=password spring.h2.console.enabled=true diff --git a/samples/boot/redis-json/src/main/java/sample/config/SecurityConfig.java b/samples/boot/redis-json/src/main/java/sample/config/SecurityConfig.java index 715a96e4..b5c7bdbe 100644 --- a/samples/boot/redis-json/src/main/java/sample/config/SecurityConfig.java +++ b/samples/boot/redis-json/src/main/java/sample/config/SecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -16,14 +16,10 @@ package sample.config; -import org.springframework.boot.autoconfigure.security.StaticResourceRequest; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; /** * Spring Security configuration. @@ -34,19 +30,12 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - @Override - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() - .username("user").password("password").roles("USER").build()); - } - // @formatter:off @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and() .formLogin() diff --git a/samples/boot/redis-json/src/main/resources/application.properties b/samples/boot/redis-json/src/main/resources/application.properties index e69de29b..1b5271b5 100644 --- a/samples/boot/redis-json/src/main/resources/application.properties +++ b/samples/boot/redis-json/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.security.user.password=password diff --git a/samples/boot/redis/src/main/java/sample/config/SecurityConfig.java b/samples/boot/redis/src/main/java/sample/config/SecurityConfig.java index 3f979097..3c46559e 100644 --- a/samples/boot/redis/src/main/java/sample/config/SecurityConfig.java +++ b/samples/boot/redis/src/main/java/sample/config/SecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -16,14 +16,10 @@ package sample.config; -import org.springframework.boot.autoconfigure.security.StaticResourceRequest; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; /** * Spring Security configuration. @@ -34,20 +30,13 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - @Override - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() - .username("user").password("password").roles("USER").build()); - } - // @formatter:off // tag::config[] @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and() .formLogin() diff --git a/samples/boot/redis/src/main/resources/application.properties b/samples/boot/redis/src/main/resources/application.properties index e69de29b..1b5271b5 100644 --- a/samples/boot/redis/src/main/resources/application.properties +++ b/samples/boot/redis/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.security.user.password=password diff --git a/samples/boot/websocket/src/main/java/sample/config/WebSecurityConfig.java b/samples/boot/websocket/src/main/java/sample/config/WebSecurityConfig.java index 2b1d4ede..6704a572 100644 --- a/samples/boot/websocket/src/main/java/sample/config/WebSecurityConfig.java +++ b/samples/boot/websocket/src/main/java/sample/config/WebSecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -17,30 +17,20 @@ package sample.config; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.security.StaticResourceRequest; -import org.springframework.context.annotation.Bean; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Bean - @Override - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() - .username("user").password("password").roles("USER").build()); - } - // @formatter:off @Autowired public void configureGlobal(AuthenticationManagerBuilder auth, @@ -53,7 +43,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { // @formatter:off @Override - public void configure(WebSecurity web) throws Exception { + public void configure(WebSecurity web) { web .ignoring().antMatchers("/h2-console/**"); } @@ -64,7 +54,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and() .formLogin()