No more yml(2)
This commit is contained in:
@ -30,6 +30,7 @@
|
||||
*/
|
||||
package org.owasp.webgoat;
|
||||
|
||||
import org.owasp.webgoat.plugins.Plugin;
|
||||
import org.owasp.webgoat.plugins.PluginClassLoader;
|
||||
import org.owasp.webgoat.plugins.PluginsLoader;
|
||||
import org.owasp.webgoat.session.Course;
|
||||
@ -37,8 +38,11 @@ import org.owasp.webgoat.session.UserTracker;
|
||||
import org.owasp.webgoat.session.WebSession;
|
||||
import org.owasp.webgoat.session.WebgoatContext;
|
||||
import org.owasp.webgoat.session.WebgoatProperties;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@ -48,9 +52,11 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.annotation.ScopedProxyMode;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("classpath:/webgoat.properties")
|
||||
@ -88,22 +94,29 @@ public class WebGoat extends SpringBootServletInitializer {
|
||||
return new WebSession(course, webgoatContext, context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LessonEndpointProvider lessonEndpointProvider(ApplicationContext applicationContext, BeanFactory factory, PluginClassLoader cl) {
|
||||
LessonEndpointProvider lessonEndpointProvider = new LessonEndpointProvider("org.owasp.webgoat", applicationContext, factory, cl);
|
||||
return lessonEndpointProvider;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Course course(PluginsLoader pluginsLoader, WebgoatContext webgoatContext, ServletContext context, WebgoatProperties webgoatProperties,
|
||||
LessonEndpointProvider endpointProvider) {
|
||||
ApplicationContext applicationContext) {
|
||||
Course course = new Course(webgoatProperties);
|
||||
course.loadCourses(webgoatContext, context, "/");
|
||||
course.loadLessonFromPlugin(pluginsLoader.loadPlugins());
|
||||
endpointProvider.registerEndpoints();
|
||||
List<Plugin> plugins = pluginsLoader.loadPlugins();
|
||||
course.loadLessonFromPlugin(plugins);
|
||||
plugins.forEach(p -> publishEndpointsWithSpring(p, (AbstractApplicationContext)applicationContext));
|
||||
return course;
|
||||
}
|
||||
|
||||
private void publishEndpointsWithSpring(Plugin plugin, AbstractApplicationContext applicationContext) {
|
||||
plugin.getLessonEndpoints().forEach(e -> {
|
||||
try {
|
||||
BeanDefinition beanDefinition = new RootBeanDefinition(e, Autowire.BY_TYPE.value(), true);
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext.getBeanFactory();
|
||||
beanFactory.registerBeanDefinition(beanDefinition.getBeanClassName(), beanDefinition);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Failed to register " + e.getSimpleName() + " as endpoint with Spring, skipping...");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserTracker userTracker() {
|
||||
UserTracker userTracker = UserTracker.instance();
|
||||
|
Reference in New Issue
Block a user