
<%--
   Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
--%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%
    String inSessionUser = ((null != request.getUserPrincipal()) ? request.getUserPrincipal().getName() : null);
    String authMode = request.getAuthType();
    String count = (String)session.getAttribute("count");
    if (count == null) {
        count = "1";
    } else {
        count = String.valueOf(1 + Integer.parseInt(count));
    }
    session.setAttribute("count", count);
%>
<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
                h2, h3 {
                    text-decoration: underline;
                }

                #menu li {
                    cursor: pointer;
                }

                #menu a:hover {
                    background-color: rgb(105, 136, 203);;
                }

                p {
                    width: 500px;
                }
            </style>
        <title>Who am I?</title>
    </head>
    <body>
        <h2>Who am I?</h2>
         
        <h4>
            Authenticated app user:
            <%=(inSessionUser == null ? "Anonymous" : inSessionUser)%>
        </h4>
         
        <h4>
            Mode:
            <%=(authMode == null ? "Not authenticated" : authMode)%>
        </h4>
         
        <h4>
            Session Access Count:
            <%=count%>
        </h4>
         
        <%
        if (inSessionUser != null) {
        %>
         
        <a href="invalidate.jsp">logout</a>
         
        <%
        }%>
         
        <h2>All Headers</h2>
        <table>
            <tr>
                <th>name</th>
                <th>Value</th>
            </tr>
             
            <%
         Enumeration eheader = request.getHeaderNames();
            if (eheader != null) {
                while (eheader.hasMoreElements()) {
                    String key = (String)eheader.nextElement();
                    String val = request.getHeader(key);
                    %>
             
            <tr>
                <td>
                    <%=key%>
                </td>
                <td>
                    <%=val%>
                </td>
            </tr>
             
            <%
                }

            }
   %>
        </table>
    </body>
</html>