|
5 | 5 | */
|
6 | 6 | package org.owasp.webgoat.controller;
|
7 | 7 |
|
| 8 | +import java.util.Collection; |
8 | 9 | import javax.servlet.http.HttpServletRequest;
|
9 | 10 | import javax.servlet.http.HttpSession;
|
10 |
| -import org.owasp.webgoat.session.Course; |
| 11 | +import org.apache.commons.lang3.StringUtils; |
11 | 12 | import org.owasp.webgoat.session.WebSession;
|
12 | 13 | import org.slf4j.Logger;
|
13 | 14 | import org.slf4j.LoggerFactory;
|
| 15 | +import org.springframework.security.core.GrantedAuthority; |
| 16 | +import org.springframework.security.core.context.SecurityContextHolder; |
14 | 17 | import org.springframework.stereotype.Controller;
|
15 | 18 | import org.springframework.web.bind.annotation.RequestMapping;
|
16 | 19 | import org.springframework.web.bind.annotation.RequestMethod;
|
@@ -40,12 +43,29 @@ public ModelAndView start(HttpServletRequest request,
|
40 | 43 | model.setViewName("redirect:/login.mvc");
|
41 | 44 | return model;
|
42 | 45 | }
|
| 46 | + String role = getRole(); |
| 47 | + String user = request.getUserPrincipal().getName(); |
| 48 | + model.addObject("role", role); |
| 49 | + model.addObject("user", user); |
43 | 50 |
|
44 | 51 | // if everything ok then go to webgoat UI
|
45 | 52 | model.setViewName("main_new");
|
46 | 53 | return model;
|
47 | 54 | }
|
48 | 55 |
|
| 56 | + private String getRole() { |
| 57 | + Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) SecurityContextHolder.getContext().getAuthentication().getAuthorities(); |
| 58 | + String role = "N/A"; |
| 59 | + for (GrantedAuthority authority : authorities) { |
| 60 | + authority.getAuthority(); |
| 61 | + role = authority.getAuthority(); |
| 62 | + role = StringUtils.lowerCase(role); |
| 63 | + role = StringUtils.remove(role, "role_"); |
| 64 | + break; |
| 65 | + } |
| 66 | + return role; |
| 67 | + } |
| 68 | + |
49 | 69 | public boolean checkWebSession(HttpSession session) {
|
50 | 70 | Object o = session.getAttribute(WebSession.SESSION);
|
51 | 71 | if (o == null) {
|
|
0 commit comments