resources = new HashMap<>();
public LessonTemplateResolver(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
- setResolvablePatterns(Sets.newHashSet(PREFIX + "*"));
+ setResolvablePatterns(Set.of(PREFIX + "*"));
}
@Override
@@ -69,7 +69,7 @@ public class LessonTemplateResolver extends FileTemplateResolver {
byte[] resource = resources.get(templateName);
if (resource == null) {
try {
- resource = ByteStreams.toByteArray(resourceLoader.getResource("classpath:/html/" + templateName + ".html").getInputStream());
+ resource = resourceLoader.getResource("classpath:/html/" + templateName + ".html").getInputStream().readAllBytes();
} catch (IOException e) {
e.printStackTrace();
}
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 0e2aac9f6..ea39e3f0b 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
@@ -28,6 +28,7 @@
* @version $Id: $Id
* @since October 28, 2003
*/
+
package org.owasp.webgoat;
import org.owasp.webgoat.i18n.Language;
@@ -122,11 +123,6 @@ public class MvcConfiguration implements WebMvcConfigurer {
return engine;
}
- /**
- * This way we expose the plugins target directory as a resource within the web application.
- *
- * @param registry
- */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/");
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 30ade6d34..7b77b6dee 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
@@ -28,6 +28,7 @@
* @version $Id: $Id
* @since October 28, 2003
*/
+
package org.owasp.webgoat;
import org.owasp.webgoat.session.UserSessionData;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/WebSecurityConfig.java b/webgoat-container/src/main/java/org/owasp/webgoat/WebSecurityConfig.java
index 81de89aa7..79a1b075b 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/WebSecurityConfig.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/WebSecurityConfig.java
@@ -1,4 +1,3 @@
-
/**
* ************************************************************************************************
* This file is part of WebGoat, an Open Web Application Security Project utility. For details,
@@ -28,6 +27,7 @@
* @version $Id: $Id
* @since December 12, 2015
*/
+
package org.owasp.webgoat;
import lombok.AllArgsConstructor;
@@ -38,7 +38,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentEndpoint.java b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentEndpoint.java
index 15b9415c0..1d1cbbb65 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentEndpoint.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentEndpoint.java
@@ -22,6 +22,7 @@
* projects.
*
*/
+
package org.owasp.webgoat.assignments;
import lombok.Getter;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentPath.java b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentPath.java
index 25336aa44..bb7f31a69 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentPath.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AssignmentPath.java
@@ -1,7 +1,5 @@
package org.owasp.webgoat.assignments;
-import org.springframework.core.annotation.AliasFor;
-import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.annotation.ElementType;
@@ -14,15 +12,11 @@ import java.lang.annotation.Target;
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
-//@RequestMapping
public @interface AssignmentPath {
- // @AliasFor(annotation = RequestMapping.class)
String[] path() default {};
- // @AliasFor(annotation = RequestMapping.class)
RequestMethod[] method() default {};
- // @AliasFor("path")
String value() default "";
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AttackResult.java b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AttackResult.java
index 573f488a1..e78d46338 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AttackResult.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/assignments/AttackResult.java
@@ -25,7 +25,6 @@
package org.owasp.webgoat.assignments;
-import com.google.common.base.Strings;
import lombok.Getter;
import org.apache.commons.lang3.StringEscapeUtils;
import org.owasp.webgoat.i18n.PluginMessages;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
index 06efc9c0f..69e63c578 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
@@ -28,6 +28,7 @@
* @version $Id: $Id
* @since October 28, 2003
*/
+
package org.owasp.webgoat.controller;
import org.owasp.webgoat.lessons.Lesson;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
index 44fe432de..af80e2c82 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
@@ -28,6 +28,7 @@
* @since October 28, 2003
* @version $Id: $Id
*/
+
package org.owasp.webgoat.controller;
import org.springframework.stereotype.Controller;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/i18n/Messages.java b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/Messages.java
index 4f3312ddf..e7758c43c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/i18n/Messages.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/Messages.java
@@ -22,6 +22,7 @@
* projects.
*
*/
+
package org.owasp.webgoat.i18n;
import lombok.AllArgsConstructor;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/i18n/PluginMessages.java b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/PluginMessages.java
index 163909724..a2a046bf3 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/i18n/PluginMessages.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/PluginMessages.java
@@ -25,9 +25,10 @@
package org.owasp.webgoat.i18n;
-import lombok.SneakyThrows;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
@@ -50,18 +51,23 @@ public class PluginMessages extends ReloadableResourceBundleMessageSource {
}
@Override
- @SneakyThrows
protected PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder) {
Properties properties = new Properties();
long lastModified = System.currentTimeMillis();
- Enumeration resources = Thread.currentThread().getContextClassLoader().getResources(filename + PROPERTIES_SUFFIX);
- while (resources.hasMoreElements()) {
- URL resource = resources.nextElement();
- String sourcePath = resource.toURI().toString().replace(PROPERTIES_SUFFIX, "");
- PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder);
- properties.putAll(holder.getProperties());
+ Enumeration resources = null;
+ try {
+ resources = Thread.currentThread().getContextClassLoader().getResources(filename + PROPERTIES_SUFFIX);
+ while (resources.hasMoreElements()) {
+ URL resource = resources.nextElement();
+ String sourcePath = resource.toURI().toString().replace(PROPERTIES_SUFFIX, "");
+ PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder);
+ properties.putAll(holder.getProperties());
+ }
+ } catch (IOException | URISyntaxException e) {
+ logger.error("Unable to read plugin message", e);
}
+
return new PropertiesHolder(properties, lastModified);
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Assignment.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Assignment.java
index 91d6b1937..f4e8aaa31 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Assignment.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Assignment.java
@@ -1,9 +1,9 @@
package org.owasp.webgoat.lessons;
-import com.google.common.collect.Lists;
import lombok.*;
import javax.persistence.*;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -45,7 +45,7 @@ public class Assignment {
private Long id;
private String name;
private String path;
-
+
@Transient
private List hints;
@@ -54,7 +54,7 @@ public class Assignment {
}
public Assignment(String name) {
- this(name, name, Lists.newArrayList());
+ this(name, name, new ArrayList<>());
}
public Assignment(String name, String path, List hints) {
@@ -65,14 +65,15 @@ public class Assignment {
this.path = path;
this.hints = hints;
}
-
+
/**
* Set path is here to overwrite stored paths.
* Since a stored path can no longer be used in a lesson while
* the lesson (name) itself is still part of the lesson.
- * @param pathName
+ *
+ * @param pathName the path
*/
public void setPath(String pathName) {
- this.path = pathName;
+ this.path = pathName;
}
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Hint.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Hint.java
index f2a1fa4b0..6b45b4d1d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Hint.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Hint.java
@@ -24,6 +24,7 @@
* projects.
*
*/
+
package org.owasp.webgoat.lessons;
import lombok.Value;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonMenuItem.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonMenuItem.java
index 41c45a682..8aca79fcc 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonMenuItem.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonMenuItem.java
@@ -1,32 +1,32 @@
/**
* *************************************************************************************************
- *
- *
+ *
+ *
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
- *
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
* Getting Source ==============
- *
+ *
* Source for this application is maintained at
* https://github.com/WebGoat/WebGoat, a repository for free software projects.
- *
*/
+
package org.owasp.webgoat.lessons;
import java.util.ArrayList;
@@ -46,8 +46,6 @@ public class LessonMenuItem {
private boolean complete;
private String link;
private int ranking;
-// private boolean showSource = true;
-// private boolean showHints = true;
/**
*
Getter for the field name
.
@@ -112,7 +110,6 @@ public class LessonMenuItem {
children.add(child);
}
- /** {@inheritDoc} */
@Override
public String toString() {
StringBuilder bldr = new StringBuilder();
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RequestParameter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RequestParameter.java
index 5d2716920..81c548fdf 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RequestParameter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RequestParameter.java
@@ -27,6 +27,7 @@
* for free software projects.
*
*/
+
package org.owasp.webgoat.lessons;
/**
@@ -69,7 +70,6 @@ public class RequestParameter implements Comparable {
return value;
}
- /** {@inheritDoc} */
@Override
public int compareTo(RequestParameter o) {
return this.name.compareTo(o.getName());
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/CourseConfiguration.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/CourseConfiguration.java
index 36bdf1305..cb7269c04 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/CourseConfiguration.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/CourseConfiguration.java
@@ -19,9 +19,9 @@
*
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software projects.
*/
+
package org.owasp.webgoat.plugins;
-import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.owasp.webgoat.assignments.AssignmentEndpoint;
@@ -39,9 +39,7 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
@@ -70,7 +68,7 @@ public class CourseConfiguration {
var endpoints = assignmentsByPackage.get(lesson.getClass().getPackageName());
if (CollectionUtils.isEmpty(endpoints)) {
log.warn("Lesson: {} has no endpoints, is this intentionally?", lesson.getTitle());
- return Lists.newArrayList();
+ return new ArrayList();
}
return endpoints.stream().map(e -> new Assignment(e.getClass().getSimpleName(), getPath(e.getClass()), getHints(e.getClass()))).collect(toList());
}
@@ -110,8 +108,8 @@ public class CourseConfiguration {
private List getHints(Class extends AssignmentEndpoint> e) {
if (e.isAnnotationPresent(AssignmentHints.class)) {
- return Lists.newArrayList(e.getAnnotationsByType(AssignmentHints.class)[0].value());
+ return List.of(e.getAnnotationsByType(AssignmentHints.class)[0].value());
}
- return Lists.newArrayList();
+ return Collections.emptyList();
}
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
deleted file mode 100644
index fd9f55ae0..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- */
-package org.owasp.webgoat.service;
-
-import com.google.common.collect.Lists;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpSession;
-import java.util.List;
-
-/**
- * CookieService class.
- *
- * @author rlawson
- * @version $Id: $Id
- */
-@Controller
-public class CookieService {
-
- /**
- * Returns cookies for last attack
- *
- * @param session a {@link javax.servlet.http.HttpSession} object.
- * @return a {@link java.util.List} object.
- */
- @RequestMapping(path = "/service/cookie.mvc", produces = "application/json")
- public @ResponseBody
- List showCookies() {
- //// TODO: 11/6/2016 to be decided
- List cookies = Lists.newArrayList();
- return cookies;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
index b0743f865..43dd88c57 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
@@ -3,6 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
+
package org.owasp.webgoat.service;
import org.owasp.webgoat.lessons.Assignment;
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 b32832a88..d009e889c 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
@@ -1,32 +1,32 @@
/**
* *************************************************************************************************
- *
- *
+ *
+ *
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
- *
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
* Getting Source ==============
- *
+ *
* Source for this application is maintained at
* https://github.com/WebGoat/WebGoat, a repository for free software projects.
- *
*/
+
package org.owasp.webgoat.service;
import lombok.AllArgsConstructor;
@@ -73,20 +73,20 @@ public class LabelDebugService {
return new ResponseEntity<>(result, HttpStatus.OK);
}
- /**
- * Sets the enabled flag on the label debugger to the given parameter
- * @param enabled {@link org.owasp.webgoat.session.LabelDebugger} object
- * @throws Exception unhandled exception
- * @return a {@link org.springframework.http.ResponseEntity} object.
- */
- @RequestMapping(value = URL_DEBUG_LABELS_MVC, produces = MediaType.APPLICATION_JSON_VALUE, params = KEY_ENABLED)
- public @ResponseBody
- ResponseEntity