diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/CleanupLocalProgressFiles.java b/webgoat-container/src/main/java/org/owasp/webgoat/CleanupLocalProgressFiles.java new file mode 100644 index 000000000..9200a8a5a --- /dev/null +++ b/webgoat-container/src/main/java/org/owasp/webgoat/CleanupLocalProgressFiles.java @@ -0,0 +1,36 @@ +package org.owasp.webgoat; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; +import java.io.File; + +/** + * @author nbaars + * @since 4/15/17. + */ +@Slf4j +@Configuration +@ConditionalOnExpression("'${webgoat.clean}' == 'true'") +public class CleanupLocalProgressFiles { + + @Value("${webgoat.server.directory}") + private String webgoatHome; + + @PostConstruct + public void clean() { + File dir = new File(webgoatHome); + if (dir.exists()) { + File[] progressFiles = dir.listFiles(f -> f.getName().endsWith(".progress")); + if (progressFiles != null) { + log.info("Removing stored user preferences..."); + for (File f : progressFiles) { + f.delete(); + } + } + } + } +} diff --git a/webgoat-container/src/main/resources/application.properties b/webgoat-container/src/main/resources/application.properties index 9d6ad7e56..6ec69f48d 100644 --- a/webgoat-container/src/main/resources/application.properties +++ b/webgoat-container/src/main/resources/application.properties @@ -16,6 +16,7 @@ security.enable-csrf=false spring.resources.cache-period=0 spring.thymeleaf.cache=false +webgoat.clean=true webgoat.server.directory=${user.home}/.webgoat/ webgoat.user.directory=${user.home}/.webgoat/ webgoat.build.version=@project.version@