This commit is contained in:
@ -0,0 +1,72 @@
|
||||
package org.owasp.webgoat.lessons.model;
|
||||
|
||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.session.WebSession;
|
||||
|
||||
/**
|
||||
* Created by jason on 9/18/15.
|
||||
*/
|
||||
public class LessonInfoModel {
|
||||
|
||||
private String lessonTitle;
|
||||
private int numberHints;
|
||||
private boolean hasSource;
|
||||
private boolean hasSolution;
|
||||
private boolean hasPlan;
|
||||
private String source;
|
||||
private String solution;
|
||||
private String plan;
|
||||
|
||||
public LessonInfoModel(WebSession webSession) {
|
||||
AbstractLesson lesson = webSession.getCurrentLesson();
|
||||
//TODO make these first class citizens of the lesson itself; and stop passing the session all over
|
||||
// this.source = (lesson.getSource(webSession));
|
||||
// this.plan = (lesson.getPage(webSession));
|
||||
// this.solution = (lesson.getSolution(webSession));
|
||||
|
||||
this.hasSource = !lesson.getSource(webSession).contains("Could not find the source file or source file does not exist");
|
||||
this.hasPlan = !lesson.getSource(webSession).contains("Could not find lesson plan");
|
||||
this.hasSolution = !lesson.getSolution(webSession).contains("Could not find the solution file or solution file does not exist");
|
||||
this.lessonTitle = lesson.getTitle();
|
||||
this.numberHints = lesson.getHintCount(webSession);
|
||||
|
||||
if (this.numberHints == 1 && lesson.getHint(webSession,0).equals("Hint: There are no hints defined.")){
|
||||
this.numberHints = 0;
|
||||
}
|
||||
System.out.println("*** numHints = " + this.numberHints);
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
public String getLessonTitle() {
|
||||
return lessonTitle;
|
||||
}
|
||||
|
||||
public int getNumberHints() {
|
||||
return numberHints;
|
||||
}
|
||||
|
||||
public boolean isHasSource() {
|
||||
return hasSource;
|
||||
}
|
||||
|
||||
public boolean isHasSolution() {
|
||||
return hasSolution;
|
||||
}
|
||||
|
||||
public boolean isHasPlan() {
|
||||
return hasPlan;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public String getSolution() {
|
||||
return solution;
|
||||
}
|
||||
|
||||
public String getPlan() {
|
||||
return plan;
|
||||
}
|
||||
|
||||
}
|
@ -46,8 +46,8 @@ public class LessonMenuItem {
|
||||
private List<LessonMenuItem> children = new ArrayList<LessonMenuItem>();
|
||||
private boolean complete;
|
||||
private String link;
|
||||
private boolean showSource = true;
|
||||
private boolean showHints = true;
|
||||
// private boolean showSource = true;
|
||||
// private boolean showHints = true;
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>name</code>.</p>
|
||||
@ -157,40 +157,6 @@ public class LessonMenuItem {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isShowSource.</p>
|
||||
*
|
||||
* @return the showSource
|
||||
*/
|
||||
public boolean isShowSource() {
|
||||
return showSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>showSource</code>.</p>
|
||||
*
|
||||
* @param showSource the showSource to set
|
||||
*/
|
||||
public void setShowSource(boolean showSource) {
|
||||
this.showSource = showSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isShowHints.</p>
|
||||
*
|
||||
* @return the showHints
|
||||
*/
|
||||
public boolean isShowHints() {
|
||||
return showHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>showHints</code>.</p>
|
||||
*
|
||||
* @param showHints the showHints to set
|
||||
*/
|
||||
public void setShowHints(boolean showHints) {
|
||||
this.showHints = showHints;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package org.owasp.webgoat.service;
|
||||
|
||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.lessons.model.LessonInfoModel;
|
||||
import org.owasp.webgoat.lessons.model.LessonMenuItem;
|
||||
import org.owasp.webgoat.session.WebSession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@Controller
|
||||
public class LessonInfoService extends BaseService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LessonMenuService.class);
|
||||
|
||||
@RequestMapping(value = "/lessoninfo.mvc", produces = "application/json")
|
||||
public @ResponseBody
|
||||
LessonInfoModel getLessonInfo(HttpSession session) {
|
||||
WebSession webSession = getWebSession(session);
|
||||
return new LessonInfoModel(webSession);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public String handleException(Exception ex) {
|
||||
return "An error occurred retrieving the LessonInfoModel:" + ex.getMessage();
|
||||
}
|
||||
|
||||
protected LessonInfoModel getLessonInfoModel(WebSession webSession) {
|
||||
return new LessonInfoModel(webSession);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -88,20 +88,6 @@ public class LessonMenuService extends BaseService {
|
||||
if (lesson.isCompleted(ws)) {
|
||||
lessonItem.setComplete(true);
|
||||
}
|
||||
/* @TODO - do this in a more efficient way
|
||||
if (lesson.isAuthorized(ws, role, WebSession.SHOWHINTS)) {
|
||||
lessonItem.setShowHints(true);
|
||||
}
|
||||
|
||||
if (lesson.isAuthorized(ws, role, WebSession.SHOWSOURCE)) {
|
||||
lessonItem.setShowSource(true);
|
||||
}
|
||||
*/
|
||||
// special handling for challenge role
|
||||
if (Category.CHALLENGE.equals(lesson.getCategory())) {
|
||||
lessonItem.setShowHints(lesson.isAuthorized(ws, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS));
|
||||
lessonItem.setShowSource(lesson.isAuthorized(ws, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS));
|
||||
}
|
||||
|
||||
categoryItem.addChild(lessonItem);
|
||||
// Does the lesson have stages
|
||||
|
Reference in New Issue
Block a user