Skip to content

Commit

Permalink
Merge pull request #25 from groldan/plugin/access_manager_use_provide…
Browse files Browse the repository at this point in the history
…d_lgcontainmentcache

plugin: access manager use provided LayerGroupContainmentCache
  • Loading branch information
groldan authored Jul 17, 2023
2 parents b620673 + f14f8cf commit d077b8d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package org.geoserver.acl.plugin.autoconfigure.accessmanager;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import org.geoserver.acl.plugin.accessmanager.ACLDispatcherCallback;
import org.geoserver.acl.plugin.accessmanager.ACLResourceAccessManager;
import org.geoserver.acl.plugin.accessmanager.wps.WPSHelper;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.impl.CatalogImpl;
import org.geoserver.security.impl.LayerGroupContainmentCache;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand All @@ -21,6 +23,10 @@ class AclAccessManagerAutoConfigurationTest {
private ApplicationContextRunner runner =
new ApplicationContextRunner()
.withBean("rawCatalog", Catalog.class, CatalogImpl::new)
.withBean(
"layerGroupContainmentCache",
LayerGroupContainmentCache.class,
() -> mock(LayerGroupContainmentCache.class))
.withConfiguration(
AutoConfigurations.of(AclAccessManagerAutoConfiguration.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public class ACLDispatcherCallback extends AbstractDispatcherCallback {

public ACLDispatcherCallback(
AuthorizationService aclService,
Catalog catalog,
LocalWorkspaceCatalog catalog,
AccessManagerConfigProvider configProvider) {

this.aclService = aclService;
this.catalog = new LocalWorkspaceCatalog(catalog);
this.catalog = catalog;
this.configProvider = configProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.geoserver.acl.plugin.accessmanager.wps.WPSAccessInfo;
import org.geoserver.acl.plugin.accessmanager.wps.WPSHelper;
import org.geoserver.acl.plugin.support.GeomHelper;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogInfo;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.FeatureTypeInfo;
Expand All @@ -36,7 +35,6 @@
import org.geoserver.catalog.WMSLayerInfo;
import org.geoserver.catalog.WMTSLayerInfo;
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.catalog.impl.LocalWorkspaceCatalog;
import org.geoserver.ows.Dispatcher;
import org.geoserver.ows.Request;
import org.geoserver.platform.ExtensionPriority;
Expand Down Expand Up @@ -112,29 +110,20 @@ enum PropertyAccessMode {

public ACLResourceAccessManager(
AuthorizationService aclService,
Catalog catalog,
LayerGroupContainmentCache groupsCache,
AccessManagerConfigProvider configurationManager,
WPSHelper wpsHelper) {

this.aclService = aclService;
this.configProvider = configurationManager;
this.groupsCache = new LayerGroupContainmentCache(new LocalWorkspaceCatalog(catalog));
this.groupsCache = groupsCache;
this.wpsHelper = wpsHelper;
}

public AccessManagerConfig getConfig() {
return this.configProvider.get();
}

/**
* sets the layer group cache
*
* @param groupsCache
*/
public void setGroupsCache(LayerGroupContainmentCache groupsCache) {
this.groupsCache = groupsCache;
}

static boolean isAuthenticated(Authentication user) {
return (user != null) && !(user instanceof AnonymousAuthenticationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.geoserver.acl.plugin.accessmanager.AccessManagerConfigProvider;
import org.geoserver.acl.plugin.accessmanager.wps.WPSHelper;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.impl.LocalWorkspaceCatalog;
import org.geoserver.security.impl.LayerGroupContainmentCache;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -18,16 +20,21 @@ public ACLResourceAccessManager aclAccessManager(
AuthorizationService aclService,
@Qualifier("rawCatalog") Catalog catalog,
AccessManagerConfigProvider configProvider,
LayerGroupContainmentCache groupsCache,
WPSHelper wpsHelper) {
return new ACLResourceAccessManager(aclService, catalog, configProvider, wpsHelper);

return new ACLResourceAccessManager(aclService, groupsCache, configProvider, wpsHelper);
}

@Bean
public ACLDispatcherCallback aclDispatcherCallback(
AuthorizationService aclAuthorizationService,
@Qualifier("rawCatalog") Catalog catalog,
AccessManagerConfigProvider configProvider) {
return new ACLDispatcherCallback(aclAuthorizationService, catalog, configProvider);

LocalWorkspaceCatalog localWorkspaceCatalog = new LocalWorkspaceCatalog(catalog);
return new ACLDispatcherCallback(
aclAuthorizationService, localWorkspaceCatalog, configProvider);
}

@Bean
Expand Down

0 comments on commit d077b8d

Please sign in to comment.