diff --git a/mongodb/util/src/main/resources/application.properties b/mongodb/util/src/main/resources/application.properties new file mode 100644 index 00000000..b5c5e0b7 --- /dev/null +++ b/mongodb/util/src/main/resources/application.properties @@ -0,0 +1 @@ +logging.level.root=INFO diff --git a/mongodb/util/src/main/resources/logback.xml b/mongodb/util/src/main/resources/logback.xml new file mode 100644 index 00000000..eace9e62 --- /dev/null +++ b/mongodb/util/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d %5p %40.40c:%4L - %m%n + + + + + + + + diff --git a/pom.xml b/pom.xml index a5bf543b..595fe1af 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.0.0 + 3.0.2 @@ -156,8 +156,8 @@ https://repo1.maven.org/maven2/ - spring-libs-snapshot - https://repo.spring.io/libs-snapshot + spring-snapshot + https://repo.spring.io/snapshot/ @@ -168,8 +168,8 @@ https://repo1.maven.org/maven2/ - spring-libs-snapshot - https://repo.spring.io/libs-snapshot + spring-snapshot + https://repo.spring.io/snapshot/ diff --git a/rest/headers/pom.xml b/rest/headers/pom.xml index 5e7a90e9..3294c81b 100644 --- a/rest/headers/pom.xml +++ b/rest/headers/pom.xml @@ -31,11 +31,10 @@ org.springframework.restdocs - spring-restdocs - 1.0.0.M1 + spring-restdocs-mockmvc test - \ No newline at end of file + diff --git a/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java b/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java index b2c88fbe..c10eadac 100644 --- a/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java +++ b/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java @@ -17,16 +17,20 @@ package example.springdata.rest.headers; import static org.hamcrest.CoreMatchers.*; import static org.springframework.http.HttpHeaders.*; -import static org.springframework.restdocs.RestDocumentation.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.restdocs.config.RestDocumentationConfigurer; +import org.springframework.restdocs.JUnitRestDocumentation; +import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -37,47 +41,52 @@ import org.springframework.web.util.UriTemplate; * @soundtrack The Intersphere - Out of phase (Live at Alte Feuerwache Mannheim) */ @SpringBootTest +@ExtendWith(RestDocumentationExtension.class) public class WebIntegrationTests { - @Autowired WebApplicationContext context; - @Autowired CustomerRepository customers; + public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); - private MockMvc mvc; + @Autowired + WebApplicationContext context; + @Autowired + CustomerRepository customers; - @BeforeEach - public void setUp() { + private MockMvc mvc; - this.mvc = MockMvcBuilders.webAppContextSetup(context).// - apply(new RestDocumentationConfigurer()).// - build(); - } + @BeforeEach + public void setUp(RestDocumentationContextProvider restDocumentation) { - @Test - public void executeConditionalGetRequests() throws Exception { + this.mvc = MockMvcBuilders.webAppContextSetup(context).// + apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation)).// + build(); + } - var customer = customers.findAll().iterator().next(); - var uri = new UriTemplate("/customers/{id}").expand(customer.getId()); + @Test + public void executeConditionalGetRequests() throws Exception { - var response = mvc.perform(get(uri)).// - andExpect(header().string(ETAG, is(notNullValue()))).// - andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// - andReturn().getResponse(); + var customer = customers.findAll().iterator().next(); + var uri = new UriTemplate("/customers/{id}").expand(customer.getId()); - // ETag-based + var response = mvc.perform(get(uri)).// + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// + andReturn().getResponse(); - response = mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// - andExpect(status().isNotModified()).// - andExpect(header().string(ETAG, is(notNullValue()))).// - andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// - andDo(document("if-none-match")).// - andReturn().getResponse(); + // ETag-based - // Last-modified-based + response = mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).// + andExpect(status().isNotModified()).// + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// + andDo(document("if-none-match")).// + andReturn().getResponse(); - mvc.perform(get(uri).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).// - andExpect(status().isNotModified()).// - andExpect(header().string(ETAG, is(notNullValue()))).// - andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// - andDo(document("if-modified-since")); - } + // Last-modified-based + + mvc.perform(get(uri).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).// + andExpect(status().isNotModified()).// + andExpect(header().string(ETAG, is(notNullValue()))).// + andExpect(header().string(LAST_MODIFIED, is(notNullValue()))).// + andDo(document("if-modified-since")); + } } 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 8c74159d..ea8cd4cc 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 @@ -26,11 +26,11 @@ import org.springframework.http.HttpMethod; 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.crypto.factory.PasswordEncoderFactories; import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; /** * This example shows various ways to secure Spring Data REST applications using Spring Security @@ -79,7 +79,7 @@ public class Application { @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) @EnableWebSecurity - static class SecurityConfiguration extends WebSecurityConfigurerAdapter { + static class SecurityConfiguration { /** * This section defines the user accounts which can be used for authentication as well as the roles each user has. @@ -107,16 +107,15 @@ public class Application { * * @param http * @throws Exception - * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) */ - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + protected SecurityFilterChain configure(HttpSecurity http) throws Exception { - http.httpBasic().and().authorizeRequests().// - antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// - antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// - antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// - csrf().disable(); + return http.httpBasic().and().authorizeRequests().// + requestMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// + requestMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// + requestMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// + csrf().disable().build(); } } } 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 fb305552..befdc4d0 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 @@ -68,8 +68,8 @@ class UrlLevelSecurityTests { mvc.perform(get("/").// accept(MediaTypes.HAL_JSON)).// - andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)).// - andExpect(status().isOk()); + andExpect(status().isOk()).// + andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)); } @Test