diff --git a/pom.xml b/pom.xml index c8221222e..89923067b 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ ${basedir}/src/main/java - + ${basedir}/src/main/resources @@ -88,6 +88,11 @@ axis-ant 1.2 + + org.apache.commons + commons-lang3 + 3.3.2 + commons-fileupload commons-fileupload diff --git a/src/main/java/org/owasp/webgoat/controller/Start.java b/src/main/java/org/owasp/webgoat/controller/Start.java index a56b4c7d4..b0e65c8f3 100644 --- a/src/main/java/org/owasp/webgoat/controller/Start.java +++ b/src/main/java/org/owasp/webgoat/controller/Start.java @@ -5,12 +5,15 @@ */ package org.owasp.webgoat.controller; +import java.util.Collection; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.owasp.webgoat.session.Course; +import org.apache.commons.lang3.StringUtils; import org.owasp.webgoat.session.WebSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -40,12 +43,29 @@ public class Start { model.setViewName("redirect:/login.mvc"); return model; } + String role = getRole(); + String user = request.getUserPrincipal().getName(); + model.addObject("role", role); + model.addObject("user", user); // if everything ok then go to webgoat UI model.setViewName("main_new"); return model; } + private String getRole() { + Collection authorities = (Collection) SecurityContextHolder.getContext().getAuthentication().getAuthorities(); + String role = "N/A"; + for (GrantedAuthority authority : authorities) { + authority.getAuthority(); + role = authority.getAuthority(); + role = StringUtils.lowerCase(role); + role = StringUtils.remove(role, "role_"); + break; + } + return role; + } + public boolean checkWebSession(HttpSession session) { Object o = session.getAttribute(WebSession.SESSION); if (o == null) { diff --git a/src/main/webapp/WEB-INF/pages/main_new.jsp b/src/main/webapp/WEB-INF/pages/main_new.jsp index 26d0081d2..4a4da8545 100644 --- a/src/main/webapp/WEB-INF/pages/main_new.jsp +++ b/src/main/webapp/WEB-INF/pages/main_new.jsp @@ -82,8 +82,8 @@