Skip to content

Commit 6c1c74c

Browse files
committed
fix: Test
1 parent bef19f7 commit 6c1c74c

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.0.6</version>
8+
<version>3.1.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111

src/main/kotlin/osahner/config/WebConfig.kt

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
99
import org.springframework.security.config.http.SessionCreationPolicy
1010
import org.springframework.security.web.SecurityFilterChain
1111
import org.springframework.web.cors.CorsConfiguration
12-
import org.springframework.web.cors.CorsConfigurationSource
1312
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
1413
import osahner.security.*
1514
import osahner.service.AppAuthenticationManager
@@ -26,43 +25,45 @@ class WebConfig(
2625
@Bean
2726
@Throws(Exception::class)
2827
fun filterChain(http: HttpSecurity): SecurityFilterChain? {
29-
return http
30-
.cors().and()
31-
.csrf().disable()
32-
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // no sessions
33-
.and()
34-
.authorizeHttpRequests()
35-
.requestMatchers("/api/**").permitAll()
36-
.requestMatchers(HttpMethod.GET, "/actuator/health/**").permitAll()
37-
.requestMatchers(HttpMethod.GET, "/actuator/info/**").permitAll()
38-
.requestMatchers(HttpMethod.POST, "/login").permitAll()
39-
.anyRequest().authenticated()
40-
.and()
28+
return http.cors { config ->
29+
config.configurationSource(UrlBasedCorsConfigurationSource().also { cors ->
30+
CorsConfiguration().apply {
31+
allowedOrigins = listOf("*")
32+
allowedMethods = listOf("POST", "PUT", "DELETE", "GET", "OPTIONS", "HEAD")
33+
allowedHeaders = listOf(
34+
"Authorization",
35+
"Content-Type",
36+
"X-Requested-With",
37+
"Accept",
38+
"Origin",
39+
"Access-Control-Request-Method",
40+
"Access-Control-Request-Headers"
41+
)
42+
exposedHeaders = listOf(
43+
"Access-Control-Allow-Origin",
44+
"Access-Control-Allow-Credentials",
45+
"Authorization",
46+
"Content-Disposition"
47+
)
48+
maxAge = 3600
49+
cors.registerCorsConfiguration("/**", this)
50+
}
51+
})
52+
}
53+
.csrf { csrf -> csrf.disable() }
54+
.sessionManagement { sessionManagement ->
55+
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
56+
}
57+
.authorizeHttpRequests { authorizeRequests ->
58+
authorizeRequests
59+
.requestMatchers("/api/**").permitAll()
60+
.requestMatchers(HttpMethod.GET, "/actuator/health/**").permitAll()
61+
.requestMatchers(HttpMethod.GET, "/actuator/info/**").permitAll()
62+
.requestMatchers(HttpMethod.POST, "/login").permitAll()
63+
.anyRequest().authenticated()
64+
}
4165
.addFilter(JWTAuthenticationFilter(authenticationManager, securityProperties, tokenProvider))
4266
.addFilter(JWTAuthorizationFilter(authenticationManager, securityProperties, tokenProvider))
4367
.build()
4468
}
45-
46-
@Bean
47-
fun corsConfigurationSource(): CorsConfigurationSource = UrlBasedCorsConfigurationSource().also { cors ->
48-
CorsConfiguration().apply {
49-
allowedOrigins = listOf("*")
50-
allowedMethods = listOf("POST", "PUT", "DELETE", "GET", "OPTIONS", "HEAD")
51-
allowedHeaders = listOf(
52-
"Authorization",
53-
"Content-Type",
54-
"X-Requested-With",
55-
"Accept",
56-
"Origin",
57-
"Access-Control-Request-Method",
58-
"Access-Control-Request-Headers"
59-
)
60-
exposedHeaders = listOf(
61-
"Access-Control-Allow-Origin", "Access-Control-Allow-Credentials", "Authorization", "Content-Disposition"
62-
)
63-
maxAge = 3600
64-
cors.registerCorsConfiguration("/**", this)
65-
}
66-
}
67-
6869
}

src/main/resources/application.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ jwt-security:
3232
expiration-time: 365
3333
management:
3434
endpoints:
35+
#enabled-by-default: false
3536
web:
36-
exposure:
37-
include: "health,info"
37+
exposure:
38+
include: "health,info,env"
3839
---
3940
spring:
4041
jpa:
4142
hibernate:
42-
ddl-auto: create-drop
43+
ddl-auto: update
4344
properties:
4445
hibernate.show_sql: true
4546
config:

src/test/kotlin/osahner/AuthenticationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ internal class AuthenticationTest(
185185
@Test
186186
@Order(11)
187187
fun `ping restricted but delete user before`() {
188-
val login = restTemplate.postForEntity<String>("/login", loginForm)
188+
val login = restTemplate.postForEntity<String>("/login", loginForm2)
189189
val bearer = login.headers["authorization"]?.get(0).orEmpty()
190190
val headers = HttpHeaders()
191191
headers.contentType = MediaType.APPLICATION_JSON
192192
headers["Authorization"] = bearer
193193
val requestEntity = HttpEntity<String>(headers)
194194

195-
userRepository.deleteAll()
195+
userRepository.deleteById(2)
196196
userRepository.flush()
197197

198198
restTemplate.exchange("/api/v1/restricted", HttpMethod.GET, requestEntity, String::class.java).also {

0 commit comments

Comments
 (0)