-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d791d94
commit 4feb588
Showing
10 changed files
with
86 additions
and
9 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
62 changes: 62 additions & 0 deletions
62
.../main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/proxy/KeycloakProxyController.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,62 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.api.proxy | ||
|
||
import jakarta.servlet.http.HttpServletRequest | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.cloud.gateway.mvc.ProxyExchange | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMethod | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
/** | ||
* Used for EE tests | ||
*/ | ||
@RestController | ||
@ConditionalOnProperty( | ||
value = ["monitorfish.keycloak.proxy.enabled"], | ||
havingValue = "true", | ||
matchIfMissing = false, | ||
) | ||
class KeycloakProxyController { | ||
@GetMapping("/realms/**") | ||
@Throws(Exception::class) | ||
fun get( | ||
proxy: ProxyExchange<ByteArray?>, | ||
request: HttpServletRequest, | ||
): ResponseEntity<*> { | ||
val params = request.parameterMap | ||
val targetUri = StringBuilder("http://0.0.0.0:8085/${request.requestURI}") | ||
|
||
if (params.isNotEmpty()) { | ||
targetUri.append("?") | ||
params.entries.joinToString("&") { (key, values) -> | ||
"${key}=${values.joinToString(",")}" | ||
}.let { targetUri.append(it) } | ||
} | ||
|
||
return proxy.uri(targetUri.toString()).get() | ||
} | ||
|
||
@GetMapping("/resources/**") | ||
@Throws(Exception::class) | ||
fun getResources( | ||
proxy: ProxyExchange<ByteArray?>, | ||
request: HttpServletRequest, | ||
): ResponseEntity<*> { | ||
val targetUri = "http://0.0.0.0:8085${request.requestURI}" | ||
|
||
return proxy.uri(targetUri).get() | ||
} | ||
|
||
@PostMapping("/realms/**") | ||
@Throws(Exception::class) | ||
fun post( | ||
proxy: ProxyExchange<ByteArray?>, | ||
request: HttpServletRequest, | ||
): ResponseEntity<*> { | ||
val targetUri = "http://0.0.0.0:8085${request.requestURI}" | ||
|
||
return proxy.uri(targetUri).post() | ||
} | ||
} |
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