From b62aa9036290d4c9b2de293984ddcca2fa7cd1b5 Mon Sep 17 00:00:00 2001 From: Dreamstar Enterprises <39380005+dreamstar-enterprises@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:01:28 +0100 Subject: [PATCH] Delete Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing directory --- .../frontiers/bff/routing/RoutingConfig.kt | 45 ---------- .../routing/circuitbreaker/CircuitBreaker.kt | 42 ---------- .../bff/routing/filters/GlobalFilters.kt | 84 ------------------- .../bff/routing/filters/IgnoreFilter.kt | 55 ------------ 4 files changed, 226 deletions(-) delete mode 100644 Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/RoutingConfig.kt delete mode 100644 Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/circuitbreaker/CircuitBreaker.kt delete mode 100644 Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/GlobalFilters.kt delete mode 100644 Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/IgnoreFilter.kt diff --git a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/RoutingConfig.kt b/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/RoutingConfig.kt deleted file mode 100644 index 947fafc..0000000 --- a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/RoutingConfig.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.frontiers.bff.routing - -import com.frontiers.bff.props.ServerProperties -import org.springframework.cloud.gateway.filter.factory.TokenRelayGatewayFilterFactory -import org.springframework.cloud.gateway.route.RouteLocator -import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -/**********************************************************************************************************************/ -/***************************************************** GATEWAY ROUTING ************************************************/ -/**********************************************************************************************************************/ - -@Configuration -internal class RoutingConfig( - private val serverProperties: ServerProperties, -) { - - @Bean - fun routeLocator( - builder: RouteLocatorBuilder, - tokenRelayGatewayFilterFactory: TokenRelayGatewayFilterFactory - ): RouteLocator { - return builder.routes() - - // routing for Resource Server - .route("resource-server") { r -> - r.path("/api${serverProperties.resourceServerPrefix}/**") - .filters { f -> - f.filter { exchange, chain -> - chain.filter(exchange) - } - f.filter(tokenRelayGatewayFilterFactory.apply()) - .removeRequestHeader("Cookie") - } - .uri(serverProperties.resourceServerUri) - } - .build() - } - -} - -/**********************************************************************************************************************/ -/**************************************************** END OF KOTLIN ***************************************************/ -/**********************************************************************************************************************/ \ No newline at end of file diff --git a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/circuitbreaker/CircuitBreaker.kt b/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/circuitbreaker/CircuitBreaker.kt deleted file mode 100644 index 13b635c..0000000 --- a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/circuitbreaker/CircuitBreaker.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.example.bff.gateway.circuitbreaker - -import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig -import io.github.resilience4j.timelimiter.TimeLimiterConfig -import org.springframework.cloud.circuitbreaker.resilience4j.ReactiveResilience4JCircuitBreakerFactory -import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder -import org.springframework.cloud.client.circuitbreaker.Customizer -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import java.time.Duration - -/**********************************************************************************************************************/ -/***************************************************** CIRCUIT BREAKER ************************************************/ -/**********************************************************************************************************************/ - -@Configuration -class Resilience4JConfig { - - @Bean - fun defaultCustomizer(): Customizer { - return Customizer { factory -> - factory.configureDefault { id -> - Resilience4JConfigBuilder(id) - .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) - .timeLimiterConfig( - TimeLimiterConfig.custom() - .timeoutDuration( - // 4.5 seconds - Duration.ofSeconds(4, 500_000_000L) - ) - .build() - ) - .build() - } - } - } - -} - -/**********************************************************************************************************************/ -/**************************************************** END OF KOTLIN ***************************************************/ -/**********************************************************************************************************************/ \ No newline at end of file diff --git a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/GlobalFilters.kt b/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/GlobalFilters.kt deleted file mode 100644 index 10a9b4b..0000000 --- a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/GlobalFilters.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.frontiers.bff.routing.filters - -import org.springframework.cloud.gateway.filter.GlobalFilter -import org.springframework.cloud.gateway.filter.factory.SaveSessionGatewayFilterFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.http.HttpHeaders -import reactor.core.publisher.Mono - -/**********************************************************************************************************************/ -/******************************************************* FILTER *******************************************************/ -/**********************************************************************************************************************/ - -@Configuration -internal class DedupeResponseFilterConfig { - - @Bean - fun dedupeResponseHeaderFilter(): GlobalFilter { - return GlobalFilter { exchange, chain -> - chain.filter(exchange).then( - Mono.fromRunnable { - val headers = exchange.response.headers - headers.dedupeResponseHeader( - "Access-Control-Allow-Credentials", - "RETAIN_UNIQUE" - ) - headers.dedupeResponseHeader( - "Access-Control-Allow-Origin", - "RETAIN_UNIQUE" - ) - } - ) - } - } -} - -private fun HttpHeaders.dedupeResponseHeader(headerName: String, strategy: String) { - val headerValues = this[headerName] ?: return - - val uniqueValues = when (strategy) { - "RETAIN_UNIQUE" -> headerValues.toSet().toList() - else -> headerValues - } - - this[headerName] = uniqueValues -} - -@Configuration -internal class SaveSessionFilterConfig( - private val saveSessionGatewayFilterFactory: SaveSessionGatewayFilterFactory -) { - - @Bean - fun saveSessionGlobalFilter(): GlobalFilter { - return GlobalFilter { exchange, chain -> - saveSessionGatewayFilterFactory.apply { - // optionally configure futher if needed - }.filter(exchange, chain) - } - } -} - -@Configuration -internal class CustomHeaderFilterConfig { - - @Bean - fun customHeaderFilter(): GlobalFilter { - return GlobalFilter { exchange, chain -> - chain.filter(exchange).then( - Mono.fromRunnable { - exchange.response.headers.add( - "X-Powered-By", - "DreamStar Enterprises" - ) - } - ) - } - } - -} - -/**********************************************************************************************************************/ -/**************************************************** END OF KOTLIN ***************************************************/ -/**********************************************************************************************************************/ \ No newline at end of file diff --git a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/IgnoreFilter.kt b/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/IgnoreFilter.kt deleted file mode 100644 index 74451ec..0000000 --- a/Spring BFF/BFF/src/main/kotlin/com/frontiers/bff/routing/filters/IgnoreFilter.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.frontiers.bff.routing.filters - -import org.slf4j.LoggerFactory -import org.springframework.context.annotation.Configuration - -/**********************************************************************************************************************/ -/*********************************************** DEFAULT SECURITY CONFIGURATION ***************************************/ -/**********************************************************************************************************************/ - -/** - * Configures endpoints considered that should be skipped - */ -@Configuration -internal class IgnoreFilter { - - private val logger = LoggerFactory.getLogger(IgnoreFilter::class.java) - - // define base paths and file extensions for security context loading - private val skipRequestPath: Map> = mapOf( - "/login-options" to listOf(), - ) - - // main function that checks if the request path should skip static resources - fun shouldSkipRequestPath(requestPath: String): Boolean { - val isSkipped = getRequestPathMatchers().any { it.matches(requestPath) } - if (isSkipped) { - logger.info("Request path '$requestPath' is skipped as a skippable path.") - } - return isSkipped - } - - // function that generates matchers for request path - private fun getRequestPathMatchers(): List { - return skipRequestPath.flatMap { (basePath, extensions) -> - if (extensions.isEmpty()) { - listOf(RequestPathMatcher(basePath)) - } else { - extensions.map { extension -> RequestPathMatcher(basePath, extension) } - } - } - } - - // data class to encapsulate the logic for matching request paths - private data class RequestPathMatcher(val basePath: String, val extension: String? = null) { - fun matches(requestPath: String): Boolean { - return requestPath.startsWith(basePath) && - (extension == null || requestPath.endsWith(".$extension", ignoreCase = true)) - } - } - -} - -/**********************************************************************************************************************/ -/**************************************************** END OF KOTLIN ***************************************************/ -/**********************************************************************************************************************/ \ No newline at end of file