Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ The included `docker-compose.yml` provides a complete setup with:
| `OIDC_SIGN_UP_ENABLED` | Whether new users should be signed up automatically if they first login via the OIDC Provider. (optional) | true | false |
| `PROCESSING_WAIT_TIME` | How many seconds to wait after the last data input before starting to process all unprocessed data. (⚠️ This needs to be lower than your integrated app reports data in Reitti) | 15 | 15 |
| `DANGEROUS_LIFE` | Enables data management features that can reset/delete all database data (⚠️ USE WITH CAUTION) | false | true |
| `TILES_CACHE` | The url of the tile caching proxy (Set to '' to disable the cache | http://tile-cache | |
| `TILES_CACHE` | The url of the tile caching proxy (Set to '' to disable the cache) | http://tile-cache | |
| `PROCESSING_BATCH_SIZE` | How many geo points should we handle at once. For low-memory environment it could be needed to set this to 100. | 1000 | 100 |
| `SERVER_PORT` | Application server port | 8080 | 8080 |
| `APP_UID` | User ID to run the application as | 1000 | 1000 |
Expand Down
2 changes: 1 addition & 1 deletion docker/tiles-cache/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM nginx:alpine

# Create cache directories for different tile types
RUN mkdir -p /var/cache/nginx/osm /var/cache/nginx/vector /var/cache/nginx/terrain /var/cache/nginx/satellite
RUN mkdir -p /var/cache/nginx/osm /var/cache/nginx/vector /var/cache/nginx/custom /var/cache/nginx/terrain /var/cache/nginx/satellite

COPY nginx.conf /etc/nginx/nginx.conf

Expand Down
30 changes: 29 additions & 1 deletion docker/tiles-cache/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ http {
loader_threshold=300 loader_files=200 loader_sleep=50ms
manager_threshold=300 manager_files=200 manager_sleep=50ms;

proxy_cache_path /var/cache/nginx/custom
levels=1:2 keys_zone=custom_tiles:512m max_size=2g inactive=180d use_temp_path=off
loader_threshold=300 loader_files=200 loader_sleep=50ms
manager_threshold=300 manager_files=200 manager_sleep=50ms;

proxy_cache_path /var/cache/nginx/terrain
levels=1:2 keys_zone=terrain_tiles:512m max_size=2g inactive=180d use_temp_path=off
loader_threshold=300 loader_files=200 loader_sleep=50ms
Expand All @@ -88,6 +93,7 @@ http {
access_log /var/log/nginx/access.log main;

server_tokens off;
resolver 127.0.0.11 ipv6=off valid=300s;

server {
listen 80;
Expand Down Expand Up @@ -128,6 +134,28 @@ http {
expires 1y;
}

location /custom/ {
set $custom_upstream $http_x_reitti_upstream_url;
if ($custom_upstream = "") {
return 400;
}

proxy_pass $custom_upstream;
proxy_set_header Host $proxy_host;
proxy_set_header User-Agent "Reitti/1.0";
proxy_ssl_server_name on;

proxy_cache custom_tiles;
proxy_cache_key "$custom_upstream";
proxy_cache_valid 200 302 1y;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

add_header X-Cache-Status $upstream_cache_status;
add_header Cache-Control $tile_client_cache_control;
expires 1y;
}

location /terrain/ {
proxy_pass https://tiles.mapterhorn.com/;
proxy_set_header Host tiles.mapterhorn.com;
Expand Down Expand Up @@ -166,4 +194,4 @@ http {
add_header Content-Type text/plain;
}
}
}
}
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import com.dedicatedcode.reitti.model.security.UserSettings;
import com.dedicatedcode.reitti.repository.RawLocationPointJdbcService;
import com.dedicatedcode.reitti.repository.UserJdbcService;
import com.dedicatedcode.reitti.repository.UserMapStyleJdbcService;
import com.dedicatedcode.reitti.repository.UserSettingsJdbcService;
import com.dedicatedcode.reitti.service.ContextPathHolder;
import com.dedicatedcode.reitti.service.TilesCustomizationProvider;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -30,17 +34,26 @@ public class UserSettingsControllerAdvice {
public static final double DEFAULT_HOME_LONGITUDE = 24.9384;
private final UserJdbcService userJdbcService;
private final UserSettingsJdbcService userSettingsJdbcService;
private final UserMapStyleJdbcService userMapStyleJdbcService;
private final TilesCustomizationProvider tilesCustomizationProvider;
private final RawLocationPointJdbcService rawLocationPointJdbcService;
private final ContextPathHolder contextPathHolder;
private final ObjectMapper objectMapper;

public UserSettingsControllerAdvice(UserJdbcService userJdbcService,
UserSettingsJdbcService userSettingsJdbcService,
UserMapStyleJdbcService userMapStyleJdbcService,
TilesCustomizationProvider tilesCustomizationProvider,
RawLocationPointJdbcService rawLocationPointJdbcService) {
RawLocationPointJdbcService rawLocationPointJdbcService,
ContextPathHolder contextPathHolder,
ObjectMapper objectMapper) {
this.userJdbcService = userJdbcService;
this.userSettingsJdbcService = userSettingsJdbcService;
this.userMapStyleJdbcService = userMapStyleJdbcService;
this.tilesCustomizationProvider = tilesCustomizationProvider;
this.rawLocationPointJdbcService = rawLocationPointJdbcService;
this.contextPathHolder = contextPathHolder;
this.objectMapper = objectMapper;
}

@ModelAttribute("userSettings")
Expand Down Expand Up @@ -109,6 +122,37 @@ public UserSettingsDTO getCurrentUserSettings() {
null);
}

@ModelAttribute("mapStylesJson")
public String getCurrentUserMapStylesJson() {
return getCurrentUser().map(user -> {
try {
return objectMapper.writeValueAsString(userMapStyleJdbcService.getSettings(user, normalizedContextPath()).customStyles());
} catch (JsonProcessingException e) {
return "[]";
}
}).orElse("[]");
}

@ModelAttribute("activeMapStyleId")
public String getCurrentUserActiveMapStyleId() {
return getCurrentUser()
.map(userMapStyleJdbcService::getActiveStyleId)
.orElse("reitti");
}

private Optional<User> getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !authentication.isAuthenticated() || "anonymousUser".equals(authentication.getPrincipal())) {
return Optional.empty();
}
return userJdbcService.findByUsername(authentication.getName());
}

private String normalizedContextPath() {
String contextPath = contextPathHolder.getContextPath();
return "/".equals(contextPath) ? "" : contextPath;
}

private UserSettingsDTO.UIMode mapUserToUiMode(Authentication authentication) {
List<String> grantedRoles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).toList();
if (grantedRoles.contains("ROLE_ADMIN") || grantedRoles.contains("ROLE_USER") || grantedRoles.contains("ROLE_API_ACCESS")) {
Expand Down
Loading