WIP lesson completion

This commit is contained in:
Nanne Baars 2016-10-12 13:40:54 -04:00
parent 217d87e523
commit 2803607901
4 changed files with 13 additions and 22 deletions

View File

@ -25,6 +25,7 @@
*/ */
package org.owasp.webgoat.lessons; package org.owasp.webgoat.lessons;
import org.owasp.webgoat.lessons.model.AttackResult;
import org.owasp.webgoat.session.LessonTracker; import org.owasp.webgoat.session.LessonTracker;
import org.owasp.webgoat.session.UserTracker; import org.owasp.webgoat.session.UserTracker;
import org.owasp.webgoat.session.WebSession; import org.owasp.webgoat.session.WebSession;
@ -52,6 +53,7 @@ public abstract class LessonEndpoint implements MvcEndpoint {
private File pluginDirectory; private File pluginDirectory;
@Autowired @Autowired
private WebSession webSession; private WebSession webSession;
private boolean solved = false;
/** /**
* The directory of the plugin directory in which the lessons resides, so if you want to access the lesson 'ClientSideFiltering' you will * The directory of the plugin directory in which the lessons resides, so if you want to access the lesson 'ClientSideFiltering' you will
@ -75,6 +77,12 @@ public abstract class LessonEndpoint implements MvcEndpoint {
return lessonTracker; return lessonTracker;
} }
protected AttackResult trackProgress(AttackResult attackResult) {
this.solved = attackResult.isLessonCompleted();
getLessonTracker().setCompleted(solved);
return attackResult;
}
@Override @Override
public final boolean isSensitive() { public final boolean isSensitive() {
return false; return false;

View File

@ -85,15 +85,12 @@ public class Plugin {
final List<String> hints = (List<String>) lessonYml.get("hints"); final List<String> hints = (List<String>) lessonYml.get("hints");
final String title = (String) lessonYml.get("title"); final String title = (String) lessonYml.get("title");
final String html = (String) lessonYml.get("id"); final String html = (String) lessonYml.get("id");
Class attackClazz = findAttack(html); this.ymlBasedLesson = new YmlBasedLesson(category, hints, title, html);
this.ymlBasedLesson = new YmlBasedLesson(category, hints, title, html, attackClazz);
this.lesson = null; this.lesson = null;
} catch (IOException e) { } catch (IOException e) {
throw new PluginLoadingFailure("Unable to read yml file", e); throw new PluginLoadingFailure("Unable to read yml file", e);
} }
} }
} }
private Class findAttack(String id) { private Class findAttack(String id) {

View File

@ -1,8 +1,8 @@
package org.owasp.webgoat.plugins; package org.owasp.webgoat.plugins;
import org.owasp.webgoat.lessons.Attack;
import org.owasp.webgoat.lessons.Category; import org.owasp.webgoat.lessons.Category;
import org.owasp.webgoat.lessons.LessonAdapter; import org.owasp.webgoat.lessons.LessonAdapter;
import org.owasp.webgoat.lessons.LessonEndpoint;
import org.owasp.webgoat.session.WebSession; import org.owasp.webgoat.session.WebSession;
import java.util.List; import java.util.List;
@ -43,15 +43,13 @@ public class YmlBasedLesson extends LessonAdapter {
private final List<String> hints; private final List<String> hints;
private final String title; private final String title;
private final String id; private final String id;
private Attack attack; private List<LessonEndpoint> lessonEndpoints;
public YmlBasedLesson(String category, List<String> hints, String title, String id, Class attack) { public YmlBasedLesson(String category, List<String> hints, String title, String id) {
this.category = category; this.category = category;
this.hints = hints; this.hints = hints;
this.title = title; this.title = title;
this.id = id; this.id = id;
// createAttack(attack);
} }
@Override @Override
@ -78,16 +76,4 @@ public class YmlBasedLesson extends LessonAdapter {
return id; return id;
} }
public Attack getLessonAttack() {
return this.attack;
}
private void createAttack(Class attack) {
try {
this.attack = (Attack) attack.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
} }