|
1 | 1 | <%@page import="com.onelogin.saml2.Auth"%> |
| 2 | +<%@page import="com.onelogin.saml2.servlet.ServletUtils"%> |
2 | 3 | <%@page import="java.util.Collection"%> |
3 | 4 | <%@page import="java.util.HashMap"%> |
4 | 5 | <%@page import="java.util.List"%> |
|
25 | 26 | <body> |
26 | 27 | <div class="container"> |
27 | 28 | <h1>A Java SAML Toolkit by OneLogin demo</h1> |
28 | | - |
| 29 | + |
29 | 30 | <!-- TODO Session support --> |
30 | | - |
| 31 | + |
31 | 32 | <% |
32 | 33 | Auth auth = new Auth(request, response); |
33 | 34 | auth.processResponse(); |
34 | 35 |
|
35 | 36 | if (!auth.isAuthenticated()) { |
36 | 37 | out.println("<div class=\"alert alert-danger\" role=\"alert\">Not authenticated</div>"); |
37 | 38 | } |
38 | | - |
| 39 | +
|
39 | 40 | List<String> errors = auth.getErrors(); |
40 | | - out.println("<p>" + StringUtils.join(errors, ", ") + "</p>"); |
41 | | - |
| 41 | +
|
42 | 42 | if (!errors.isEmpty()) { |
| 43 | + out.println("<p>" + StringUtils.join(errors, ", ") + "</p>"); |
43 | 44 | if (auth.isDebugActive()) { |
44 | 45 | String errorReason = auth.getLastErrorReason(); |
45 | 46 | if (errorReason != null && !errorReason.isEmpty()) { |
|
50 | 51 | } else { |
51 | 52 | Map<String, List<String>> attributes = auth.getAttributes(); |
52 | 53 | String nameId = auth.getNameId(); |
53 | | - |
| 54 | +
|
54 | 55 | session.setAttribute("attributes", attributes); |
55 | 56 | session.setAttribute("nameId", nameId); |
56 | | - |
57 | | - if (attributes.isEmpty()) { |
58 | | - %> |
59 | | - <div class="alert alert-danger" role="alert">You don't have any attributes</div> |
60 | | - <% |
61 | | - } |
62 | | - else { |
63 | | - %> |
64 | | - <table class="table table-striped"> |
65 | | - <thead> |
66 | | - <th>Name</th> |
67 | | - <th>Values</th> |
68 | | - </thead> |
69 | | - <tbody> |
70 | | - <% |
71 | | - Collection<String> keys = attributes.keySet(); |
72 | | - for(String name :keys){ |
73 | | - out.println("<tr><td>" + name + "</td><td>"); |
74 | | - List<String> values = attributes.get(name); |
75 | | - for(String value :values) { |
76 | | - out.println("<li>" + value + "</li>"); |
| 57 | +
|
| 58 | + String relayState = request.getParameter("RelayState"); |
| 59 | +
|
| 60 | + if (relayState != null && relayState != ServletUtils.getSelfRoutedURLNoQuery(request) && |
| 61 | + !relayState.contains("/dologin.jsp") ) { // We don't want to be redirected to login.jsp neither |
| 62 | + response.sendRedirect(request.getParameter("RelayState")); |
| 63 | + } else { |
| 64 | + |
| 65 | +
|
| 66 | + if (attributes.isEmpty()) { |
| 67 | + %> |
| 68 | + <div class="alert alert-danger" role="alert">You don't have any attributes</div> |
| 69 | + <% |
| 70 | + } |
| 71 | + else { |
| 72 | + %> |
| 73 | + <table class="table table-striped"> |
| 74 | + <thead> |
| 75 | + <th>Name</th> |
| 76 | + <th>Values</th> |
| 77 | + </thead> |
| 78 | + <tbody> |
| 79 | + <% |
| 80 | + Collection<String> keys = attributes.keySet(); |
| 81 | + for(String name :keys){ |
| 82 | + out.println("<tr><td>" + name + "</td><td>"); |
| 83 | + List<String> values = attributes.get(name); |
| 84 | + for(String value :values) { |
| 85 | + out.println("<li>" + value + "</li>"); |
| 86 | + } |
| 87 | + |
| 88 | + out.println("</td></tr>"); |
77 | 89 | } |
78 | | - |
79 | | - out.println("</td></tr>"); |
| 90 | + %> |
| 91 | + </tbody> |
| 92 | + </table> |
| 93 | + <% |
80 | 94 | } |
81 | | - %> |
82 | | - </tbody> |
83 | | - </table> |
84 | | - <% |
| 95 | + %> |
| 96 | + <a href="attrs.jsp" class="btn btn-primary">See user data stored at session</a> |
| 97 | + <a href="dologout.jsp" class="btn btn-primary">Logout</a> |
| 98 | + <% |
85 | 99 | } |
86 | | - %> |
87 | | - <a href="attrs.jsp" class="btn btn-primary">See user data stored at session</a> |
88 | | - <a href="dologout.jsp" class="btn btn-primary">Logout</a> |
89 | | - <% |
90 | 100 | } |
91 | | - %> |
| 101 | + %> |
92 | 102 | </div> |
93 | 103 | </body> |
94 | 104 | </html> |
0 commit comments