Skip to content

Commit d5bd953

Browse files
committed
Add Spring Security.
Add test to increase coverage.
1 parent 269dff8 commit d5bd953

File tree

8 files changed

+126
-4
lines changed

8 files changed

+126
-4
lines changed

buildSrc/src/main/kotlin/sb-ot-demo.java-conventions.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,28 @@ tasks {
119119
limit {
120120
counter = "METHOD"
121121
value = "MISSEDCOUNT"
122-
maximum = "3.0".toBigDecimal()
122+
maximum = "2.0".toBigDecimal()
123123
}
124124
}
125125
rule {
126126
limit {
127127
counter = "LINE"
128128
value = "MISSEDCOUNT"
129-
maximum = "10.0".toBigDecimal()
129+
maximum = "7.0".toBigDecimal()
130130
}
131131
}
132132
rule {
133133
limit {
134134
counter = "INSTRUCTION"
135135
value = "COVEREDRATIO"
136-
minimum = "0.90".toBigDecimal()
136+
minimum = "0.93".toBigDecimal()
137137
}
138138
}
139139
rule {
140140
limit {
141141
counter = "BRANCH"
142142
value = "COVEREDRATIO"
143-
minimum = "0.65".toBigDecimal()
143+
minimum = "0.66".toBigDecimal()
144144
}
145145
}
146146
}

spring-boot-2-demo-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
implementation("org.springframework.boot:spring-boot-starter-web")
1919
implementation("org.springframework.boot:spring-boot-starter-webflux")
2020
implementation("org.springframework.boot:spring-boot-starter-actuator")
21+
implementation("org.springframework.boot:spring-boot-starter-security")
2122
implementation("io.micrometer:micrometer-registry-prometheus")
2223
implementation("org.springdoc:springdoc-openapi-ui")
2324

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
package io.github.mfvanek.spring.boot2.test.config;
9+
10+
import lombok.SneakyThrows;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
14+
import org.springframework.security.web.SecurityFilterChain;
15+
16+
@Configuration(proxyBeanMethods = false)
17+
public class SecurityConfig {
18+
19+
@Bean
20+
@SneakyThrows
21+
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
22+
http.authorizeHttpRequests(authorize ->
23+
authorize.anyRequest().permitAll());
24+
return http.build();
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
package io.github.mfvanek.spring.boot2.test.controllers;
9+
10+
import io.github.mfvanek.spring.boot2.test.support.TestBase;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static io.github.mfvanek.spring.boot2.test.filters.TraceIdInResponseServletFilter.TRACE_ID_HEADER_NAME;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
class RedirectControllerTest extends TestBase {
17+
18+
@Test
19+
void redirectShouldWork() {
20+
final Object result = webTestClient.get()
21+
.uri("/redirect")
22+
.exchange()
23+
.expectStatus().isEqualTo(303)
24+
.expectHeader().exists(TRACE_ID_HEADER_NAME)
25+
.expectHeader().location("https://www.google.com")
26+
.expectBody(Object.class)
27+
.returnResult()
28+
.getResponseBody();
29+
assertThat(result)
30+
.isNull();
31+
}
32+
}

spring-boot-3-demo-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
implementation("org.springframework.boot:spring-boot-starter-web")
1616
implementation("org.springframework.boot:spring-boot-starter-webflux")
1717
implementation("org.springframework.boot:spring-boot-starter-actuator")
18+
implementation("org.springframework.boot:spring-boot-starter-security")
1819
implementation("io.micrometer:micrometer-registry-prometheus")
1920
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui")
2021

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
package io.github.mfvanek.spring.boot3.test.config;
9+
10+
import lombok.SneakyThrows;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
14+
import org.springframework.security.web.SecurityFilterChain;
15+
16+
@Configuration(proxyBeanMethods = false)
17+
public class SecurityConfig {
18+
19+
@Bean
20+
@SneakyThrows
21+
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
22+
http.authorizeHttpRequests(authorize ->
23+
authorize.anyRequest().permitAll());
24+
return http.build();
25+
}
26+
}

spring-boot-3-demo-app/src/main/resources/application.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ management:
112112
- w3c
113113
sampling:
114114
probability: 1.0
115+
observations:
116+
enable:
117+
spring:
118+
security: false
115119
otlp:
116120
tracing:
117121
endpoint: http://localhost:4317
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2020-2025. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/spring-boot-open-telemetry-demo
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
package io.github.mfvanek.spring.boot3.test.controllers;
9+
10+
import io.github.mfvanek.spring.boot3.test.support.TestBase;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static io.github.mfvanek.spring.boot3.test.filters.TraceIdInResponseServletFilter.TRACE_ID_HEADER_NAME;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
class RedirectControllerTest extends TestBase {
17+
18+
@Test
19+
void redirectShouldWork() {
20+
final Object result = webTestClient.get()
21+
.uri("/redirect")
22+
.exchange()
23+
.expectStatus().isEqualTo(303)
24+
.expectHeader().exists(TRACE_ID_HEADER_NAME)
25+
.expectHeader().location("https://www.google.com")
26+
.expectBody(Object.class)
27+
.returnResult()
28+
.getResponseBody();
29+
assertThat(result)
30+
.isNull();
31+
}
32+
}

0 commit comments

Comments
 (0)