-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement configurable CORS (#61)
* feat: implement configurable CORS * fix: js trustchain verification * fix: allow all CORS origins by default
- Loading branch information
Showing
13 changed files
with
141 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...on-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/config/SecurityConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.sphereon.oid.fed.server.federation.config | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity | ||
import org.springframework.security.config.annotation.web.invoke | ||
import org.springframework.security.web.SecurityFilterChain | ||
import org.springframework.web.cors.CorsConfiguration | ||
import org.springframework.web.cors.CorsConfigurationSource | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
class SecurityConfig { | ||
@Value("\${app.dev-mode:false}") | ||
private var devMode: Boolean = false | ||
|
||
@Value("\${app.cors.allowed-origins}") | ||
private lateinit var allowedOrigins: String | ||
|
||
@Value("\${app.cors.allowed-methods}") | ||
private lateinit var allowedMethods: String | ||
|
||
@Value("\${app.cors.allowed-headers}") | ||
private lateinit var allowedHeaders: String | ||
|
||
@Value("\${app.cors.max-age:3600}") | ||
private var maxAge: Long = 3600 | ||
|
||
@Bean | ||
fun filterChain(http: HttpSecurity): SecurityFilterChain { | ||
http { | ||
authorizeRequests { | ||
authorize("/**", permitAll) | ||
} | ||
csrf { disable() } | ||
cors { } | ||
} | ||
return http.build() | ||
} | ||
|
||
@Bean | ||
fun corsConfigurationSource(): CorsConfigurationSource { | ||
val configuration = CorsConfiguration() | ||
configuration.allowedOrigins = allowedOrigins.split(",") | ||
configuration.allowedMethods = allowedMethods.split(",") | ||
configuration.allowedHeaders = allowedHeaders.split(",") | ||
configuration.maxAge = maxAge | ||
|
||
val source = UrlBasedCorsConfigurationSource() | ||
source.registerCorsConfiguration("/**", configuration) | ||
return source | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters