commit
6116b8e368
@ -1,5 +1,6 @@
|
|||||||
package org.owasp.webgoat.plugins;
|
package org.owasp.webgoat.plugins;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -61,7 +62,7 @@ public class Plugin {
|
|||||||
|
|
||||||
private void loadClass(String name, byte[] classFile) {
|
private void loadClass(String name, byte[] classFile) {
|
||||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
PluginClassLoader pluginClassLoader = new PluginClassLoader(contextClassLoader, classFile);
|
PluginClassLoader pluginClassLoader = new PluginClassLoader(contextClassLoader, name, classFile);
|
||||||
try {
|
try {
|
||||||
String realClassName = name.replaceFirst("/", "").replaceAll("/", ".").replaceAll(".class", "");
|
String realClassName = name.replaceFirst("/", "").replaceAll("/", ".").replaceAll(".class", "");
|
||||||
Class clazz = pluginClassLoader.loadClass(realClassName);
|
Class clazz = pluginClassLoader.loadClass(realClassName);
|
||||||
@ -123,17 +124,24 @@ public class Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractLesson getLesson() {
|
||||||
|
try {
|
||||||
|
return lesson.newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
|
throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Class<AbstractLesson> getLesson() {
|
public Optional<File> getLessonSolution(String language) {
|
||||||
return lesson;
|
return Optional.fromNullable(this.solutionLanguageFiles.get(language));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, File> getLessonSolutions() {
|
public Map<String, File> getLessonSolutions() {
|
||||||
return this.solutionLanguageFiles;
|
return this.solutionLanguageFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getLessonSource() {
|
public Optional<File> getLessonSource() {
|
||||||
return lessonSourceFile;
|
return Optional.fromNullable(lessonSourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, File> getLessonPlans() {
|
public Map<String, File> getLessonPlans() {
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package org.owasp.webgoat.plugins;
|
package org.owasp.webgoat.plugins;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class PluginClassLoader extends ClassLoader {
|
public class PluginClassLoader extends ClassLoader {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(Plugin.class);
|
||||||
private final byte[] classFile;
|
private final byte[] classFile;
|
||||||
|
|
||||||
public PluginClassLoader(ClassLoader parent, byte[] classFile) {
|
public PluginClassLoader(ClassLoader parent, String nameOfClass, byte[] classFile) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
logger.debug("Creating class loader for {}", nameOfClass);
|
||||||
this.classFile = classFile;
|
this.classFile = classFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class findClass(String name) {
|
public Class findClass(String name) {
|
||||||
|
logger.debug("Finding class " + name);
|
||||||
return defineClass(name, classFile, 0, classFile.length);
|
return defineClass(name, classFile, 0, classFile.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map
|
import java.util.Map;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.owasp.webgoat.HammerHead;
|
import org.owasp.webgoat.HammerHead;
|
||||||
@ -304,12 +304,8 @@ public class Course {
|
|||||||
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
||||||
for (Plugin plugin : plugins) {
|
for (Plugin plugin : plugins) {
|
||||||
try {
|
try {
|
||||||
Class<AbstractLesson> c = plugin.getLesson();
|
AbstractLesson lesson = plugin.getLesson();
|
||||||
Object o = c.newInstance();
|
|
||||||
|
|
||||||
AbstractLesson lesson = (AbstractLesson) o;
|
|
||||||
lesson.setWebgoatContext(webgoatContext);
|
lesson.setWebgoatContext(webgoatContext);
|
||||||
|
|
||||||
lesson.update(properties);
|
lesson.update(properties);
|
||||||
|
|
||||||
if (!lesson.getHidden()) {
|
if (!lesson.getHidden()) {
|
||||||
@ -318,8 +314,12 @@ public class Course {
|
|||||||
for(Map.Entry<String, File> lessonPlan : plugin.getLessonPlans().entrySet()) {
|
for(Map.Entry<String, File> lessonPlan : plugin.getLessonPlans().entrySet()) {
|
||||||
lesson.setLessonPlanFileName(lessonPlan.getKey(), lessonPlan.getValue().toString());
|
lesson.setLessonPlanFileName(lessonPlan.getKey(), lessonPlan.getValue().toString());
|
||||||
}
|
}
|
||||||
lesson.setLessonSolutionFileName(plugin.getLessonSolutions().get("en").toString());
|
if (plugin.getLessonSolution("en").isPresent()) {
|
||||||
lesson.setSourceFileName(plugin.getLessonSource().toString());
|
lesson.setLessonSolutionFileName(plugin.getLessonSolution("en").toString());
|
||||||
|
}
|
||||||
|
if (plugin.getLessonSource().isPresent()) {
|
||||||
|
lesson.setSourceFileName(plugin.getLessonSource().get().toString());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error in loadLessons: ", e);
|
logger.error("Error in loadLessons: ", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user