1
mongodb/util/src/main/resources/application.properties
Normal file
1
mongodb/util/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
logging.level.root=INFO
|
||||
14
mongodb/util/src/main/resources/logback.xml
Normal file
14
mongodb/util/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
10
pom.xml
10
pom.xml
@@ -13,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
@@ -156,8 +156,8 @@
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-libs-snapshot</id>
|
||||
<url>https://repo.spring.io/libs-snapshot</url>
|
||||
<id>spring-snapshot</id>
|
||||
<url>https://repo.spring.io/snapshot/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -168,8 +168,8 @@
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-libs-snapshot</id>
|
||||
<url>https://repo.spring.io/libs-snapshot</url>
|
||||
<id>spring-snapshot</id>
|
||||
<url>https://repo.spring.io/snapshot/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
@@ -31,11 +31,10 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.restdocs</groupId>
|
||||
<artifactId>spring-restdocs</artifactId>
|
||||
<version>1.0.0.M1</version>
|
||||
<artifactId>spring-restdocs-mockmvc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user