diff --git a/elasticsearch/example/pom.xml b/elasticsearch/example/pom.xml index 6037cfaf..d9c907b5 100644 --- a/elasticsearch/example/pom.xml +++ b/elasticsearch/example/pom.xml @@ -16,4 +16,24 @@ 2.0.0.BUILD-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-elasticsearch + + + org.springframework.boot + spring-boot-starter-logging + + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + diff --git a/pom.xml b/pom.xml index 5efce1fd..eeed5318 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.M5 + 2.0.0.M6 diff --git a/rest/security/src/main/java/example/springdata/rest/security/Application.java b/rest/security/src/main/java/example/springdata/rest/security/Application.java index 9fc898f2..be6ca1a7 100644 --- a/rest/security/src/main/java/example/springdata/rest/security/Application.java +++ b/rest/security/src/main/java/example/springdata/rest/security/Application.java @@ -20,14 +20,18 @@ import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; -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.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.User.UserBuilder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; /** * This example shows various ways to secure Spring Data REST applications using Spring Security @@ -80,15 +84,16 @@ public class Application { /** * This section defines the user accounts which can be used for authentication as well as the roles each user has. - * - * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) */ - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { + @Bean + InMemoryUserDetailsManager userDetailsManager() { - auth.inMemoryAuthentication().// - withUser("greg").password("turnquist").roles("USER").and().// - withUser("ollie").password("gierke").roles("USER", "ADMIN"); + UserBuilder builder = User.withDefaultPasswordEncoder(); + + UserDetails greg = builder.username("greg").password("turnquist").roles("USER").build(); + UserDetails ollie = builder.username("ollie").password("gierke").roles("USER", "ADMIN").build(); + + return new InMemoryUserDetailsManager(greg, ollie); } /** diff --git a/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java b/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java index 1ab362e5..f1633d95 100644 --- a/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java +++ b/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java @@ -21,6 +21,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; +import java.util.Base64; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,7 +32,6 @@ import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.crypto.codec.Base64; import org.springframework.security.web.FilterChainProxy; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -86,7 +87,8 @@ public class UrlLevelSecurityTests { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE); - headers.add(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("greg:turnquist").getBytes()))); + headers.add(HttpHeaders.AUTHORIZATION, + "Basic " + new String(Base64.getEncoder().encodeToString(("greg:turnquist").getBytes()))); mvc.perform(get("/employees").// headers(headers)).// @@ -103,7 +105,8 @@ public class UrlLevelSecurityTests { HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE); - headers.set(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("ollie:gierke").getBytes()))); + headers.set(HttpHeaders.AUTHORIZATION, + "Basic " + new String(Base64.getEncoder().encodeToString(("ollie:gierke").getBytes()))); mvc.perform(get("/employees").// headers(headers)).// @@ -112,11 +115,9 @@ public class UrlLevelSecurityTests { headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - String location = mvc - .perform(post("/employees").// - content(PAYLOAD).// - headers(headers)) - .// + String location = mvc.perform(post("/employees").// + content(PAYLOAD).// + headers(headers)).// andExpect(status().isCreated()).// andReturn().getResponse().getHeader(HttpHeaders.LOCATION);