From 5f109a1e92cd02df8b5588743ed141bc93542817 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 22 Oct 2019 12:08:19 +0200 Subject: Add helper functions for spring security. --- .../main/kotlin/pl/treksoft/kvision/remote/Security.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'kvision-modules') diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt index e87b95ff..328e384d 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt @@ -30,6 +30,20 @@ import org.springframework.security.web.server.util.matcher.ServerWebExchangeMat * A function to gather paths for spring security matchers. */ fun ServerHttpSecurity.AuthorizeExchangeSpec.serviceMatchers(vararg services: KVServiceManager<*>): ServerHttpSecurity.AuthorizeExchangeSpec.Access { + return this.matchers(*getServerWebExchangeMatcher(*services)) +} + +/** + * A function to gather paths for spring security matchers. + */ +fun serviceMatchers(vararg services: KVServiceManager<*>): ServerWebExchangeMatcher { + return ServerWebExchangeMatchers.matchers(*getServerWebExchangeMatcher(*services)) +} + +/** + * A function to gather paths for spring security matchers. + */ +fun getServerWebExchangeMatcher(vararg services: KVServiceManager<*>): Array { val matchers = mutableListOf() val getPaths = services.flatMap { it.getRequests.keys }.toTypedArray() if (getPaths.isNotEmpty()) matchers.add(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, *getPaths)) @@ -46,5 +60,5 @@ fun ServerHttpSecurity.AuthorizeExchangeSpec.serviceMatchers(vararg services: KV *optionsPaths ) ) - return this.matchers(*matchers.toTypedArray()) + return matchers.toTypedArray() } -- cgit