Made lesson resolution with Thymeleaf dynamic
This commit is contained in:
parent
4a19ddf40a
commit
22d2255664
@ -1,7 +1,7 @@
|
||||
package org.owasp.webgoat;
|
||||
|
||||
import org.owasp.webgoat.lessons.LessonEndpointMapping;
|
||||
import org.owasp.webgoat.plugins.PluginsLoader;
|
||||
import org.owasp.webgoat.plugins.PluginClassLoader;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
@ -30,23 +30,25 @@ public class LessonEndpointProvider {
|
||||
|
||||
private final String pluginBasePackage;
|
||||
private final ApplicationContext parentContext;
|
||||
private final PluginClassLoader classLoader;
|
||||
private ListableBeanFactory context;
|
||||
private DefaultListableBeanFactory providedBeans;
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
public LessonEndpointProvider(String pluginBasePackage, ApplicationContext parentContext, BeanFactory beanFactory) {
|
||||
public LessonEndpointProvider(String pluginBasePackage, ApplicationContext parentContext, BeanFactory beanFactory, PluginClassLoader cl) {
|
||||
this.pluginBasePackage = pluginBasePackage;
|
||||
this.parentContext = parentContext;
|
||||
this.providedBeans = new DefaultListableBeanFactory(this.parentContext.getParentBeanFactory());
|
||||
this.beanFactory = beanFactory;
|
||||
this.classLoader = cl;
|
||||
}
|
||||
|
||||
public void registerEndpoints() {
|
||||
if (context == null) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.setParent(parentContext);
|
||||
context.setClassLoader(PluginsLoader.classLoader);
|
||||
context.setClassLoader(classLoader);
|
||||
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||
scanner.addIncludeFilter(new AnnotationTypeFilter(LessonEndpointMapping.class));
|
||||
|
@ -33,6 +33,7 @@ public class LessonTemplateResolver extends TemplateResolver {
|
||||
@Override
|
||||
protected String computeResourceName(TemplateProcessingParameters params) {
|
||||
String templateName = params.getTemplateName();
|
||||
|
||||
return templateName.substring(PREFIX.length());
|
||||
}
|
||||
|
||||
@ -46,7 +47,8 @@ public class LessonTemplateResolver extends TemplateResolver {
|
||||
try {
|
||||
return new ByteArrayInputStream(Files.toByteArray(lesson));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//no html yet
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.owasp.webgoat;
|
||||
|
||||
import org.owasp.webgoat.plugins.PluginClassLoader;
|
||||
import org.owasp.webgoat.plugins.PluginsLoader;
|
||||
import org.owasp.webgoat.session.Course;
|
||||
import org.owasp.webgoat.session.WebSession;
|
||||
@ -41,8 +42,13 @@ public class WebGoat extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PluginsLoader pluginsLoader(@Qualifier("pluginTargetDirectory") File pluginTargetDirectory) {
|
||||
return new PluginsLoader(pluginTargetDirectory);
|
||||
public PluginClassLoader pluginClassLoader() {
|
||||
return new PluginClassLoader(PluginClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PluginsLoader pluginsLoader(@Qualifier("pluginTargetDirectory") File pluginTargetDirectory, PluginClassLoader classLoader) {
|
||||
return new PluginsLoader(pluginTargetDirectory, classLoader);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -52,8 +58,8 @@ public class WebGoat extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LessonEndpointProvider lessonEndpointProvider(ApplicationContext applicationContext, BeanFactory factory) {
|
||||
LessonEndpointProvider lessonEndpointProvider = new LessonEndpointProvider("org.owasp.webgoat", applicationContext, factory);
|
||||
public LessonEndpointProvider lessonEndpointProvider(ApplicationContext applicationContext, BeanFactory factory, PluginClassLoader cl) {
|
||||
LessonEndpointProvider lessonEndpointProvider = new LessonEndpointProvider("org.owasp.webgoat", applicationContext, factory, cl);
|
||||
return lessonEndpointProvider;
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ public class Plugin {
|
||||
|
||||
private static final String NAME_LESSON_SOLUTION_DIRECTORY = "lessonSolutions";
|
||||
private static final String NAME_LESSON_PLANS_DIRECTORY = "lessonPlans";
|
||||
public static PluginClassLoader classLoader;
|
||||
|
||||
private PluginClassLoader classLoader;
|
||||
private Class<AbstractLesson> lesson;
|
||||
private Map<String, File> solutionLanguageFiles = new HashMap<>();
|
||||
private Map<String, File> lessonPlansLanguageFiles = new HashMap<>();
|
||||
|
@ -6,7 +6,6 @@ import org.owasp.webgoat.util.LabelProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -37,18 +36,17 @@ import java.util.zip.ZipEntry;
|
||||
* @author dm
|
||||
* @version $Id: $Id
|
||||
*/
|
||||
@Component
|
||||
public class PluginsLoader {
|
||||
|
||||
private static final String WEBGOAT_PLUGIN_EXTENSION = "jar";
|
||||
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());
|
||||
|
||||
private final PluginClassLoader classLoader;
|
||||
|
||||
@Autowired
|
||||
public PluginsLoader(File pluginTargetDirectory) {
|
||||
public PluginsLoader(File pluginTargetDirectory, PluginClassLoader pluginClassLoader) {
|
||||
this.classLoader = pluginClassLoader;
|
||||
this.pluginTargetDirectory = pluginTargetDirectory;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,6 @@
|
||||
<div id="message" class="info" th:utext="${message}"></div>
|
||||
<br/>
|
||||
<div th:utext="${lesson.content}"></div>
|
||||
<div th:replace="lesson:showLesson"></div>
|
||||
<div th:replace="lesson:__${lesson}__"></div>
|
||||
</html>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user