Skip to content

Commit

Permalink
Merge pull request #62 from groldan/server/auth_caching
Browse files Browse the repository at this point in the history
Add server-side authorization requests caching
  • Loading branch information
groldan authored Apr 4, 2024
2 parents e1ae131 + a62140f commit 799159a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/artifacts/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver.acl.integration</groupId>
<artifactId>gs-acl-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* (c) 2023 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.acl.autoconfigure.cache;

import lombok.extern.slf4j.Slf4j;

import org.geoserver.acl.authorization.cache.CachingAuthorizationServiceConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Import;

import javax.annotation.PostConstruct;

/**
* @since 2.2
* @see CachingAuthorizationServiceConfiguration
*/
@AutoConfiguration
@ConditionalOnProperty(
name = "geoserver.acl.caching.enabled",
havingValue = "true",
matchIfMissing = true)
@Import(CachingAuthorizationServiceConfiguration.class)
@Slf4j(topic = "org.geoserver.acl.autoconfigure.cache")
public class CachingAuthorizationServiceServerAutoConfiguration {

@PostConstruct
void logUsing() {
log.info("Caching ACL AuthorizationService enabled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ org.geoserver.acl.autoconfigure.security.InternalSecurityAutoConfiguration,\
org.geoserver.acl.autoconfigure.security.PreAuthenticationSecurityAutoConfiguration,\
org.geoserver.acl.autoconfigure.security.AuthenticationManagerAutoConfiguration,\
org.geoserver.acl.autoconfigure.springdoc.SpringDocAutoConfiguration,\
org.geoserver.acl.autoconfigure.bus.RabbitAutoConfiguration
org.geoserver.acl.autoconfigure.bus.RabbitAutoConfiguration,\
org.geoserver.acl.autoconfigure.cache.CachingAuthorizationServiceServerAutoConfiguration

17 changes: 17 additions & 0 deletions src/artifacts/api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ spring:
default-property-inclusion: non-empty
serialization:
indent-output: true
cache:
type: caffeine
caffeine:
#CaffeineSpec supports parsing configuration off of a string
#The string syntax is a series of comma-separated keys or key-value pairs, each corresponding to a Caffeine builder method.
#
#initialCapacity=[integer]
#maximumSize=[long]
#maximumWeight=[long]
#expireAfterAccess=[duration]
#expireAfterWrite=[duration]
#refreshAfterWrite=[duration]
#softValues: sets Caffeine.softValues.
#recordStats: sets Caffeine.recordStats.
spec: softValues,initialCapacity=10000,recordStats
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Expand Down Expand Up @@ -128,6 +143,8 @@ jndi:
geoserver:
bus.enabled: false
acl:
caching:
enabled: ${acl.caching:true}
datasource:
jndi-name: ${acl.db.jndiName:java:comp/env/jdbc/acl}
url: ${acl.db.url:}
Expand Down
1 change: 1 addition & 0 deletions src/artifacts/api/src/main/resources/values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rabbitmq.user: guest
rabbitmq.password: guest
#rabbitmq.vhost:

acl.caching: true
#
# Basic auth security configuration
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,13 @@ private ProcessingResult wpsProcessingResult(
}

private AccessInfo getAccessInfo(AccessRequest accessRequest) {
Stopwatch sw = Stopwatch.createStarted();
final Level timeLogLevel = FINE;
final Stopwatch sw = LOGGER.isLoggable(timeLogLevel) ? Stopwatch.createStarted() : null;
AccessInfo accessInfo = aclService.getAccessInfo(accessRequest);
sw.stop();
log(FINE, "ACL auth run in {0}: {1} -> {2}", sw, accessRequest, accessInfo);
if (null != sw) {
sw.stop();
log(timeLogLevel, "ACL auth run in {0}: {1} -> {2}", sw, accessRequest, accessInfo);
}

if (accessInfo == null) {
accessInfo = AccessInfo.DENY_ALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
matchIfMissing = true)
@Import(CachingAuthorizationServiceConfiguration.class)
@Slf4j(topic = "org.geoserver.acl.plugin.autoconfigure.cache")
public class CachingAuthorizationServiceAutoConfiguration {
public class CachingAuthorizationServicePluginAutoConfiguration {

@PostConstruct
void logUsing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.geoserver.acl.plugin.autoconfigure.accessmanager.AclAccessManagerAutoConfiguration,\
org.geoserver.acl.plugin.autoconfigure.webui.AclWebUIAutoConfiguration,\
org.geoserver.acl.plugin.autoconfigure.wps.AclWpsAutoConfiguration,\
org.geoserver.acl.plugin.autoconfigure.cache.CachingAuthorizationServiceAutoConfiguration
org.geoserver.acl.plugin.autoconfigure.cache.CachingAuthorizationServicePluginAutoConfiguration

0 comments on commit 799159a

Please sign in to comment.