Skip to content

Commit 3fd7b34

Browse files
committed
more changes for showSource and showHints
1 parent 5c1b3e1 commit 3fd7b34

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
*
6161
* Getting Source ==============
6262
*
63-
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
64-
* for free software projects.
63+
* Source for this application is maintained at
64+
* https://github.com/WebGoat/WebGoat, a repository for free software projects.
6565
*
6666
* For details, please see http://webgoat.github.io
6767
*
@@ -70,7 +70,7 @@
7070
*/
7171
public abstract class AbstractLesson extends Screen implements Comparable<Object> {
7272

73-
final Logger logger = LoggerFactory.getLogger(AbstractLesson.class);
73+
private static final Logger logger = LoggerFactory.getLogger(AbstractLesson.class);
7474

7575
/**
7676
* Description of the Field
@@ -612,6 +612,7 @@ public boolean isAuthorized(WebSession s, int employeeId, String functionId) {
612612
* @return
613613
*/
614614
public boolean isAuthorized(WebSession s, String role, String functionId) {
615+
logger.info("Checking if " + role + " authorized for: " + functionId);
615616
boolean authorized = false;
616617
try {
617618
String query = "SELECT * FROM auth WHERE role = '" + role + "' and functionid = '" + functionId + "'";
@@ -620,13 +621,14 @@ public boolean isAuthorized(WebSession s, String role, String functionId) {
620621
.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
621622
ResultSet answer_results = answer_statement.executeQuery(query);
622623
authorized = answer_results.first();
624+
logger.info("authorized: "+ authorized);
623625
} catch (SQLException sqle) {
624626
s.setMessage("Error authorizing");
625-
sqle.printStackTrace();
627+
logger.error("Error authorizing", sqle);
626628
}
627629
} catch (Exception e) {
628630
s.setMessage("Error authorizing");
629-
e.printStackTrace();
631+
logger.error("Error authorizing", e);
630632
}
631633
return authorized;
632634
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.StringWriter;
3535
import javax.servlet.http.HttpServletRequest;
3636
import javax.servlet.http.HttpSession;
37-
import org.owasp.webgoat.controller.Welcome;
3837
import org.owasp.webgoat.session.WebSession;
3938
import org.slf4j.Logger;
4039
import org.slf4j.LoggerFactory;
@@ -51,7 +50,7 @@
5150
@RequestMapping("/service")
5251
public abstract class BaseService {
5352

54-
final Logger logger = LoggerFactory.getLogger(BaseService.class);
53+
private static final Logger logger = LoggerFactory.getLogger(BaseService.class);
5554

5655
@ExceptionHandler(Exception.class)
5756
@ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT)

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.owasp.webgoat.lessons.model.LessonMenuItemType;
4141
import org.owasp.webgoat.session.Course;
4242
import org.owasp.webgoat.session.WebSession;
43+
import org.slf4j.Logger;
44+
import org.slf4j.LoggerFactory;
4345
import org.springframework.stereotype.Controller;
4446
import org.springframework.web.bind.annotation.RequestMapping;
4547
import org.springframework.web.bind.annotation.ResponseBody;
@@ -51,6 +53,8 @@
5153
@Controller
5254
public class LessonMenuService extends BaseService {
5355

56+
private static final Logger logger = LoggerFactory.getLogger(LessonMenuService.class);
57+
5458
/**
5559
* Returns the lesson menu which is used to build the left nav
5660
*
@@ -72,6 +76,8 @@ List<LessonMenuItem> showLeftNav(HttpSession session) {
7276
categoryItem.setType(LessonMenuItemType.CATEGORY);
7377
// check for any lessons for this category
7478
List<AbstractLesson> lessons = ws.getLessons(category);
79+
String role = ws.getRole();
80+
logger.info("Role: " + role);
7581
for (AbstractLesson lesson : lessons) {
7682
LessonMenuItem lessonItem = new LessonMenuItem();
7783
lessonItem.setName(lesson.getTitle());
@@ -80,13 +86,21 @@ List<LessonMenuItem> showLeftNav(HttpSession session) {
8086
if (lesson.isCompleted(ws)) {
8187
lessonItem.setComplete(true);
8288
}
83-
if (ws.isAuthorizedInLesson(ws.getRole(), WebSession.SHOWHINTS)) {
89+
90+
if (lesson.isAuthorized(ws, role, WebSession.SHOWHINTS)) {
8491
lessonItem.setShowHints(true);
8592
}
8693

87-
if (ws.isAuthorizedInLesson(ws.getRole(), WebSession.SHOWSOURCE)) {
94+
if (lesson.isAuthorized(ws, role, WebSession.SHOWSOURCE)) {
8895
lessonItem.setShowSource(true);
8996
}
97+
98+
// special handling for challenge role
99+
if (Category.CHALLENGE.equals(lesson.getCategory())) {
100+
lessonItem.setShowHints(lesson.isAuthorized(ws, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS));
101+
lessonItem.setShowSource(lesson.isAuthorized(ws, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS));
102+
}
103+
90104
categoryItem.addChild(lessonItem);
91105
// Does the lesson have stages
92106
if (lesson instanceof RandomLessonAdapter) {

src/main/java/org/owasp/webgoat/session/WebSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public class WebSession {
7575
/**
7676
* Tomcat role for a webgoat user
7777
*/
78-
public final static String WEBGOAT_USER = "webgoat_user";
78+
public final static String WEBGOAT_USER = "ROLE_WEBGOAT_USER";
7979

8080
/**
8181
* Tomcat role for a webgoat admin
8282
*/
83-
public final static String WEBGOAT_ADMIN = "webgoat_admin";
83+
public final static String WEBGOAT_ADMIN = "ROLE_WEBGOAT_ADMIN";
8484

8585
/**
8686
* Description of the Field

0 commit comments

Comments
 (0)