adding security for testing purpose
This commit is contained in:
parent
0a64e26a8f
commit
f757eba28b
|
@ -23,6 +23,10 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -43,6 +47,13 @@
|
||||||
<version>${spock.version}</version>
|
<version>${spock.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.rest-assured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -99,13 +110,23 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>autoconfiguration</id>
|
<id>integration</id>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -118,13 +139,8 @@
|
||||||
<goal>test</goal>
|
<goal>test</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
|
||||||
<exclude>**/*IntegrationTest.java</exclude>
|
|
||||||
<exclude>**/*IntTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/AutoconfigurationTest.java</include>
|
<include>**/*IntegrationTest.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -142,7 +158,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- The main class to start by executing java -jar -->
|
<!-- The main class to start by executing java -jar -->
|
||||||
<start-class>org.baeldung.boot.Application</start-class>
|
<start-class>com.baeldung.boot.Application</start-class>
|
||||||
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
|
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
|
||||||
<spock.version>1.2-groovy-2.4</spock.version>
|
<spock.version>1.2-groovy-2.4</spock.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
//package com.baeldung.boot;
|
||||||
|
//
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
|
//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;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//@Configuration
|
||||||
|
//@EnableWebSecurity
|
||||||
|
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
// auth.inMemoryAuthentication()
|
||||||
|
// .withUser("john")
|
||||||
|
// .password("{noop}123")
|
||||||
|
// .roles("USER");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
// http.authorizeRequests()
|
||||||
|
// .antMatchers("/hello")
|
||||||
|
// .permitAll()
|
||||||
|
// .anyRequest()
|
||||||
|
// .authenticated()
|
||||||
|
// .and()
|
||||||
|
// .httpBasic();
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.baeldung.boot.controller.rest;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class HomeController {
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String salutation() {
|
||||||
|
return "Welcome !";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
# security
|
||||||
|
spring.security.user.name=john
|
||||||
|
spring.security.user.password=123
|
|
@ -10,7 +10,7 @@ import spock.lang.Title
|
||||||
@Title("Application Specification")
|
@Title("Application Specification")
|
||||||
@Narrative("Specification which beans are expected")
|
@Narrative("Specification which beans are expected")
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class LoadContextTest extends Specification {
|
class LoadContextIntegrationTest extends Specification {
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private WebController webController
|
private WebController webController
|
|
@ -12,9 +12,9 @@ import spock.lang.Title
|
||||||
|
|
||||||
@Title("WebController Specification")
|
@Title("WebController Specification")
|
||||||
@Narrative("The Specification of the behaviour of the WebController. It can greet a person, change the name and reset it to 'world'")
|
@Narrative("The Specification of the behaviour of the WebController. It can greet a person, change the name and reset it to 'world'")
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc(secure=false)
|
||||||
@WebMvcTest
|
@WebMvcTest()
|
||||||
class WebControllerTest extends Specification {
|
class WebControllerIntegrationTest extends Specification {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mvc
|
private MockMvc mvc
|
Binary file not shown.
Loading…
Reference in New Issue