diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/LabelDebugService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/LabelDebugService.java index d73f7e274..c00fc20f9 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/service/LabelDebugService.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/LabelDebugService.java @@ -29,18 +29,23 @@ */ package org.owasp.webgoat.service; +import java.util.HashMap; +import java.util.Map; + import org.owasp.webgoat.session.LabelDebugger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; /** - *

PluginReloadService class.

+ *

LabelDebugService class.

* * @author nbaars * @version $Id: $Id @@ -48,21 +53,52 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller public class LabelDebugService extends BaseService { + private static final String URL_DEBUG_LABELS_MVC = "/debug/labels.mvc"; + private static final String KEY_ENABLED = "enabled"; + private static final String KEY_SUCCESS = "success"; + private static final Logger logger = LoggerFactory.getLogger(LabelDebugService.class); @Autowired private LabelDebugger labelDebugger; + /** - * Reload all the plugins + * Checks if debugging of labels is enabled or disabled * * @return a {@link org.springframework.http.ResponseEntity} object. */ - @RequestMapping(value = "/debug/labels.mvc") + @RequestMapping(value = URL_DEBUG_LABELS_MVC, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - //todo parse params to add enable / disable - ResponseEntity reloadPlugins() { - labelDebugger.enable(); - return new ResponseEntity("Label debugger enabled refresh the WebGoat page!",HttpStatus.OK); + ResponseEntity> checkDebuggingStatus() { + logger.debug("Checking label debugging, it is " + labelDebugger.isEnabled()); // FIXME parameterize + Map result = createResponse(labelDebugger.isEnabled()); + return new ResponseEntity>(result, HttpStatus.OK); + } + + /** + * Sets the enabled flag on the label debugger to the given parameter + * + * @return a {@link org.springframework.http.ResponseEntity} object. + * @throws Exception + */ + @RequestMapping(value = URL_DEBUG_LABELS_MVC, produces = MediaType.APPLICATION_JSON_VALUE, params = KEY_ENABLED) + public @ResponseBody + ResponseEntity> setDebuggingStatus(@RequestParam("enabled") Boolean enabled) throws Exception { + logger.debug("Setting label debugging to " + labelDebugger.isEnabled()); // FIXME parameterize + Map result = createResponse(enabled); + labelDebugger.setEnabled(enabled); + return new ResponseEntity>(result, HttpStatus.OK); + } + + /** + * @param enabled + * @return a {@link java.util.Map} object. + */ + private Map createResponse(Boolean enabled) { + Map result = new HashMap(); + result.put(KEY_SUCCESS, Boolean.TRUE); + result.put(KEY_ENABLED, enabled); + return result; } } diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/PluginReloadService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/PluginReloadService.java index 64e8fc50e..6355318aa 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/service/PluginReloadService.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/PluginReloadService.java @@ -29,19 +29,23 @@ */ package org.owasp.webgoat.service; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + import org.owasp.webgoat.plugins.PluginsLoader; import org.owasp.webgoat.session.WebSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; -import javax.servlet.http.HttpSession; -import java.nio.file.Paths; - /** *

PluginReloadService class.

* @@ -59,16 +63,20 @@ public class PluginReloadService extends BaseService { * @param session a {@link javax.servlet.http.HttpSession} object. * @return a {@link org.springframework.http.ResponseEntity} object. */ - @RequestMapping(value = "/reloadplugins.mvc") + @RequestMapping(value = "/reloadplugins.mvc", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - ResponseEntity reloadPlugins(HttpSession session) { + ResponseEntity> reloadPlugins(HttpSession session) { WebSession webSession = (WebSession) session.getAttribute(WebSession.SESSION); + logger.debug("Loading plugins into cache"); String pluginPath = session.getServletContext().getRealPath("plugin_lessons"); String targetPath = session.getServletContext().getRealPath("plugin_extracted"); new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).copyJars(); - webSession.getCourse().loadLessonFromPlugin(session.getServletContext()); - return new ResponseEntity("Plugins reload refresh the WebGoat page!",HttpStatus.OK); + + Map result = new HashMap(); + result.put("success", true); + result.put("message", "Plugins reloaded"); + return new ResponseEntity>(result, HttpStatus.OK); } } diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/LabelDebugger.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/LabelDebugger.java index 0e199755b..23470dfc8 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/session/LabelDebugger.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/LabelDebugger.java @@ -10,7 +10,7 @@ import java.io.Serializable; */ public class LabelDebugger implements Serializable { - private boolean isEnabled = false; + private boolean enabled = false; /** *

isEnabled.

@@ -18,14 +18,31 @@ public class LabelDebugger implements Serializable { * @return a boolean. */ public boolean isEnabled() { - return isEnabled; + return enabled; } /** - *

enable.

+ *

Enables label debugging

*/ public void enable() { - this.isEnabled = true; + this.enabled = true; + } + + /** + *

Disables label debugging

+ */ + public void disable() { + this.enabled = false; + } + + /** + *

Sets the status to enabled

+ * @param enabled + * @throws Exception if enabled is null + */ + public void setEnabled(Boolean enabled) throws Exception { + if(enabled == null) throw new Exception("Cannot set enabled to null"); + this.enabled = enabled; } } diff --git a/webgoat-container/src/main/webapp/WEB-INF/pages/main_new.jsp b/webgoat-container/src/main/webapp/WEB-INF/pages/main_new.jsp index 356706e1b..e9416e270 100644 --- a/webgoat-container/src/main/webapp/WEB-INF/pages/main_new.jsp +++ b/webgoat-container/src/main/webapp/WEB-INF/pages/main_new.jsp @@ -71,10 +71,10 @@ - + +
  • Show developer controls
  • - - +