-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #495 from groldan/gateway_shared_auth_disable_config
Allow to disable gateway-shared-auth global filter in the gateway
- Loading branch information
Showing
9 changed files
with
174 additions
and
49 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...n/java/org/geoserver/cloud/autoconfigure/gateway/GatewayApplicationAutoconfiguration.java
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,79 @@ | ||
/* | ||
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.autoconfigure.gateway; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.geoserver.cloud.gateway.filter.GatewaySharedAuhenticationGlobalFilter; | ||
import org.geoserver.cloud.gateway.filter.RouteProfileGatewayFilterFactory; | ||
import org.geoserver.cloud.gateway.filter.StripBasePathGatewayFilterFactory; | ||
import org.geoserver.cloud.gateway.predicate.RegExpQueryRoutePredicateFactory; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.env.Environment; | ||
|
||
@AutoConfiguration | ||
@Slf4j | ||
public class GatewayApplicationAutoconfiguration { | ||
|
||
/** | ||
* Custom gateway predicate factory to support matching by regular expressions on both name and | ||
* value of query parameters | ||
* | ||
* <p>E.g.: | ||
* | ||
* <pre>{@code | ||
* - id: wms_ows | ||
* uri: http://wms-service:8080 | ||
* predicates: | ||
* # match service=wms case insensitively | ||
* - RegExpQuery=(?i:service),(?i:wms) | ||
* }</pre> | ||
*/ | ||
@Bean | ||
RegExpQueryRoutePredicateFactory regExpQueryRoutePredicateFactory() { | ||
return new RegExpQueryRoutePredicateFactory(); | ||
} | ||
|
||
/** | ||
* Allows to enable routes only if a given spring profile is enabled | ||
* | ||
* <p>Since the `spring.cloud.gateway.routes` is a list and not a map/dictionary, routes can't | ||
* be added in profiles, because the list is overritten fully. This filter allows to enable | ||
* routes based on profiles from a single list of routes. | ||
* | ||
* <p>E.g.: | ||
* | ||
* <pre>{@code | ||
* - id: catalog | ||
* uri: ... | ||
* predicates: | ||
* - Path=${geoserver.base-path}/api/v1/** | ||
* filters: | ||
* # Expose the catalog and configuration API only if the dev profile is active | ||
* - RouteProfile=dev,403 | ||
* }</pre> | ||
*/ | ||
@Bean | ||
RouteProfileGatewayFilterFactory routeProfileGatewayFilterFactory(Environment environment) { | ||
return new RouteProfileGatewayFilterFactory(environment); | ||
} | ||
|
||
@Bean | ||
StripBasePathGatewayFilterFactory stripBasePathGatewayFilterFactory() { | ||
return new StripBasePathGatewayFilterFactory(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty( | ||
name = "geoserver.security.gateway-shared-auth.enabled", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
GatewaySharedAuhenticationGlobalFilter gatewaySharedAuhenticationGlobalFilter() { | ||
log.info("gateway-shared-auth is enabled"); | ||
return new GatewaySharedAuhenticationGlobalFilter(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ain/java/org/geoserver/cloud/autoconfigure/gateway/SharedAuthConfigurationProperties.java
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,25 @@ | ||
/* | ||
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.autoconfigure.gateway; | ||
|
||
import lombok.Data; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* For automatic documentation purposes only, as used by the {@literal | ||
* spring-boot-configuration-processor} | ||
*/ | ||
@ConfigurationProperties(prefix = "geoserver.security.gateway-shared-auth") | ||
@Data | ||
class SharedAuthConfigurationProperties { | ||
|
||
/** | ||
* Enable or disable the Gateway/WebUI Shared Authentication mechanism, where the Gateway works | ||
* as mediator to share the authentication from the GeoServer WebUI with the rest of the | ||
* services. | ||
*/ | ||
private boolean enabled = true; | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/apps/infrastructure/gateway/src/main/resources/META-INF/spring.factories
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,3 @@ | ||
# Auto Configure | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
org.geoserver.cloud.autoconfigure.gateway.GatewayApplicationAutoconfiguration |
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
46 changes: 46 additions & 0 deletions
46
...va/org/geoserver/cloud/autoconfigure/gateway/GatewayApplicationAutoconfigurationTest.java
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,46 @@ | ||
/* | ||
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.autoconfigure.gateway; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.geoserver.cloud.gateway.filter.GatewaySharedAuhenticationGlobalFilter; | ||
import org.geoserver.cloud.gateway.filter.RouteProfileGatewayFilterFactory; | ||
import org.geoserver.cloud.gateway.filter.StripBasePathGatewayFilterFactory; | ||
import org.geoserver.cloud.gateway.predicate.RegExpQueryRoutePredicateFactory; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; | ||
|
||
class GatewayApplicationAutoconfigurationTest { | ||
|
||
private ReactiveWebApplicationContextRunner runner = | ||
new ReactiveWebApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of(GatewayApplicationAutoconfiguration.class)); | ||
|
||
@Test | ||
void testDefaultAppContextContributions() { | ||
runner.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.hasSingleBean(RegExpQueryRoutePredicateFactory.class) | ||
.hasSingleBean(RouteProfileGatewayFilterFactory.class) | ||
.hasSingleBean(StripBasePathGatewayFilterFactory.class) | ||
.hasSingleBean(GatewaySharedAuhenticationGlobalFilter.class)); | ||
} | ||
|
||
@Test | ||
void disableGatewaySharedAuhenticationGlobalFilter() { | ||
runner.withPropertyValues("geoserver.security.gateway-shared-auth.enabled: false") | ||
.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.doesNotHaveBean( | ||
GatewaySharedAuhenticationGlobalFilter.class)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/apps/infrastructure/gateway/src/test/resources/logback-test.xml
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,13 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="org.springframework" level="info"/> | ||
</configuration> |
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