Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. @RequestMapping(value = "/hello.do", method = RequestMethod.GET)
  2. public ModelAndView helloPage() {
  3.  
  4. ModelAndView model = new ModelAndView();
  5. model.addObject("title", "Spring Security Login Form - Database Authentication");
  6. model.addObject("message", "This page is for ROLE_ADMIN only!");
  7. model.setViewName("hello");
  8.  
  9. return model;
  10.  
  11. }
  12.  
  13. <form name='loginForm'
  14. action="<c:url value='/hello.do' />" method='POST'>
  15.  
  16. <table>
  17. <tr>
  18. <td>User:</td>
  19. <td><input type='text' name='username'></td>
  20. </tr>
  21. <tr>
  22. <td>Password:</td>
  23. <td><input type='password' name='password' /></td>
  24. </tr>
  25. <tr>
  26. <td colspan='2'><input name="submit" type="submit"
  27. value="submit" /></td>
  28. </tr>
  29. </table>
  30.  
  31. <input type="hidden" name="${_csrf.parameterName}"
  32. value="${_csrf.token}" />
  33. </form>
  34.  
  35. <sec:authorize access="hasRole('ROLE_ADMIN')">
  36.  
  37. <!-- For login user -->
  38. <c:url value="/logout" var="logoutUrl" />
  39. <form action="${logoutUrl}" method="post" id="logoutForm">
  40. <input type="hidden" name="${_csrf.parameterName}"
  41. value="${_csrf.token}" />
  42. </form>
  43. <script>
  44. function formSubmit() {
  45. document.getElementById("logoutForm").submit();
  46. }
  47. </script>
  48.  
  49. <c:if test="${pageContext.request.userPrincipal.name != null}">
  50. <h2>
  51. User : ${pageContext.request.userPrincipal.name} | <a
  52. href="javascript:formSubmit()"> Logout</a>
  53. </h2>
  54. </c:if><h1>hola admin</h1>
  55.  
  56. </sec:authorize>
  57.  
  58. <sec:authorize access="hasRole('ROLE_USER')">
  59. <!-- For login user -->
  60. <c:url value="/logout" var="logoutUrl" />
  61. <form action="${logoutUrl}" method="post" id="logoutForm">
  62. <input type="hidden" name="${_csrf.parameterName}"
  63. value="${_csrf.token}" />
  64. </form>
  65. <script>
  66. function formSubmit() {
  67. document.getElementById("logoutForm").submit();
  68. }
  69. </script>
  70.  
  71. <c:if test="${pageContext.request.userPrincipal.name != null}">
  72. <h2>
  73. User : ${pageContext.request.userPrincipal.name} | <a
  74. href="javascript:formSubmit()"> Logout</a>
  75. </h2>
  76. </c:if><h1>hola USUARIO</h1>
  77.  
  78. </sec:authorize>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement