Skip to content

Commit 7979b29

Browse files
author
lawson89
committed
WEB-127 Report Card does not reflect viewing hints
WEB-143 Add "1 of N" to Hint display
1 parent b835711 commit 7979b29

File tree

6 files changed

+153
-113
lines changed

6 files changed

+153
-113
lines changed

src/main/java/org/owasp/webgoat/lessons/model/Hint.java

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
/***************************************************************************************************
2-
*
3-
*
4-
* This file is part of WebGoat, an Open Web Application Security Project utility. For details,
5-
* please see http://www.owasp.org/
6-
*
1+
/**
2+
* *************************************************************************************************
3+
*
4+
*
5+
* This file is part of WebGoat, an Open Web Application Security Project
6+
* utility. For details, please see http://www.owasp.org/
7+
*
78
* Copyright (c) 2002 - 20014 Bruce Mayhew
8-
*
9-
* This program is free software; you can redistribute it and/or modify it under the terms of the
10-
* GNU General Public License as published by the Free Software Foundation; either version 2 of the
11-
* License, or (at your option) any later version.
12-
*
13-
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14-
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15-
* General Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Public License along with this program; if
18-
* not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19-
* 02111-1307, USA.
20-
*
9+
*
10+
* This program is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License as published by the Free Software
12+
* Foundation; either version 2 of the License, or (at your option) any later
13+
* version.
14+
*
15+
* This program is distributed in the hope that it will be useful, but WITHOUT
16+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18+
* details.
19+
*
20+
* You should have received a copy of the GNU General Public License along with
21+
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22+
* Place - Suite 330, Boston, MA 02111-1307, USA.
23+
*
2124
* Getting Source ==============
22-
*
23-
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
24-
* projects.
25-
*
25+
*
26+
* Source for this application is maintained at
27+
* https://github.com/WebGoat/WebGoat, a repository for free software projects.
28+
*
2629
* For details, please see http://webgoat.github.io
2730
*/
2831
package org.owasp.webgoat.lessons.model;
@@ -36,6 +39,7 @@ public class Hint {
3639
private String hint;
3740
private String lesson;
3841
private int number;
42+
private boolean viewed = false;
3943

4044
/**
4145
* @return the hint
@@ -79,4 +83,18 @@ public void setNumber(int number) {
7983
this.number = number;
8084
}
8185

86+
/**
87+
* @return the viewed
88+
*/
89+
public boolean isViewed() {
90+
return viewed;
91+
}
92+
93+
/**
94+
* @param viewed the viewed to set
95+
*/
96+
public void setViewed(boolean viewed) {
97+
this.viewed = viewed;
98+
}
99+
82100
}

src/main/java/org/owasp/webgoat/service/HintService.java

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import org.owasp.webgoat.lessons.model.Hint;
1313
import org.owasp.webgoat.session.WebSession;
1414
import org.springframework.stereotype.Controller;
15+
import org.springframework.web.bind.annotation.RequestBody;
1516
import org.springframework.web.bind.annotation.RequestMapping;
17+
import org.springframework.web.bind.annotation.RequestMethod;
1618
import org.springframework.web.bind.annotation.ResponseBody;
17-
import org.springframework.web.servlet.ModelAndView;
1819

1920
/**
2021
*
@@ -43,44 +44,57 @@ List<Hint> showHint(HttpSession session) {
4344
if (hints == null) {
4445
return listHints;
4546
}
47+
int maxHintViewed = l.getLessonTracker(ws).getMaxHintLevel();
48+
System.out.println("maxHintViewed: " + maxHintViewed);
4649
int idx = 0;
50+
4751
for (String h : hints) {
4852
Hint hint = new Hint();
4953
hint.setHint(h);
5054
hint.setLesson(l.getName());
5155
hint.setNumber(idx);
56+
if (idx <= maxHintViewed) {
57+
hint.setViewed(true);
58+
}
5259
listHints.add(hint);
5360
idx++;
5461
}
5562
return listHints;
5663
}
5764

58-
@RequestMapping(value = "/hint_widget.mvc", produces = "text/html")
59-
public
60-
ModelAndView showHintsAsHtml(HttpSession session) {
61-
ModelAndView model = new ModelAndView();
62-
List<Hint> listHints = new ArrayList<Hint>();
63-
model.addObject("hints", listHints);
65+
/**
66+
* Marks hint as viewed on the current lesson Yes this is not very RESTish -
67+
* clean this up in next version
68+
*
69+
* @param hintNumber
70+
* @param session
71+
* @return
72+
*/
73+
@RequestMapping(value = "/hint_mark_as_viewed.mvc", produces = "application/json", method = RequestMethod.POST)
74+
public @ResponseBody
75+
boolean markHintAsViewed(HttpSession session, @RequestBody Integer hintNumber) {
76+
if (hintNumber == null) {
77+
return false;
78+
}
6479
WebSession ws = getWebSession(session);
6580
AbstractLesson l = ws.getCurrentLesson();
66-
if (l == null) {
67-
return model;
68-
}
69-
List<String> hints;
70-
hints = l.getHintsPublic(ws);
71-
if (hints == null) {
72-
return model;
73-
}
74-
int idx = 0;
75-
for (String h : hints) {
76-
Hint hint = new Hint();
77-
hint.setHint(h);
78-
hint.setLesson(l.getName());
79-
hint.setNumber(idx);
80-
listHints.add(hint);
81-
idx++;
82-
}
83-
model.setViewName("widgets/hints");
84-
return model;
81+
l.getLessonTracker(ws).setMaxHintLevel(hintNumber);
82+
return true;
8583
}
84+
85+
/**
86+
* Returns max hint viewed for current lesson
87+
*
88+
* @param session
89+
* @return
90+
*/
91+
@RequestMapping(value = "/max_hint_viewed.mvc", produces = "application/json")
92+
public @ResponseBody
93+
Integer getMaxHintViewed(HttpSession session) {
94+
WebSession ws = getWebSession(session);
95+
AbstractLesson l = ws.getCurrentLesson();
96+
int maxHintViewed = l.getLessonTracker(ws).getMaxHintLevel();
97+
return maxHintViewed;
98+
}
99+
86100
}

src/main/java/org/owasp/webgoat/service/ParameterService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
*
2424
* Getting Source ==============
2525
*
26-
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
27-
* for free software projects.
26+
* Source for this application is maintained at
27+
* https://github.com/WebGoat/WebGoat, a repository for free software projects.
2828
*
2929
* For details, please see http://webgoat.github.io
3030
*/
3131
package org.owasp.webgoat.service;
3232

33-
import java.util.ArrayList;
3433
import java.util.Collections;
3534
import java.util.List;
3635
import javax.servlet.http.HttpSession;
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
//goatConstants
22

33
var goatConstants = {
4-
CATEGORYCLASS:'fa-angle-right pull-right',
5-
lessonCompleteClass:'glyphicon glyphicon-check lessonComplete',
6-
selectedMenuClass:'selected',
7-
keepOpenClass:'keepOpen',
8-
menuPrefix : [
9-
{
10-
name:'LESSONS',
11-
type:'STATIC',
12-
complete:false,
13-
link:'',
14-
children:null,
15-
class:'fa-bars static'
16-
}],
17-
//services
18-
lessonService: 'service/lessonmenu.mvc',
19-
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
20-
hintService:'service/hint.mvc',
21-
sourceService:'service/source.mvc',
22-
solutionService:'service/solution.mvc',
23-
lessonPlanService:'service/lessonplan.mvc',
24-
menuService: 'service/lessonmenu.mvc',
25-
lessonTitleService: 'service/lessontitle.mvc',
26-
restartLessonService: 'service/restartlesson.mvc',
27-
28-
// literal messages
29-
notFound: 'Could not find',
30-
noHints: 'There are no hints defined.',
31-
noSourcePulled: 'No source was retrieved for this lesson'
32-
4+
CATEGORYCLASS: 'fa-angle-right pull-right',
5+
lessonCompleteClass: 'glyphicon glyphicon-check lessonComplete',
6+
selectedMenuClass: 'selected',
7+
keepOpenClass: 'keepOpen',
8+
menuPrefix: [
9+
{
10+
name: 'LESSONS',
11+
type: 'STATIC',
12+
complete: false,
13+
link: '',
14+
children: null,
15+
class: 'fa-bars static'
16+
}],
17+
//services
18+
lessonService: 'service/lessonmenu.mvc',
19+
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
20+
hintService: 'service/hint.mvc',
21+
hintServiceMarkAsViewed: 'service/hint_mark_as_viewed.mvc',
22+
sourceService: 'service/source.mvc',
23+
solutionService: 'service/solution.mvc',
24+
lessonPlanService: 'service/lessonplan.mvc',
25+
menuService: 'service/lessonmenu.mvc',
26+
lessonTitleService: 'service/lessontitle.mvc',
27+
restartLessonService: 'service/restartlesson.mvc',
28+
// literal messages
29+
notFound: 'Could not find',
30+
noHints: 'There are no hints defined.',
31+
noSourcePulled: 'No source was retrieved for this lesson'
32+
3333
};
3434

3535

0 commit comments

Comments
 (0)