Merge pull request #36 from WebGoat/legacy-loader
WEB-183 Loading of Admin screens Nanne +1'd
This commit is contained in:
commit
4c30957a2d
4
pom.xml
4
pom.xml
@ -48,7 +48,9 @@
|
|||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<archiveClasses>true</archiveClasses>
|
<!-- archiving the classes breaks the admin screen loads in course.java
|
||||||
|
the legacy lesson loader does not look in jar files for lessons -->
|
||||||
|
<archiveClasses>false</archiveClasses>
|
||||||
<manifest>
|
<manifest>
|
||||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
259
src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java
Normal file
259
src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
package org.owasp.webgoat.plugins;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.owasp.webgoat.HammerHead;
|
||||||
|
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||||
|
import org.owasp.webgoat.session.WebgoatContext;
|
||||||
|
import org.owasp.webgoat.session.WebgoatProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *************************************************************************************************
|
||||||
|
* <p/>
|
||||||
|
* <p/>
|
||||||
|
* This file is part of WebGoat, an Open Web Application Security Project
|
||||||
|
* utility. For details, please see http://www.owasp.org/
|
||||||
|
* <p/>
|
||||||
|
* Copyright (c) 2002 - 20014 Bruce Mayhew
|
||||||
|
* <p/>
|
||||||
|
* 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.
|
||||||
|
* <p/>
|
||||||
|
* 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.
|
||||||
|
* <p/>
|
||||||
|
* 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.
|
||||||
|
* <p/>
|
||||||
|
* Getting Source ==============
|
||||||
|
* <p/>
|
||||||
|
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
|
||||||
|
* for free software projects.
|
||||||
|
* <p/>
|
||||||
|
* For details, please see http://webgoat.github.io
|
||||||
|
*
|
||||||
|
* @author Bruce Mayhew <a href="http://code.google.com/p/webgoat">WebGoat</a>
|
||||||
|
* @created October 28, 2003
|
||||||
|
*/
|
||||||
|
public class LegacyLoader {
|
||||||
|
|
||||||
|
final Logger logger = LoggerFactory.getLogger(LegacyLoader.class);
|
||||||
|
|
||||||
|
private final List<String> files = new LinkedList<String>();
|
||||||
|
|
||||||
|
public LegacyLoader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take an absolute file and return the filename.
|
||||||
|
* <p/>
|
||||||
|
* Ex. /etc/password becomes password
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @return the file name
|
||||||
|
*/
|
||||||
|
private static String getFileName(String s) {
|
||||||
|
String fileName = new File(s).getName();
|
||||||
|
|
||||||
|
if (fileName.contains("/")) {
|
||||||
|
fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileName.contains(".")) {
|
||||||
|
fileName = fileName.substring(0, fileName.indexOf("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take a class name and return the equivalent file name
|
||||||
|
* <p/>
|
||||||
|
* Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
|
||||||
|
*
|
||||||
|
* @param className
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getSourceFile(String className) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append(className.replace(".", "/"));
|
||||||
|
sb.append(".java");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a file name and builds the class file name
|
||||||
|
*
|
||||||
|
* @param fileName Description of the Parameter
|
||||||
|
* @param path Description of the Parameter
|
||||||
|
* @return Description of the Return Value
|
||||||
|
*/
|
||||||
|
private static String getClassFile(String fileName, String path) {
|
||||||
|
String ext = ".class";
|
||||||
|
fileName = fileName.trim();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We do not handle directories. We do not handle files with different
|
||||||
|
* extensions
|
||||||
|
*/
|
||||||
|
if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip over plugins and/or extracted plugins
|
||||||
|
if ( fileName.indexOf("lessons/plugin") >= 0 || fileName.indexOf("plugin_extracted") >= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the file is in /WEB-INF/classes strip the dir info off
|
||||||
|
int index = fileName.indexOf("/WEB-INF/classes/");
|
||||||
|
if (index != -1) {
|
||||||
|
fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
|
||||||
|
fileName = fileName.replace('/', '.');
|
||||||
|
fileName = fileName.replace('\\', '.');
|
||||||
|
} else {
|
||||||
|
// Strip off the leading path info
|
||||||
|
fileName = fileName.substring(path.length(), fileName.length() - ext.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all of the filenames into a temporary cache
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
public void loadFiles(ServletContext context, String path) {
|
||||||
|
logger.debug("Loading files into cache, path: " + path);
|
||||||
|
Set resourcePaths = context.getResourcePaths(path);
|
||||||
|
if (resourcePaths == null) {
|
||||||
|
logger.error("Unable to load file cache for courses, this is probably a bug or configuration issue");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Iterator itr = resourcePaths.iterator();
|
||||||
|
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
String file = (String) itr.next();
|
||||||
|
|
||||||
|
if (file.length() != 1 && file.endsWith("/")) {
|
||||||
|
loadFiles(context, file);
|
||||||
|
} else {
|
||||||
|
files.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate all the lesson objects into a cache
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public List<AbstractLesson> loadLessons(WebgoatContext webgoatContext, ServletContext context, String path, WebgoatProperties properties ) {
|
||||||
|
|
||||||
|
loadFiles(context, path);
|
||||||
|
|
||||||
|
List<AbstractLesson> lessons = new LinkedList<AbstractLesson>();
|
||||||
|
|
||||||
|
for (String file : files) {
|
||||||
|
String className = getClassFile(file, path);
|
||||||
|
|
||||||
|
if (className != null && !className.endsWith("_i")) {
|
||||||
|
try {
|
||||||
|
Class c = Class.forName(className);
|
||||||
|
Object o = c.newInstance();
|
||||||
|
|
||||||
|
if (o instanceof AbstractLesson) {
|
||||||
|
AbstractLesson lesson = (AbstractLesson) o;
|
||||||
|
lesson.setWebgoatContext(webgoatContext);
|
||||||
|
|
||||||
|
lesson.update(properties);
|
||||||
|
|
||||||
|
if (lesson.getHidden() == false) {
|
||||||
|
lessons.add(lesson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Bruce says:
|
||||||
|
// I don't think we want to log the exception here. We could
|
||||||
|
// be potentially showing a lot of exceptions that don't matter.
|
||||||
|
// We would only care if the lesson extended AbstractLesson and we
|
||||||
|
// can't tell that because it threw the exception. Catch 22
|
||||||
|
// logger.error("Error in loadLessons: ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadResources(lessons);
|
||||||
|
return lessons;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLanguageFromFileName(String first, String absoluteFile) {
|
||||||
|
int p1 = absoluteFile.indexOf("/", absoluteFile.indexOf(first) + 1);
|
||||||
|
int p2 = absoluteFile.indexOf("/", p1 + 1);
|
||||||
|
String langStr = absoluteFile.substring(p1 + 1, p2);
|
||||||
|
|
||||||
|
return langStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each lesson, set the source file and lesson file
|
||||||
|
* @param lessons
|
||||||
|
*/
|
||||||
|
public void loadResources(List<AbstractLesson> lessons ) {
|
||||||
|
for (AbstractLesson lesson : lessons) {
|
||||||
|
logger.info("Loading resources for lesson -> " + lesson.getName());
|
||||||
|
String className = lesson.getClass().getName();
|
||||||
|
String classFile = getSourceFile(className);
|
||||||
|
logger.info("Lesson classname: " + className);
|
||||||
|
logger.info("Lesson java file: " + classFile);
|
||||||
|
|
||||||
|
for (String absoluteFile : files) {
|
||||||
|
String fileName = getFileName(absoluteFile);
|
||||||
|
//logger.debug("Course: looking at file: " + absoluteFile);
|
||||||
|
|
||||||
|
if (absoluteFile.endsWith(classFile)) {
|
||||||
|
logger.info("Set source file for " + classFile);
|
||||||
|
lesson.setSourceFileName(absoluteFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (absoluteFile.startsWith("/lesson_plans") && absoluteFile.endsWith(".html")
|
||||||
|
&& className.endsWith(fileName)) {
|
||||||
|
logger.info("setting lesson plan file " + absoluteFile + " for lesson "
|
||||||
|
+ lesson.getClass().getName());
|
||||||
|
logger.info("fileName: " + fileName + " == className: " + className);
|
||||||
|
String language = getLanguageFromFileName("/lesson_plans", absoluteFile);
|
||||||
|
lesson.setLessonPlanFileName(language, absoluteFile);
|
||||||
|
}
|
||||||
|
if (absoluteFile.startsWith("/lesson_solutions") && absoluteFile.endsWith(".html")
|
||||||
|
&& className.endsWith(fileName)) {
|
||||||
|
logger.info("setting lesson solution file " + absoluteFile + " for lesson "
|
||||||
|
+ lesson.getClass().getName());
|
||||||
|
logger.info("fileName: " + fileName + " == className: " + className);
|
||||||
|
lesson.setLessonSolutionFileName(absoluteFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,335 +1,333 @@
|
|||||||
package org.owasp.webgoat.session;
|
package org.owasp.webgoat.session;
|
||||||
|
|
||||||
import org.owasp.webgoat.HammerHead;
|
import java.io.File;
|
||||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
import java.io.IOException;
|
||||||
import org.owasp.webgoat.lessons.Category;
|
import java.nio.file.Paths;
|
||||||
import org.owasp.webgoat.plugins.GlobalProperties;
|
import java.util.ArrayList;
|
||||||
import org.owasp.webgoat.plugins.Plugin;
|
import java.util.Collections;
|
||||||
import org.owasp.webgoat.plugins.PluginFileUtils;
|
import java.util.Iterator;
|
||||||
import org.owasp.webgoat.plugins.PluginsLoader;
|
import java.util.LinkedList;
|
||||||
import org.slf4j.Logger;
|
import java.util.List;
|
||||||
import org.slf4j.LoggerFactory;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import java.io.File;
|
import org.owasp.webgoat.HammerHead;
|
||||||
import java.io.IOException;
|
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||||
import java.nio.file.Path;
|
import org.owasp.webgoat.lessons.Category;
|
||||||
import java.nio.file.Paths;
|
import org.owasp.webgoat.plugins.GlobalProperties;
|
||||||
import java.util.ArrayList;
|
import org.owasp.webgoat.plugins.LegacyLoader;
|
||||||
import java.util.Collections;
|
import org.owasp.webgoat.plugins.Plugin;
|
||||||
import java.util.Iterator;
|
import org.owasp.webgoat.plugins.PluginsLoader;
|
||||||
import java.util.LinkedList;
|
import org.slf4j.Logger;
|
||||||
import java.util.List;
|
import org.slf4j.LoggerFactory;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
/**
|
||||||
|
* *************************************************************************************************
|
||||||
/**
|
* <p/>
|
||||||
* *************************************************************************************************
|
* <p/>
|
||||||
* <p/>
|
* This file is part of WebGoat, an Open Web Application Security Project
|
||||||
* <p/>
|
* utility. For details, please see http://www.owasp.org/
|
||||||
* This file is part of WebGoat, an Open Web Application Security Project
|
* <p/>
|
||||||
* utility. For details, please see http://www.owasp.org/
|
* Copyright (c) 2002 - 20014 Bruce Mayhew
|
||||||
* <p/>
|
* <p/>
|
||||||
* Copyright (c) 2002 - 20014 Bruce Mayhew
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
* <p/>
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
* the terms of the GNU General Public License as published by the Free Software
|
* version.
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
* <p/>
|
||||||
* version.
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* <p/>
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
* details.
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* <p/>
|
||||||
* details.
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* <p/>
|
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
* You should have received a copy of the GNU General Public License along with
|
* Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
* <p/>
|
||||||
* Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Getting Source ==============
|
||||||
* <p/>
|
* <p/>
|
||||||
* Getting Source ==============
|
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
|
||||||
* <p/>
|
* for free software projects.
|
||||||
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
|
* <p/>
|
||||||
* for free software projects.
|
* For details, please see http://webgoat.github.io
|
||||||
* <p/>
|
*
|
||||||
* For details, please see http://webgoat.github.io
|
* @author Bruce Mayhew <a href="http://code.google.com/p/webgoat">WebGoat</a>
|
||||||
*
|
* @created October 28, 2003
|
||||||
* @author Bruce Mayhew <a href="http://code.google.com/p/webgoat">WebGoat</a>
|
*/
|
||||||
* @created October 28, 2003
|
public class Course {
|
||||||
*/
|
|
||||||
public class Course {
|
final Logger logger = LoggerFactory.getLogger(Course.class);
|
||||||
|
|
||||||
final Logger logger = LoggerFactory.getLogger(Course.class);
|
private final List<AbstractLesson> lessons = new LinkedList<AbstractLesson>();
|
||||||
|
|
||||||
private final List<AbstractLesson> lessons = new LinkedList<AbstractLesson>();
|
private final static String PROPERTIES_FILENAME = HammerHead.propertiesPath;
|
||||||
|
|
||||||
private final static String PROPERTIES_FILENAME = HammerHead.propertiesPath;
|
private WebgoatProperties properties = null;
|
||||||
|
|
||||||
private WebgoatProperties properties = null;
|
private WebgoatContext webgoatContext;
|
||||||
|
|
||||||
private final List<String> files = new LinkedList<String>();
|
public Course() {
|
||||||
|
try {
|
||||||
private WebgoatContext webgoatContext;
|
properties = new WebgoatProperties(PROPERTIES_FILENAME);
|
||||||
|
} catch (IOException e) {
|
||||||
public Course() {
|
logger.error("Error loading webgoat properties", e);
|
||||||
try {
|
}
|
||||||
properties = new WebgoatProperties(PROPERTIES_FILENAME);
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Error loading webgoat properties", e);
|
/**
|
||||||
}
|
* Take an absolute file and return the filename.
|
||||||
}
|
* <p/>
|
||||||
|
* Ex. /etc/password becomes password
|
||||||
/**
|
*
|
||||||
* Take an absolute file and return the filename.
|
* @param s
|
||||||
* <p/>
|
* @return the file name
|
||||||
* Ex. /etc/password becomes password
|
*/
|
||||||
*
|
private static String getFileName(String s) {
|
||||||
* @param s
|
String fileName = new File(s).getName();
|
||||||
* @return the file name
|
|
||||||
*/
|
if (fileName.contains("/")) {
|
||||||
private static String getFileName(String s) {
|
fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
|
||||||
String fileName = new File(s).getName();
|
}
|
||||||
|
|
||||||
if (fileName.contains("/")) {
|
if (fileName.contains(".")) {
|
||||||
fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
|
fileName = fileName.substring(0, fileName.indexOf("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName.contains(".")) {
|
return fileName;
|
||||||
fileName = fileName.substring(0, fileName.indexOf("."));
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
return fileName;
|
* Take a class name and return the equivalent file name
|
||||||
}
|
* <p/>
|
||||||
|
* Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
|
||||||
/**
|
*
|
||||||
* Take a class name and return the equivalent file name
|
* @param className
|
||||||
* <p/>
|
* @return
|
||||||
* Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
|
*/
|
||||||
*
|
private static String getSourceFile(String className) {
|
||||||
* @param className
|
StringBuilder sb = new StringBuilder();
|
||||||
* @return
|
|
||||||
*/
|
sb.append(className.replace(".", "/"));
|
||||||
private static String getSourceFile(String className) {
|
sb.append(".java");
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
return sb.toString();
|
||||||
sb.append(className.replace(".", "/"));
|
}
|
||||||
sb.append(".java");
|
|
||||||
|
/**
|
||||||
return sb.toString();
|
* Takes a file name and builds the class file name
|
||||||
}
|
*
|
||||||
|
* @param fileName Description of the Parameter
|
||||||
/**
|
* @param path Description of the Parameter
|
||||||
* Takes a file name and builds the class file name
|
* @return Description of the Return Value
|
||||||
*
|
*/
|
||||||
* @param fileName Description of the Parameter
|
private static String getClassFile(String fileName, String path) {
|
||||||
* @param path Description of the Parameter
|
String ext = ".class";
|
||||||
* @return Description of the Return Value
|
fileName = fileName.trim();
|
||||||
*/
|
|
||||||
private static String getClassFile(String fileName, String path) {
|
/**
|
||||||
String ext = ".class";
|
* We do not handle directories. We do not handle files with different
|
||||||
fileName = fileName.trim();
|
* extensions
|
||||||
|
*/
|
||||||
/**
|
if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
|
||||||
* We do not handle directories. We do not handle files with different
|
return null;
|
||||||
* extensions
|
}
|
||||||
*/
|
|
||||||
if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
|
// if the file is in /WEB-INF/classes strip the dir info off
|
||||||
return null;
|
int index = fileName.indexOf("/WEB-INF/classes/");
|
||||||
}
|
if (index != -1) {
|
||||||
|
fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
|
||||||
// if the file is in /WEB-INF/classes strip the dir info off
|
fileName = fileName.replace('/', '.');
|
||||||
int index = fileName.indexOf("/WEB-INF/classes/");
|
fileName = fileName.replace('\\', '.');
|
||||||
if (index != -1) {
|
} else {
|
||||||
fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
|
// Strip off the leading path info
|
||||||
fileName = fileName.replace('/', '.');
|
fileName = fileName.substring(path.length(), fileName.length() - ext.length());
|
||||||
fileName = fileName.replace('\\', '.');
|
}
|
||||||
} else {
|
|
||||||
// Strip off the leading path info
|
return fileName;
|
||||||
fileName = fileName.substring(path.length(), fileName.length() - ext.length());
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
return fileName;
|
* Gets the categories attribute of the Course object
|
||||||
}
|
*
|
||||||
|
* @return The categories value
|
||||||
/**
|
*/
|
||||||
* Gets the categories attribute of the Course object
|
public List getCategories() {
|
||||||
*
|
List<Category> categories = new ArrayList<Category>();
|
||||||
* @return The categories value
|
for (AbstractLesson lesson : lessons) {
|
||||||
*/
|
if (!categories.contains(lesson.getCategory())) {
|
||||||
public List getCategories() {
|
categories.add(lesson.getCategory());
|
||||||
List<Category> categories = new ArrayList<Category>();
|
}
|
||||||
for (AbstractLesson lesson : lessons) {
|
}
|
||||||
if (!categories.contains(lesson.getCategory())) {
|
|
||||||
categories.add(lesson.getCategory());
|
Collections.sort(categories);
|
||||||
}
|
|
||||||
}
|
return categories;
|
||||||
|
}
|
||||||
Collections.sort(categories);
|
|
||||||
|
/**
|
||||||
return categories;
|
* Gets the firstLesson attribute of the Course object
|
||||||
}
|
*
|
||||||
|
* @return The firstLesson value
|
||||||
/**
|
*/
|
||||||
* Gets the firstLesson attribute of the Course object
|
public AbstractLesson getFirstLesson() {
|
||||||
*
|
List<String> roles = new ArrayList<String>();
|
||||||
* @return The firstLesson value
|
roles.add(AbstractLesson.USER_ROLE);
|
||||||
*/
|
// Category 0 is the admin function. We want the first real category
|
||||||
public AbstractLesson getFirstLesson() {
|
// to be returned. This is normally the General category and the Http Basics lesson
|
||||||
List<String> roles = new ArrayList<String>();
|
return ((AbstractLesson) getLessons((Category) getCategories().get(0), roles).get(0));
|
||||||
roles.add(AbstractLesson.USER_ROLE);
|
}
|
||||||
// Category 0 is the admin function. We want the first real category
|
|
||||||
// to be returned. This is normally the General category and the Http Basics lesson
|
/**
|
||||||
return ((AbstractLesson) getLessons((Category) getCategories().get(0), roles).get(0));
|
* Gets the lesson attribute of the Course object
|
||||||
}
|
*
|
||||||
|
* @param s
|
||||||
/**
|
* @param lessonId Description of the Parameter
|
||||||
* Gets the lesson attribute of the Course object
|
* @param roles
|
||||||
*
|
* @return The lesson value
|
||||||
* @param s
|
*/
|
||||||
* @param lessonId Description of the Parameter
|
public AbstractLesson getLesson(WebSession s, int lessonId, List<String> roles) {
|
||||||
* @param roles
|
if (s.isHackedAdmin()) {
|
||||||
* @return The lesson value
|
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
||||||
*/
|
}
|
||||||
public AbstractLesson getLesson(WebSession s, int lessonId, List<String> roles) {
|
// System.out.println("getLesson() with roles: " + roles);
|
||||||
if (s.isHackedAdmin()) {
|
Iterator<AbstractLesson> iter = lessons.iterator();
|
||||||
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
|
||||||
}
|
while (iter.hasNext()) {
|
||||||
// System.out.println("getLesson() with roles: " + roles);
|
AbstractLesson lesson = iter.next();
|
||||||
Iterator<AbstractLesson> iter = lessons.iterator();
|
|
||||||
|
// System.out.println("getLesson() at role: " + lesson.getRole());
|
||||||
while (iter.hasNext()) {
|
if (lesson.getScreenId() == lessonId && roles.contains(lesson.getRole())) {
|
||||||
AbstractLesson lesson = iter.next();
|
return lesson;
|
||||||
|
}
|
||||||
// System.out.println("getLesson() at role: " + lesson.getRole());
|
}
|
||||||
if (lesson.getScreenId() == lessonId && roles.contains(lesson.getRole())) {
|
|
||||||
return lesson;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public AbstractLesson getLesson(WebSession s, int lessonId, String role) {
|
||||||
return null;
|
List<String> roles = new ArrayList<String>();
|
||||||
}
|
roles.add(role);
|
||||||
|
return getLesson(s, lessonId, roles);
|
||||||
public AbstractLesson getLesson(WebSession s, int lessonId, String role) {
|
}
|
||||||
List<String> roles = new ArrayList<String>();
|
|
||||||
roles.add(role);
|
public List getLessons(WebSession s, String role) {
|
||||||
return getLesson(s, lessonId, roles);
|
List<String> roles = new ArrayList<String>();
|
||||||
}
|
roles.add(role);
|
||||||
|
return getLessons(s, roles);
|
||||||
public List getLessons(WebSession s, String role) {
|
}
|
||||||
List<String> roles = new ArrayList<String>();
|
|
||||||
roles.add(role);
|
/**
|
||||||
return getLessons(s, roles);
|
* Gets the lessons attribute of the Course object
|
||||||
}
|
*
|
||||||
|
* @param s
|
||||||
/**
|
* @param roles
|
||||||
* Gets the lessons attribute of the Course object
|
* @return The lessons value
|
||||||
*
|
*/
|
||||||
* @param s
|
public List<AbstractLesson> getLessons(WebSession s, List<String> roles) {
|
||||||
* @param roles
|
if (s.isHackedAdmin()) {
|
||||||
* @return The lessons value
|
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
||||||
*/
|
}
|
||||||
public List<AbstractLesson> getLessons(WebSession s, List<String> roles) {
|
List<AbstractLesson> lessonList = new ArrayList<AbstractLesson>();
|
||||||
if (s.isHackedAdmin()) {
|
Iterator categoryIter = getCategories().iterator();
|
||||||
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
|
||||||
}
|
while (categoryIter.hasNext()) {
|
||||||
List<AbstractLesson> lessonList = new ArrayList<AbstractLesson>();
|
lessonList.addAll(getLessons(s, (Category) categoryIter.next(), roles));
|
||||||
Iterator categoryIter = getCategories().iterator();
|
}
|
||||||
|
return lessonList;
|
||||||
while (categoryIter.hasNext()) {
|
}
|
||||||
lessonList.addAll(getLessons(s, (Category) categoryIter.next(), roles));
|
|
||||||
}
|
/**
|
||||||
return lessonList;
|
* Gets the lessons attribute of the Course object
|
||||||
}
|
*
|
||||||
|
* @param category Description of the Parameter
|
||||||
/**
|
* @param role Description of the Parameter
|
||||||
* Gets the lessons attribute of the Course object
|
* @return The lessons value
|
||||||
*
|
*/
|
||||||
* @param category Description of the Parameter
|
private List<AbstractLesson> getLessons(Category category, List roles) {
|
||||||
* @param role Description of the Parameter
|
List<AbstractLesson> lessonList = new ArrayList<AbstractLesson>();
|
||||||
* @return The lessons value
|
|
||||||
*/
|
for (AbstractLesson lesson : lessons) {
|
||||||
private List<AbstractLesson> getLessons(Category category, List roles) {
|
if (lesson.getCategory().equals(category) && roles.contains(lesson.getRole())) {
|
||||||
List<AbstractLesson> lessonList = new ArrayList<AbstractLesson>();
|
lessonList.add(lesson);
|
||||||
|
}
|
||||||
for (AbstractLesson lesson : lessons) {
|
}
|
||||||
if (lesson.getCategory().equals(category) && roles.contains(lesson.getRole())) {
|
|
||||||
lessonList.add(lesson);
|
Collections.sort(lessonList);
|
||||||
}
|
// System.out.println(java.util.Arrays.asList(lessonList));
|
||||||
}
|
return lessonList;
|
||||||
|
}
|
||||||
Collections.sort(lessonList);
|
|
||||||
// System.out.println(java.util.Arrays.asList(lessonList));
|
public List getLessons(WebSession s, Category category, String role) {
|
||||||
return lessonList;
|
List<String> roles = new ArrayList<String>();
|
||||||
}
|
roles.add(role);
|
||||||
|
return getLessons(s, category, roles);
|
||||||
public List getLessons(WebSession s, Category category, String role) {
|
}
|
||||||
List<String> roles = new ArrayList<String>();
|
|
||||||
roles.add(role);
|
public List<AbstractLesson> getLessons(WebSession s, Category category, List<String> roles) {
|
||||||
return getLessons(s, category, roles);
|
if (s.isHackedAdmin()) {
|
||||||
}
|
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
||||||
|
}
|
||||||
public List<AbstractLesson> getLessons(WebSession s, Category category, List<String> roles) {
|
return getLessons(category, roles);
|
||||||
if (s.isHackedAdmin()) {
|
}
|
||||||
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
|
|
||||||
}
|
public AbstractLesson getLesson(int lessonId) {
|
||||||
return getLessons(category, roles);
|
for (AbstractLesson l : lessons) {
|
||||||
}
|
if (l.getScreenId() == lessonId) {
|
||||||
|
return l;
|
||||||
public AbstractLesson getLesson(int lessonId) {
|
}
|
||||||
for (AbstractLesson l : lessons) {
|
}
|
||||||
if (l.getScreenId() == lessonId) {
|
return null;
|
||||||
return l;
|
}
|
||||||
}
|
|
||||||
}
|
private void loadLessonFromPlugin(ServletContext context) {
|
||||||
return null;
|
logger.debug("Loading plugins into cache");
|
||||||
}
|
String pluginPath = context.getRealPath("plugin_lessons");
|
||||||
|
String targetPath = context.getRealPath("plugin_extracted");
|
||||||
private void loadLessonFromPlugin(ServletContext context) {
|
if (pluginPath == null) {
|
||||||
logger.debug("Loading plugins into cache");
|
logger.error("Plugins directory {} not found", pluginPath);
|
||||||
String pluginPath = context.getRealPath("plugin_lessons");
|
return;
|
||||||
String targetPath = context.getRealPath("plugin_extracted");
|
}
|
||||||
if (pluginPath == null) {
|
new GlobalProperties(Paths.get(targetPath)).loadProperties(Paths.get(context.getRealPath("container//i18n")));
|
||||||
logger.error("Plugins directory {} not found", pluginPath);
|
|
||||||
return;
|
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
||||||
}
|
for (Plugin plugin : plugins) {
|
||||||
new GlobalProperties(Paths.get(targetPath)).loadProperties(Paths.get(context.getRealPath("container//i18n")));
|
try {
|
||||||
|
Class<AbstractLesson> c = plugin.getLesson();
|
||||||
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
Object o = c.newInstance();
|
||||||
for (Plugin plugin : plugins) {
|
|
||||||
try {
|
AbstractLesson lesson = (AbstractLesson) o;
|
||||||
Class<AbstractLesson> c = plugin.getLesson();
|
lesson.setWebgoatContext(webgoatContext);
|
||||||
Object o = c.newInstance();
|
|
||||||
|
lesson.update(properties);
|
||||||
AbstractLesson lesson = (AbstractLesson) o;
|
|
||||||
lesson.setWebgoatContext(webgoatContext);
|
if (!lesson.getHidden()) {
|
||||||
|
lessons.add(lesson);
|
||||||
lesson.update(properties);
|
}
|
||||||
|
for(Map.Entry<String, File> lessonPlan : plugin.getLessonPlans().entrySet()) {
|
||||||
if (!lesson.getHidden()) {
|
lesson.setLessonPlanFileName(lessonPlan.getKey(), lessonPlan.getValue().toString());
|
||||||
lessons.add(lesson);
|
}
|
||||||
}
|
lesson.setLessonSolutionFileName(plugin.getLessonSolutions().get("en").toString());
|
||||||
for(Map.Entry<String, File> lessonPlan : plugin.getLessonPlans().entrySet()) {
|
lesson.setSourceFileName(plugin.getLessonSource().toString());
|
||||||
lesson.setLessonPlanFileName(lessonPlan.getKey(), lessonPlan.getValue().toString());
|
} catch (Exception e) {
|
||||||
}
|
logger.error("Error in loadLessons: ", e);
|
||||||
lesson.setLessonSolutionFileName(plugin.getLessonSolutions().get("en").toString());
|
}
|
||||||
lesson.setSourceFileName(plugin.getLessonSource().toString());
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
logger.error("Error in loadLessons: ", e);
|
|
||||||
}
|
/**
|
||||||
}
|
* Description of the Method
|
||||||
}
|
*
|
||||||
|
* @param webgoatContext
|
||||||
/**
|
* @param path Description of the Parameter
|
||||||
* Description of the Method
|
* @param context Description of the Parameter
|
||||||
*
|
*/
|
||||||
* @param webgoatContext
|
public void loadCourses(WebgoatContext webgoatContext, ServletContext context, String path) {
|
||||||
* @param path Description of the Parameter
|
logger.info("Loading courses: " + path);
|
||||||
* @param context Description of the Parameter
|
this.webgoatContext = webgoatContext;
|
||||||
*/
|
loadLessonFromPlugin(context);
|
||||||
public void loadCourses(WebgoatContext webgoatContext, ServletContext context, String path) {
|
LegacyLoader loader = new LegacyLoader();
|
||||||
logger.info("Loading courses: " + path);
|
lessons.addAll(loader.loadLessons(webgoatContext, context, path, properties));
|
||||||
this.webgoatContext = webgoatContext;
|
}
|
||||||
loadLessonFromPlugin(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user