commit
58ddbdaf29
|
@ -1,7 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>spring-boot-springdoc</artifactId>
|
<artifactId>spring-boot-springdoc</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
@ -112,6 +110,8 @@
|
||||||
<include>application.properties</include>
|
<include>application.properties</include>
|
||||||
<include>data.sql</include>
|
<include>data.sql</include>
|
||||||
<include>schema.sql</include>
|
<include>schema.sql</include>
|
||||||
|
<include>app.key</include>
|
||||||
|
<include>app.pub</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -52,8 +52,9 @@ public class SecurityConfiguration {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
return http
|
return http
|
||||||
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
|
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
|
||||||
.antMatchers("/api/auth/**", "/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**", "/webjars/**",
|
|
||||||
"/swagger-ui/index.html")
|
.antMatchers("/api/auth/**", "/swagger-ui-custom.html" ,"/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**", "/webjars/**",
|
||||||
|
"/swagger-ui/index.html","/api-docs/**")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
.authenticated())
|
.authenticated())
|
||||||
|
|
|
@ -11,7 +11,6 @@ public class SecurityTokenApplication {
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SecurityTokenApplication.class, args);
|
SpringApplication.run(SecurityTokenApplication.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class OpenApiJwtIntegrationTest
|
||||||
{
|
{
|
||||||
assertNotNull(authenticationApi);
|
assertNotNull(authenticationApi);
|
||||||
|
|
||||||
String response = this.restTemplate.getForObject("http://localhost:" + port + "/swagger-ui.html", String.class);
|
String response = this.restTemplate.getForObject("http://localhost:" + port + "/swagger-ui/index.html", String.class);
|
||||||
|
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertTrue(response.contains("Swagger UI"));
|
assertTrue(response.contains("Swagger UI"));
|
||||||
|
@ -43,8 +43,7 @@ class OpenApiJwtIntegrationTest
|
||||||
{
|
{
|
||||||
assertNotNull(authenticationApi);
|
assertNotNull(authenticationApi);
|
||||||
|
|
||||||
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/v3/api-docs",
|
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/api-docs", String.class);
|
||||||
String.class);
|
|
||||||
|
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||||
|
@ -59,8 +58,8 @@ class OpenApiJwtIntegrationTest
|
||||||
{
|
{
|
||||||
assertNotNull(authenticationApi);
|
assertNotNull(authenticationApi);
|
||||||
|
|
||||||
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/v3/api-docs",
|
|
||||||
String.class);
|
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/api-docs", String.class);
|
||||||
|
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getBody());
|
assertNotNull(response.getBody());
|
||||||
|
@ -75,8 +74,7 @@ class OpenApiJwtIntegrationTest
|
||||||
{
|
{
|
||||||
assertNotNull(authenticationApi);
|
assertNotNull(authenticationApi);
|
||||||
|
|
||||||
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/v3/api-docs",
|
ResponseEntity<String> response = this.restTemplate.getForEntity("http://localhost:" + port + "/api-docs", String.class);
|
||||||
String.class);
|
|
||||||
|
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getBody());
|
assertNotNull(response.getBody());
|
||||||
|
|
|
@ -50,8 +50,8 @@ class MongoAuthApplicationIntegrationTest {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
mvc = MockMvcBuilders.webAppContextSetup(context)
|
mvc = MockMvcBuilders.webAppContextSetup(context)
|
||||||
.apply(springSecurity())
|
.apply(springSecurity())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUp() {
|
private void setUp() {
|
||||||
|
@ -85,34 +85,34 @@ class MongoAuthApplicationIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
void givenUserCredentials_whenInvokeUserAuthorizedEndPoint_thenReturn200() throws Exception {
|
void givenUserCredentials_whenInvokeUserAuthorizedEndPoint_thenReturn200() throws Exception {
|
||||||
mvc.perform(get("/user").with(httpBasic(USER_NAME, PASSWORD)))
|
mvc.perform(get("/user").with(httpBasic(USER_NAME, PASSWORD)))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenUserNotExists_whenInvokeEndPoint_thenReturn401() throws Exception {
|
void givenUserNotExists_whenInvokeEndPoint_thenReturn401() throws Exception {
|
||||||
mvc.perform(get("/user").with(httpBasic("not_existing_user", "password")))
|
mvc.perform(get("/user").with(httpBasic("not_existing_user", "password")))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception {
|
void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception {
|
||||||
mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password")))
|
mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password")))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenUserCredentials_whenInvokeAdminAuthorizedEndPoint_thenReturn403() throws Exception {
|
void givenUserCredentials_whenInvokeAdminAuthorizedEndPoint_thenReturn403() throws Exception {
|
||||||
mvc.perform(get("/admin").with(httpBasic(USER_NAME, PASSWORD)))
|
mvc.perform(get("/admin").with(httpBasic(USER_NAME, PASSWORD)))
|
||||||
.andExpect(status().isForbidden());
|
.andExpect(status().isForbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenAdminCredentials_whenInvokeAdminAuthorizedEndPoint_thenReturn200() throws Exception {
|
void givenAdminCredentials_whenInvokeAdminAuthorizedEndPoint_thenReturn200() throws Exception {
|
||||||
mvc.perform(get("/admin").with(httpBasic(ADMIN_NAME, PASSWORD)))
|
mvc.perform(get("/admin").with(httpBasic(ADMIN_NAME, PASSWORD)))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
mvc.perform(get("/user").with(httpBasic(ADMIN_NAME, PASSWORD)))
|
mvc.perform(get("/user").with(httpBasic(ADMIN_NAME, PASSWORD)))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue