-
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.
Merge pull request #564 from groldan/sec-jdbc-and-ldap
Add JDBC and LDAP security plugins
- Loading branch information
Showing
19 changed files
with
459 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
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)); | ||
} | ||
} |
Oops, something went wrong.