Skip to content
6 changes: 3 additions & 3 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

val mapStructVersion = "1.6.3"
val swaggerOpenAPIVersion = "3.0.3"
val dotEnvVersion = "5.1.0"
val bouncyCastleVersion = "1.84"

group = "com.devaulty"
version = "0.0.1-SNAPSHOT"
Expand All @@ -35,10 +35,9 @@ dependencies {
implementation("org.springframework.security:spring-security-crypto")
implementation("org.mapstruct:mapstruct:${mapStructVersion}")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:${swaggerOpenAPIVersion}")
implementation(platform("me.paulschwarz:spring-dotenv-bom:${dotEnvVersion}"))
implementation("org.bouncycastle:bcprov-jdk18on:${bouncyCastleVersion}")

developmentOnly("org.springframework.boot:spring-boot-devtools")
developmentOnly("me.paulschwarz:springboot4-dotenv:${dotEnvVersion}")

runtimeOnly("org.xerial:sqlite-jdbc")
runtimeOnly("org.hibernate.orm:hibernate-community-dialects")
Expand All @@ -50,6 +49,7 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-liquibase-test")
testImplementation("org.springframework.boot:spring-boot-starter-validation-test")
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.scheduling.annotation.EnableScheduling;

import static org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO;

@SpringBootApplication
@EnableScheduling
@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
public class BackendApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.devaulty.backend.adapter.in.scheduler;

import com.devaulty.backend.application.port.out.security.MasterKeySessionPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Duration;

@Component
public class VaultAutoLockScheduler {

private final Duration inactivityTimeout = Duration.ofMinutes(15);

private static final Logger logger = LoggerFactory.getLogger(VaultAutoLockScheduler.class);

private final MasterKeySessionPort masterKeySessionPort;

public VaultAutoLockScheduler(MasterKeySessionPort masterKeySessionPort) {
this.masterKeySessionPort = masterKeySessionPort;
}

@Scheduled(fixedDelay = 10000) // Runs every 10 seconds
public void purgeExpiredSession() {
if (!masterKeySessionPort.hasKey()) {
return;
}

if (masterKeySessionPort.getOrClearIfExpired(inactivityTimeout) == null) {
logger.info("Inactivity Timeout reached. Vault locked.");
}
}
}
Loading