Endpoints provided by lessons now work
This commit is contained in:
@ -3,10 +3,12 @@ package org.owasp.webgoat.plugins;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.lessons.LessonEndpointMapping;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -27,13 +29,14 @@ public class Plugin {
|
||||
|
||||
private static final String NAME_LESSON_SOLUTION_DIRECTORY = "lessonSolutions";
|
||||
private static final String NAME_LESSON_PLANS_DIRECTORY = "lessonPlans";
|
||||
private final PluginClassLoader classLoader;
|
||||
public static PluginClassLoader classLoader;
|
||||
|
||||
private Class<AbstractLesson> lesson;
|
||||
private Map<String, File> solutionLanguageFiles = new HashMap<>();
|
||||
private Map<String, File> lessonPlansLanguageFiles = new HashMap<>();
|
||||
private List<File> pluginFiles = Lists.newArrayList();
|
||||
private File lessonSourceFile;
|
||||
private List<Class> lessonEndpoints = Lists.newArrayList();
|
||||
|
||||
public Plugin(PluginClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
@ -47,6 +50,22 @@ public class Plugin {
|
||||
public void findLesson(List<String> classes) {
|
||||
for (String clazzName : classes) {
|
||||
findLesson(clazzName);
|
||||
findLessonEndpoints(clazzName);
|
||||
}
|
||||
}
|
||||
|
||||
private void findLessonEndpoints(String name) {
|
||||
String realClassName = StringUtils.trimLeadingCharacter(name, '/').replaceAll("/", ".").replaceAll(".class", "");
|
||||
try {
|
||||
Class endpointClass = classLoader.loadClass(realClassName);
|
||||
Annotation annotation = endpointClass.getAnnotation(LessonEndpointMapping.class);
|
||||
if (annotation != null ) {
|
||||
this.lessonEndpoints.add(endpointClass);
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +104,10 @@ public class Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Class> getLessonEndpoints() {
|
||||
return lessonEndpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>rewritePaths.</p>
|
||||
*
|
||||
|
@ -64,20 +64,6 @@ public class PluginFileUtils {
|
||||
return hasParentDirectoryWithName(p.getParent(), s);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>createDirsIfNotExists.</p>
|
||||
*
|
||||
* @param p a {@link java.nio.file.Path} object.
|
||||
* @return a {@link java.nio.file.Path} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
public static Path createDirsIfNotExists(Path p) throws IOException {
|
||||
if (Files.notExists(p)) {
|
||||
Files.createDirectories(p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>replaceInFiles.</p>
|
||||
*
|
||||
|
@ -44,6 +44,8 @@ public class PluginsLoader {
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final File pluginTargetDirectory;
|
||||
public static PluginClassLoader classLoader = new PluginClassLoader(PluginClassLoader.class.getClassLoader());
|
||||
|
||||
|
||||
@Autowired
|
||||
public PluginsLoader(File pluginTargetDirectory) {
|
||||
@ -153,8 +155,6 @@ public class PluginsLoader {
|
||||
|
||||
private List<Callable<Plugin>> extractJars(List<URL> jars) {
|
||||
List<Callable<Plugin>> extractorCallables = Lists.newArrayList();
|
||||
ClassLoader parentClassLoader = PluginClassLoader.class.getClassLoader();
|
||||
final PluginClassLoader classLoader = new PluginClassLoader(parentClassLoader);
|
||||
|
||||
for (final URL jar : jars) {
|
||||
classLoader.addURL(jar);
|
||||
|
Reference in New Issue
Block a user