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

@ -32,7 +32,7 @@ import org.owasp.webgoat.lessons.model.AttackResult;
* @version $Id: $Id
* @since August 08, 2016
*/
public interface Attack {
public interface Attack {
AttackResult attack();

View File

@ -25,6 +25,7 @@
*/
package org.owasp.webgoat.lessons;
import org.owasp.webgoat.lessons.model.AttackResult;
import org.owasp.webgoat.session.LessonTracker;
import org.owasp.webgoat.session.UserTracker;
import org.owasp.webgoat.session.WebSession;
@ -52,6 +53,7 @@ public abstract class LessonEndpoint implements MvcEndpoint {
private File pluginDirectory;
@Autowired
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
@ -75,6 +77,12 @@ public abstract class LessonEndpoint implements MvcEndpoint {
return lessonTracker;
}
protected AttackResult trackProgress(AttackResult attackResult) {
this.solved = attackResult.isLessonCompleted();
getLessonTracker().setCompleted(solved);
return attackResult;
}
@Override
public final boolean isSensitive() {
return false;

View File

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

View File

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