@@ -5,13 +5,17 @@ import gogo.gogobetting.global.filter.LoggingFilter
55import gogo.gogobetting.global.handler.CustomAccessDeniedHandler
66import gogo.gogobetting.global.handler.CustomAuthenticationEntryPointHandler
77import gogo.gogobetting.global.internal.user.stub.Authority
8+ import gogo.gogobetting.global.security.SecurityProperties
89import org.springframework.context.annotation.Bean
910import org.springframework.context.annotation.Configuration
1011import org.springframework.http.HttpMethod
12+ import org.springframework.security.authorization.AuthorizationDecision
1113import org.springframework.security.config.annotation.web.builders.HttpSecurity
1214import org.springframework.security.config.http.SessionCreationPolicy
1315import org.springframework.security.web.SecurityFilterChain
16+ import org.springframework.security.web.access.intercept.RequestAuthorizationContext
1417import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
18+ import org.springframework.security.web.util.matcher.IpAddressMatcher
1519import org.springframework.web.cors.CorsConfiguration
1620import org.springframework.web.cors.CorsConfigurationSource
1721import org.springframework.web.cors.UrlBasedCorsConfigurationSource
@@ -21,7 +25,8 @@ class SecurityConfig(
2125 private val customAccessDeniedHandler : CustomAccessDeniedHandler ,
2226 private val customAuthenticationEntryPointHandler : CustomAuthenticationEntryPointHandler ,
2327 private val authenticationFilter : AuthenticationFilter ,
24- private val loggingFilter : LoggingFilter
28+ private val loggingFilter : LoggingFilter ,
29+ private val securityProperties : SecurityProperties
2530) {
2631
2732 @Bean
@@ -57,14 +62,19 @@ class SecurityConfig(
5762 httpRequests.requestMatchers(HttpMethod .POST , " /betting/batch/cancel/{match_id}" ).hasAnyRole(Authority .USER .name, Authority .STAFF .name)
5863
5964 // server to server
60- httpRequests.requestMatchers(HttpMethod .GET , " /betting/bundle" ).permitAll()
65+ httpRequests.requestMatchers(HttpMethod .GET , " /betting/bundle" ).access { _, context -> hasIpAddress(context) }
6166
6267 httpRequests.anyRequest().denyAll()
6368 }
6469
6570 return http.build()
6671 }
6772
73+ private fun hasIpAddress (context : RequestAuthorizationContext ): AuthorizationDecision {
74+ val ALLOWED_IP_ADDRESS_MATCHER = IpAddressMatcher (" ${securityProperties.serverToServerIp}${securityProperties.serverToServerSubnet} " )
75+ return AuthorizationDecision (ALLOWED_IP_ADDRESS_MATCHER .matches(context.request))
76+ }
77+
6878 @Bean
6979 fun corsConfigurationSource (): CorsConfigurationSource {
7080 val configuration = CorsConfiguration ()
0 commit comments