diff --git a/webgoat-container/pom.xml b/webgoat-container/pom.xml
index 9446836d5..6546faf64 100644
--- a/webgoat-container/pom.xml
+++ b/webgoat-container/pom.xml
@@ -1,5 +1,6 @@
-
+webgoat-container4.0.0
@@ -112,6 +113,41 @@
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ ${maven-jar-plugin.version}
+
+
+ create-jar
+ compile
+
+ jar
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ ${build-helper-maven-plugin.version}
+
+
+ attach-artifacts
+ package
+
+ attach-artifact
+
+
+
+
+ ${project.build.directory}/webgoat-container-${project.version}.jar
+
+
+
+
+
+ org.apache.maven.pluginsmaven-resources-plugin
@@ -133,20 +169,6 @@
ISO-8859-1
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${maven-jar-plugin.version}
-
-
- create-jar
- compile
-
- jar
-
-
-
- org.apache.maven.pluginsmaven-surefire-plugin
@@ -160,6 +182,21 @@
org.springframework.bootspring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+ org.thymeleaf.extra
+ thymeleaf-extras-springsecurity4
+
+
+
+
+
@@ -184,10 +221,14 @@
true
-
-
-
+
+
+
+
+ org.springframework.boot
+ spring-boot-loader
+ javax.servletjstl
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
index 144899c78..e8f2cb828 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
@@ -8,10 +8,8 @@ import org.owasp.webgoat.session.ErrorScreen;
import org.owasp.webgoat.session.Screen;
import org.owasp.webgoat.session.UserTracker;
import org.owasp.webgoat.session.WebSession;
-import org.owasp.webgoat.session.WebgoatContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -62,42 +60,18 @@ import java.util.TimeZone;
*/
public class HammerHead extends HttpServlet {
- final Logger logger = LoggerFactory.getLogger(HammerHead.class);
-
-
- /**
- *
- */
private static final long serialVersionUID = 645640331343188020L;
+ private static SimpleDateFormat httpDateFormat;
+ private final Logger logger = LoggerFactory.getLogger(HammerHead.class);
+ private WebSession webSession;
- /**
- * Description of the Field
- */
- protected static SimpleDateFormat httpDateFormat;
-
- /**
- * Set the session timeout to be 2 days
- */
- private final static int sessionTimeoutSeconds = 60 * 60 * 24 * 2;
-
- // private final static int sessionTimeoutSeconds = 1;
- /**
- * Properties file path
- */
- public static String propertiesPath = null;
-
- /**
- * provides convenience methods for getting setup information from the
- * ServletContext
- */
- private WebgoatContext webgoatContext = null;
-
- public HammerHead(WebgoatContext context) {
- this.webgoatContext = context;
+ public HammerHead() {
+ //for catcher subclass
}
- //TODO_NB
- public HammerHead() {}
+ public HammerHead(WebSession webSession) {
+ this.webSession = webSession;
+ }
/**
* {@inheritDoc}
@@ -250,7 +224,6 @@ public class HammerHead extends HttpServlet {
logger.info("Initializing main webgoat servlet");
httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyyy HH:mm:ss z", Locale.US);
httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- propertiesPath = new ClassPathResource("/WEB-INF/webgoat.properties").getPath();
}
/**
@@ -348,25 +321,6 @@ public class HammerHead extends HttpServlet {
return (screen);
}
- /**
- * This method sets the required expiration headers in the response for a
- * given RunData object. This method attempts to set all relevant headers,
- * both for HTTP 1.0 and HTTP 1.1.
- *
- * @param response The new cacheHeaders value
- * @param expiry The new cacheHeaders value
- */
- protected static void setCacheHeaders(HttpServletResponse response, int expiry) {
- if (expiry == 0) {
- response.setHeader("Pragma", "no-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setHeader("Expires", formatHttpDate(new Date()));
- } else {
- Date expiryDate = new Date(System.currentTimeMillis() + expiry);
- response.setHeader("Expires", formatHttpDate(expiryDate));
- }
- }
-
/**
* Description of the Method
*
@@ -382,10 +336,11 @@ public class HammerHead extends HttpServlet {
// session should already be created by spring security
hs = request.getSession(false);
+ //TODO rewrite this logic
logger.debug("HH Entering Session_id: " + hs.getId());
// dumpSession( hs );
// Get our session object out of the HTTP session
- WebSession session = null;
+ WebSession session = this.webSession;
Object o = hs.getAttribute(WebSession.SESSION);
if ((o != null) && o instanceof WebSession) {
@@ -394,13 +349,11 @@ public class HammerHead extends HttpServlet {
} else {
// Create new custom session and save it in the HTTP session
logger.warn("HH Creating new WebSession");
- session = new WebSession(webgoatContext, context);
// Ensure splash screen shows on any restart
// rlawson - removed this since we show splash screen at login now
//hs.removeAttribute(WELCOMED);
+ //@TODO NO NEED TO PUT IN THE HTTP SESSION, FOCUS WILL FIX LATER
hs.setAttribute(WebSession.SESSION, session);
- // reset timeout
- hs.setMaxInactiveInterval(sessionTimeoutSeconds);
}
session.update(request, response, this.getServletName());
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java b/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
index 1075e6c3d..208e900ba 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
@@ -1,18 +1,17 @@
package org.owasp.webgoat;
import org.owasp.webgoat.session.LabelDebugger;
-import org.owasp.webgoat.session.WebgoatContext;
+import org.owasp.webgoat.session.WebSession;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.io.File;
-import java.io.IOException;
/**
*
@@ -20,10 +19,15 @@ import java.io.IOException;
@Configuration
public class MvcConfiguration extends WebMvcConfigurerAdapter {
+ @Autowired
+ @Qualifier("pluginTargetDirectory")
+ private File pluginTargetDirectory;
+
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
registry.addViewController("/lesson_content").setViewName("lesson_content");
+ registry.addViewController("/start.mvc").setViewName("main_new");
}
@Bean
@@ -33,23 +37,15 @@ public class MvcConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- Resource resource = new ClassPathResource("/plugin_lessons/plugin_lessons_marker.txt");
- try {
- File pluginsDir = resource.getFile().getParentFile();
- registry.addResourceHandler("/plugin_lessons/**").addResourceLocations("file:///" + pluginsDir.toString() + "/");
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+ registry.addResourceHandler("/plugin_lessons/**").addResourceLocations("file:///" + pluginTargetDirectory.toString() + "/");
}
@Bean
- public HammerHead hammerHead(WebgoatContext context) {
- return new HammerHead(context);
+ public HammerHead hammerHead(WebSession webSession) {
+ return new HammerHead(webSession);
}
@Bean
- //@Scope(value= WebApplicationContext.SCOPE_SESSION)
public LabelDebugger labelDebugger() {
return new LabelDebugger();
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java b/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
index 013f464a2..615cc4122 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
@@ -1,11 +1,25 @@
package org.owasp.webgoat;
+import org.owasp.webgoat.plugins.PluginsLoader;
+import org.owasp.webgoat.session.Course;
+import org.owasp.webgoat.session.WebSession;
+import org.owasp.webgoat.session.WebgoatContext;
+import org.owasp.webgoat.session.WebgoatProperties;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
+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 javax.servlet.ServletContext;
+import java.io.File;
@SpringBootApplication
+@PropertySource("classpath:/webgoat.properties")
public class WebGoat extends SpringBootServletInitializer {
@Override
@@ -17,28 +31,31 @@ public class WebGoat extends SpringBootServletInitializer {
SpringApplication.run(WebGoat.class, args);
}
-// @Bean
-// @Autowired
-// public TomcatEmbeddedServletContainerFactory servletContainer(final JarScanner jarScanner) {
-// TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
-// factory.setPort(80);
-// factory.setSessionTimeout(10, TimeUnit.MINUTES);
-// factory.addContextCustomizers(new TomcatContextCustomizer() {
-// @Override
-// public void customize(Context context) {
-//
-// context.setJarScanner(jarScanner);
-// }
-// });
-// return factory;
-// }
-//
-// @Bean
-// public JarScanner getJarScanner() {
-// StandardJarScanner jarScanner = new StandardJarScanner();
-// jarScanner.setScanClassPath(true);
-// return jarScanner;
-// }
+ @Bean(name = "pluginTargetDirectory")
+ public File pluginTargetDirectory() {
+ File tempDir = com.google.common.io.Files.createTempDir();
+ tempDir.deleteOnExit();
+ return tempDir;
+ }
+ @Bean
+ public PluginsLoader pluginsLoader(@Qualifier("pluginTargetDirectory") File pluginTargetDirectory) {
+ System.out.println("Plugin target directory: " + pluginTargetDirectory.toString());
+ return new PluginsLoader(pluginTargetDirectory);
+ }
+ @Bean
+ @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
+ public WebSession webSession(Course course, WebgoatContext webgoatContext, ServletContext context) {
+ return new WebSession(course, webgoatContext, context);
+ }
+
+ @Bean
+ public Course course(PluginsLoader pluginsLoader, WebgoatContext webgoatContext, ServletContext context,
+ WebgoatProperties webgoatProperties) {
+ Course course = new Course(webgoatProperties);
+ course.loadCourses(webgoatContext, context, "/");
+ course.loadLessonFromPlugin(pluginsLoader.loadPlugins());
+ return course;
+ }
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java b/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java
deleted file mode 100644
index b9667b0c8..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.owasp.webgoat.application;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-
-/**
- * Singleton which is created on context startup
- *
- * @author rlawson
- * @version $Id: $Id
- */
-//TODO_NB still necessary?
-public class Application {
-
- private static final Application INSTANCE = new Application();
-
- private Application() {
-
- }
-
- /**
- *
getInstance.
- *
- * @return a {@link org.owasp.webgoat.application.Application} object.
- */
- public static final Application getInstance() {
- return INSTANCE;
- }
-
- private String version = "SNAPSHOT";
- private String build = "local";
- private String name = "WebGoat";
-
- /**
- *
Getter for the field version.
- *
- * @return the version
- */
- public String getVersion() {
- return version;
- }
-
- /**
- *
Setter for the field version.
- *
- * @param version the version to set
- */
- public void setVersion(String version) {
- if (StringUtils.isNotBlank(version)) {
- this.version = version;
- }
- }
-
- /**
- *
- *
- * @param propertiesFileName a {@link java.lang.String} object.
- * @throws java.io.IOException if any.
- */
- public WebgoatProperties(String propertiesFileName) throws IOException {
- if (propertiesFileName == null) {
- throw new IOException("Path to webgoat.properties is null, initialization must have failed");
- }
-
-// File propertiesFile = new File(propertiesFileName);
-// if (propertiesFile.exists() == false) {
-// throw new IOException("Unable to locate webgoat.properties at: " + propertiesFileName);
-// }
- Resource resource = new ClassPathResource("/webgoat.properties");
- //FileInputStream in = new FileInputStream(propertiesFile);
- load(resource.getInputStream());
- }
/**
*
getIntProperty.
@@ -77,7 +60,7 @@ public class WebgoatProperties extends Properties {
public int getIntProperty(String key, int defaultValue) {
int value = defaultValue;
- String s = getProperty(key);
+ String s = env.getProperty(key);
if (s != null) {
value = Integer.parseInt(s);
}
@@ -96,7 +79,7 @@ public class WebgoatProperties extends Properties {
boolean value = defaultValue;
key = this.trimLesson(key);
- String s = getProperty(key);
+ String s = env.getProperty(key);
if (s != null) {
if (s.equalsIgnoreCase("true")) {
value = true;
@@ -127,21 +110,4 @@ public class WebgoatProperties extends Properties {
return result;
}
-
- /**
- *