Skip to content

Commit

Permalink
chore: update cors config
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Jan 8, 2025
1 parent 59917ab commit a684d45
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions deploy/demo/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ spec:
secretKeyRef:
name: commonurl-demo
key: CATALOG_STORE_HOST
- name: CORS_ORIGIN_PATTERNS
value: https://*.demo.fellesdatakatalog.digdir.no
2 changes: 2 additions & 0 deletions deploy/prod/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ spec:
secretKeyRef:
name: commonurl-prod
key: CATALOG_STORE_HOST
- name: CORS_ORIGIN_PATTERNS
value: https://*.fellesdatakatalog.digdir.no
2 changes: 2 additions & 0 deletions deploy/staging/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ spec:
secretKeyRef:
name: commonurl-staging
key: CATALOG_STORE_HOST
- name: CORS_ORIGIN_PATTERNS
value: https://*.staging.fellesdatakatalog.digdir.no,http://localhost:*
20 changes: 18 additions & 2 deletions src/main/kotlin/no/fdk/concept_catalog/security/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.fdk.concept_catalog.security

import jakarta.servlet.http.HttpServletRequest
import org.apache.jena.riot.Lang
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -12,15 +13,30 @@ import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator
import org.springframework.security.oauth2.jwt.*
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.util.matcher.RequestMatcher
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource

@Configuration
open class SecurityConfig {
open class SecurityConfig(
@Value("\${application.cors.originPatterns}")
val corsOriginPatterns: Array<String>
) {

@Bean
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
http {
csrf { disable() }
cors { }
cors {
configurationSource = CorsConfigurationSource {
val config = CorsConfiguration()
config.allowCredentials = false
config.allowedHeaders = listOf("*")
config.maxAge = 3600L
config.allowedOriginPatterns = corsOriginPatterns.toList()
config.allowedMethods = listOf("GET", "POST", "OPTIONS", "DELETE", "PATCH")
config
}
}
oauth2ResourceServer { jwt { } }
authorizeHttpRequests {
authorize(RDFMatcher(), permitAll)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ application:
collectionBaseUri: ${COLLECTION_BASE_URI:https://concept-catalog.fellesdatakatalog.digdir.no}
historyServiceUri: ${CATALOG_HISTORY_SERVICE_URI:http://localhost:9090}
adminServiceUri: ${CATALOG_ADMIN_SERVICE_URI:https://catalog-admin-service.fellesdatakatalog.digdir.no}
cors.originPatterns: "${CORS_ORIGIN_PATTERNS}"

---
spring:
Expand All @@ -45,6 +46,7 @@ spring:
username: elastic
password: elasticpwd
uris: http://localhost:9200
application.cors.originPatterns: "*"

---
spring:
Expand All @@ -55,3 +57,4 @@ spring:
password: elasticpwd
application:
historyServiceUri: http://localhost:6000
cors.originPatterns: "*"

0 comments on commit a684d45

Please sign in to comment.