From 7fe6e1bb6ea21a2f7f7cbc1619f259ffbb77dae8 Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Wed, 12 Oct 2016 15:21:39 -0400 Subject: [PATCH] No more yml --- .../org/owasp/webgoat/lessons/NewLesson.java | 52 +++++++++++++++++++ .../org/owasp/webgoat/plugins/Plugin.java | 26 ++++------ 2 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java new file mode 100644 index 000000000..b19db4194 --- /dev/null +++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java @@ -0,0 +1,52 @@ +package org.owasp.webgoat.lessons; + +import org.owasp.webgoat.session.WebSession; + +import java.util.List; + +/** + * ************************************************************************************************ + * This file is part of WebGoat, an Open Web Application Security Project utility. For details, + * please see http://www.owasp.org/ + *

+ * Copyright (c) 2002 - 20014 Bruce Mayhew + *

+ * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License along with this program; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + *

+ * Getting Source ============== + *

+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *

+ * + * @author WebGoat + * @version $Id: $Id + * @since October 12, 2016 + */ +public abstract class NewLesson extends LessonAdapter { + + @Override + public abstract Category getDefaultCategory(); + + @Override + public abstract List getHints(WebSession s); //TODO we should probably remove WebSession due to old lessons still here + + @Override + public abstract Integer getDefaultRanking(); + + @Override + public abstract String getTitle(); + + @Override + public abstract String getId(); +} diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java index 23395dd51..5a9772523 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java @@ -5,9 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.google.common.base.Optional; import com.google.common.collect.Lists; -import com.google.common.reflect.ClassPath; import org.apache.commons.io.FileUtils; import org.owasp.webgoat.lessons.AbstractLesson; +import org.owasp.webgoat.lessons.NewLesson; import org.springframework.util.StringUtils; import java.io.File; @@ -33,7 +33,8 @@ public class Plugin { private PluginClassLoader classLoader; private Class lesson; - private YmlBasedLesson ymlBasedLesson; + private YmlBasedLesson ymlBasedLesson; //TODO REMOVE! + private Class newLesson; private Map solutionLanguageFiles = new HashMap<>(); private Map lessonPlansLanguageFiles = new HashMap<>(); private List pluginFiles = Lists.newArrayList(); @@ -64,11 +65,14 @@ public class Plugin { if (AbstractLesson.class.isAssignableFrom(clazz)) { this.lesson = clazz; } + if (NewLesson.class.isAssignableFrom(clazz)) { + this.newLesson = clazz; + } } catch (ClassNotFoundException ce) { throw new PluginLoadingFailure("Class " + realClassName + " listed in jar but unable to load the class.", ce); } - //New code all lessons should work as below + //TODO remove readYmlLessonConfiguration(); } @@ -93,19 +97,6 @@ public class Plugin { } } - private Class findAttack(String id) { - try { - for (final ClassPath.ClassInfo info : ClassPath.from(this.classLoader).getTopLevelClasses()) { - if (info.getName().endsWith(id)) { - return info.load(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - /** *

loadFiles.

* @@ -176,6 +167,9 @@ public class Plugin { if (lesson != null) { return Optional.of(lesson.newInstance()); } + if (newLesson != null) { + return Optional.of(newLesson.newInstance()); + } } catch (IllegalAccessException | InstantiationException e) { throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);