Fixing can't login to webgoat #307
This commit is contained in:
@ -103,9 +103,8 @@ public class WebGoat extends SpringBootServletInitializer {
|
||||
@Bean
|
||||
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@SneakyThrows
|
||||
public UserTracker userTracker(@Value("${webgoat.user.directory}") final String webgoatHome,
|
||||
@Value("${webgoat.tracker.overwrite:false}") final boolean overwrite, WebSession webSession) {
|
||||
UserTracker userTracker = new UserTracker(webgoatHome, webSession.getUserName(), overwrite);
|
||||
public UserTracker userTracker(@Value("${webgoat.user.directory}") final String webgoatHome, WebSession webSession) {
|
||||
UserTracker userTracker = new UserTracker(webgoatHome, webSession.getUserName());
|
||||
userTracker.load();
|
||||
return userTracker;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.owasp.webgoat.session;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.lessons.Assignment;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@ -44,17 +45,16 @@ import java.util.stream.Collectors;
|
||||
* @version $Id: $Id
|
||||
* @since October 29, 2003
|
||||
*/
|
||||
@Slf4j
|
||||
public class UserTracker {
|
||||
|
||||
private final String webgoatHome;
|
||||
private final String user;
|
||||
private final boolean overwrite;
|
||||
private Map<String, LessonTracker> storage = new HashMap<>();
|
||||
|
||||
public UserTracker(final String webgoatHome, final String user, final boolean overwrite) {
|
||||
public UserTracker(final String webgoatHome, final String user) {
|
||||
this.webgoatHome = webgoatHome;
|
||||
this.user = user;
|
||||
this.overwrite = overwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,13 +85,15 @@ public class UserTracker {
|
||||
save();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void load() {
|
||||
File file = new File(webgoatHome, user + ".progress");
|
||||
if (overwrite) {
|
||||
this.storage = Maps.newHashMap();
|
||||
} else if (file.exists() && file.isFile()) {
|
||||
this.storage = (Map<String, LessonTracker>) SerializationUtils.deserialize(FileCopyUtils.copyToByteArray(file));
|
||||
if (file.exists() && file.isFile()) {
|
||||
try {
|
||||
this.storage = (Map<String, LessonTracker>) SerializationUtils.deserialize(FileCopyUtils.copyToByteArray(file));
|
||||
} catch (Exception e) {
|
||||
log.error("Unable to read the progress file, creating a new one...");
|
||||
this.storage = Maps.newHashMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +111,7 @@ public class UserTracker {
|
||||
|
||||
public int numberOfLessonsSolved() {
|
||||
int numberOfLessonsSolved = 0;
|
||||
for(LessonTracker lessonTracker : storage.values()) {
|
||||
for (LessonTracker lessonTracker : storage.values()) {
|
||||
if (lessonTracker.isLessonSolved()) {
|
||||
numberOfLessonsSolved = numberOfLessonsSolved + 1;
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ security.enable-csrf=false
|
||||
spring.devtools.restart.enabled=false
|
||||
spring.resources.cache-period=0
|
||||
|
||||
|
||||
webgoat.tracker.overwrite=false
|
||||
webgoat.user.directory=${user.home}/.webgoat/
|
||||
webgoat.build.version=@project.version@
|
||||
webgoat.build.number=@build.number@
|
||||
|
Reference in New Issue
Block a user