-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Both plugins are enabled by default, can be disabled with ``` geoserver.security.ldap=false geoserver.security.jdbc=false ```
- Loading branch information
Showing
15 changed files
with
455 additions
and
2 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
28 changes: 28 additions & 0 deletions
28
...n/java/org/geoserver/cloud/autoconfigure/security/jdbc/JDBCSecurityAutoConfiguration.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,28 @@ | ||
/* | ||
* (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.security.jdbc; | ||
|
||
import org.geoserver.cloud.autoconfigure.security.ConditionalOnGeoServerSecurityEnabled; | ||
import org.geoserver.cloud.autoconfigure.security.GeoServerSecurityAutoConfiguration; | ||
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.ImportResource; | ||
|
||
/** {@link AutoConfiguration @AutoConfiguration} to enable {@code gs-sec-jdbc} */ | ||
// run before GeoServerSecurityAutoConfiguration so the provider is available when | ||
// GeoServerSecurityManager calls GeoServerExtensions.extensions(GeoServerSecurityProvider.class) | ||
@AutoConfiguration(before = GeoServerSecurityAutoConfiguration.class) | ||
@EnableConfigurationProperties(JDBCSecurityConfigProperties.class) | ||
@ConditionalOnGeoServerSecurityEnabled | ||
@ConditionalOnProperty( | ||
name = "geoserver.security.jdbc", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
@ImportResource( | ||
reader = FilteringXmlBeanDefinitionReader.class, // | ||
locations = "jar:gs-sec-jdbc-.*!/applicationContext.xml") | ||
public class JDBCSecurityAutoConfiguration {} |
17 changes: 17 additions & 0 deletions
17
...in/java/org/geoserver/cloud/autoconfigure/security/jdbc/JDBCSecurityConfigProperties.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,17 @@ | ||
/* | ||
* (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.security.jdbc; | ||
|
||
import lombok.Data; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("geoserver.security") | ||
@Data | ||
public class JDBCSecurityConfigProperties { | ||
|
||
/** Enable or disable GeoServer JDBC Security plugin */ | ||
private boolean jdbc = true; | ||
} |
34 changes: 34 additions & 0 deletions
34
...a/org/geoserver/cloud/autoconfigure/security/jdbc/JDBCSecurityWebUIAutoConfiguration.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,34 @@ | ||
/* | ||
* (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.security.jdbc; | ||
|
||
import org.geoserver.cloud.autoconfigure.security.ConditionalOnGeoServerSecurityEnabled; | ||
import org.geoserver.cloud.autoconfigure.security.GeoServerSecurityAutoConfiguration; | ||
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; | ||
import org.geoserver.security.web.auth.AuthenticationFilterPanelInfo; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.ImportResource; | ||
|
||
/** | ||
* {@link AutoConfiguration @AutoConfiguration} to enable {@code gs-web-sec-jdbc} when running with | ||
* the webui components in the classpath | ||
*/ | ||
// run before GeoServerSecurityAutoConfiguration so the provider is available when | ||
// GeoServerSecurityManager calls GeoServerExtensions.extensions(GeoServerSecurityProvider.class) | ||
@AutoConfiguration(before = GeoServerSecurityAutoConfiguration.class) | ||
@EnableConfigurationProperties(JDBCSecurityConfigProperties.class) | ||
@ConditionalOnClass(AuthenticationFilterPanelInfo.class) | ||
@ConditionalOnGeoServerSecurityEnabled | ||
@ConditionalOnProperty( | ||
name = "geoserver.security.jdbc", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
@ImportResource( | ||
reader = FilteringXmlBeanDefinitionReader.class, // | ||
locations = "jar:gs-web-sec-jdbc-.*!/applicationContext.xml") | ||
public class JDBCSecurityWebUIAutoConfiguration {} |
28 changes: 28 additions & 0 deletions
28
...n/java/org/geoserver/cloud/autoconfigure/security/ldap/LDAPSecurityAutoConfiguration.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,28 @@ | ||
/* | ||
* (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.security.ldap; | ||
|
||
import org.geoserver.cloud.autoconfigure.security.ConditionalOnGeoServerSecurityEnabled; | ||
import org.geoserver.cloud.autoconfigure.security.GeoServerSecurityAutoConfiguration; | ||
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.ImportResource; | ||
|
||
/** {@link AutoConfiguration @AutoConfiguration} to enable {@code gs-sec-ldap} */ | ||
// run before GeoServerSecurityAutoConfiguration so the provider is available when | ||
// GeoServerSecurityManager calls GeoServerExtensions.extensions(GeoServerSecurityProvider.class) | ||
@AutoConfiguration(before = GeoServerSecurityAutoConfiguration.class) | ||
@EnableConfigurationProperties(LDAPSecurityConfigProperties.class) | ||
@ConditionalOnGeoServerSecurityEnabled | ||
@ConditionalOnProperty( | ||
name = "geoserver.security.ldap", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
@ImportResource( | ||
reader = FilteringXmlBeanDefinitionReader.class, // | ||
locations = "jar:gs-sec-ldap-.*!/applicationContext.xml") | ||
public class LDAPSecurityAutoConfiguration {} |
17 changes: 17 additions & 0 deletions
17
...in/java/org/geoserver/cloud/autoconfigure/security/ldap/LDAPSecurityConfigProperties.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,17 @@ | ||
/* | ||
* (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.security.ldap; | ||
|
||
import lombok.Data; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("geoserver.security") | ||
@Data | ||
public class LDAPSecurityConfigProperties { | ||
|
||
/** Enable or disable GeoServer LDAP Security plugin */ | ||
private boolean ldap = true; | ||
} |
34 changes: 34 additions & 0 deletions
34
...a/org/geoserver/cloud/autoconfigure/security/ldap/LDAPSecurityWebUIAutoConfiguration.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,34 @@ | ||
/* | ||
* (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.security.ldap; | ||
|
||
import org.geoserver.cloud.autoconfigure.security.ConditionalOnGeoServerSecurityEnabled; | ||
import org.geoserver.cloud.autoconfigure.security.GeoServerSecurityAutoConfiguration; | ||
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; | ||
import org.geoserver.security.web.auth.AuthenticationFilterPanelInfo; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.ImportResource; | ||
|
||
/** | ||
* {@link AutoConfiguration @AutoConfiguration} to enable {@code gs-web-sec-ldap} when running with | ||
* the webui components in the classpath | ||
*/ | ||
// run before GeoServerSecurityAutoConfiguration so the provider is available when | ||
// GeoServerSecurityManager calls GeoServerExtensions.extensions(GeoServerSecurityProvider.class) | ||
@AutoConfiguration(before = GeoServerSecurityAutoConfiguration.class) | ||
@EnableConfigurationProperties(LDAPSecurityConfigProperties.class) | ||
@ConditionalOnClass(AuthenticationFilterPanelInfo.class) | ||
@ConditionalOnGeoServerSecurityEnabled | ||
@ConditionalOnProperty( | ||
name = "geoserver.security.ldap", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
@ImportResource( | ||
reader = FilteringXmlBeanDefinitionReader.class, // | ||
locations = "jar:gs-web-sec-ldap-.*!/applicationContext.xml") | ||
public class LDAPSecurityWebUIAutoConfiguration {} |
6 changes: 5 additions & 1 deletion
6
src/starters/security/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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
org.geoserver.cloud.autoconfigure.authzn.AuthKeyAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.authzn.GatewayPreAuthenticationAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.authzn.GatewaySharedAuthenticationAutoConfiguration | ||
org.geoserver.cloud.autoconfigure.authzn.GatewaySharedAuthenticationAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.security.jdbc.JDBCSecurityAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.security.jdbc.JDBCSecurityWebUIAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.security.ldap.LDAPSecurityAutoConfiguration,\ | ||
org.geoserver.cloud.autoconfigure.security.ldap.LDAPSecurityWebUIAutoConfiguration |
46 changes: 46 additions & 0 deletions
46
...va/org/geoserver/cloud/autoconfigure/security/jdbc/JDBCSecurityAutoConfigurationTest.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) 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.security.jdbc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.geoserver.security.GeoServerSecurityManager; | ||
import org.geoserver.security.jdbc.JDBCSecurityProvider; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; | ||
|
||
class JDBCSecurityAutoConfigurationTest { | ||
|
||
private WebApplicationContextRunner runner = | ||
new WebApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(JDBCSecurityAutoConfiguration.class)) | ||
.withBean( | ||
GeoServerSecurityManager.class, | ||
() -> mock(GeoServerSecurityManager.class)); | ||
|
||
@Test | ||
void testExpectedBeans() { | ||
runner.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.hasSingleBean(JDBCSecurityProvider.class) | ||
.getBean(JDBCSecurityConfigProperties.class) | ||
.hasFieldOrPropertyWithValue("jdbc", true)); | ||
} | ||
|
||
@Test | ||
void testDisabled() { | ||
runner.withPropertyValues("geoserver.security.jdbc=false") | ||
.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.doesNotHaveBean(JDBCSecurityProvider.class) | ||
.doesNotHaveBean(JDBCSecurityConfigProperties.class)); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...g/geoserver/cloud/autoconfigure/security/jdbc/JDBCSecurityWebUIAutoConfigurationTest.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,72 @@ | ||
/* | ||
* (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.security.jdbc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.geoserver.platform.ModuleStatusImpl; | ||
import org.geoserver.security.GeoServerSecurityManager; | ||
import org.geoserver.security.web.auth.AuthenticationFilterPanelInfo; | ||
import org.geoserver.security.web.jdbc.JDBCAuthProviderPanelInfo; | ||
import org.geoserver.security.web.jdbc.JDBCRoleServicePanelInfo; | ||
import org.geoserver.security.web.jdbc.JDBCUserGroupServicePanelInfo; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.FilteredClassLoader; | ||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; | ||
|
||
class JDBCSecurityWebUIAutoConfigurationTest { | ||
|
||
private WebApplicationContextRunner runner = | ||
new WebApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of( | ||
JDBCSecurityAutoConfiguration.class, | ||
JDBCSecurityWebUIAutoConfiguration.class)) | ||
.withBean( | ||
GeoServerSecurityManager.class, | ||
() -> mock(GeoServerSecurityManager.class)); | ||
|
||
@Test | ||
void testConditionalOnClassNoMatch() { | ||
runner.withClassLoader(new FilteredClassLoader(AuthenticationFilterPanelInfo.class)) | ||
.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.doesNotHaveBean(JDBCUserGroupServicePanelInfo.class) | ||
.doesNotHaveBean(JDBCRoleServicePanelInfo.class) | ||
.doesNotHaveBean(JDBCAuthProviderPanelInfo.class) | ||
.doesNotHaveBean("jdbcSecurityWebExtension")); | ||
} | ||
|
||
@Test | ||
void testConditionalOnClassMatch() { | ||
runner.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.hasSingleBean(JDBCUserGroupServicePanelInfo.class) | ||
.hasSingleBean(JDBCRoleServicePanelInfo.class) | ||
.hasSingleBean(JDBCAuthProviderPanelInfo.class) | ||
.hasBean("jdbcSecurityWebExtension") | ||
.getBean("jdbcSecurityWebExtension") | ||
.isInstanceOf(ModuleStatusImpl.class)); | ||
} | ||
|
||
@Test | ||
void testDisabled() { | ||
runner.withPropertyValues("geoserver.security.jdbc=false") | ||
.run( | ||
context -> | ||
assertThat(context) | ||
.hasNotFailed() | ||
.doesNotHaveBean(JDBCUserGroupServicePanelInfo.class) | ||
.doesNotHaveBean(JDBCRoleServicePanelInfo.class) | ||
.doesNotHaveBean(JDBCAuthProviderPanelInfo.class) | ||
.doesNotHaveBean("jdbcSecurityWebExtension")); | ||
} | ||
} |
Oops, something went wrong.