Hide logout in main.jsp if not logged in

This commit is contained in:
Rob Winch 2013-08-17 14:38:39 -05:00
parent 5fe32bb3c8
commit 51b9c4a19a
11 changed files with 82 additions and 61 deletions

View File

@ -80,16 +80,18 @@ include::hello-includes/exploring-the-secured-application.asc[]
==== Displaying the user name ==== Displaying the user name
Now that we have authenticated, let's update the application to display the username. Update main.jsp to contain the following snippet: Now that we have authenticated, let's update the application to display the username if the user is authenticated. Update main.jsp to contain the following snippet:
.src/main/webapp/WEB-INF/decorators/main.jsp .src/main/webapp/WEB-INF/decorators/main.jsp
[source,html] [source,html]
[subs="verbatim,quotes"] [subs="verbatim,quotes"]
---- ----
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
*<p class="navbar-text pull-right"> *<c:if test="${pageContext.request.remoteUser != null}">
<p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p>* </p>
</c:if>*
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>
@ -112,10 +114,12 @@ Now that we can view the user name, let's update the application to allow loggin
[subs="verbatim,quotes"] [subs="verbatim,quotes"]
---- ----
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
*<c:url var="logoutUrl" value="/logout"/> *<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post">
<input type="submit" value="Log out" /> <input type="submit" value="Log out" />
</form:form>* </form:form>
</c:if>*
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -86,7 +86,6 @@
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> <![endif]-->
<decorator:head/>
</head> </head>
@ -104,18 +103,18 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>
<c:url var="composeUrl" value="/?form"/> <c:url var="composeUrl" value="/?form"/>
<li><a href="${composeUrl}">Compose</a></li> <li><a href="${composeUrl}">Compose</a></li>
<c:url var="userUrl" value="/user/"/>
<li><a href="${userUrl}">User</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>

View File

@ -103,11 +103,13 @@
<c:url var="logoUrl" value="/resources/img/logo.png"/> <c:url var="logoUrl" value="/resources/img/logo.png"/>
<a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a> <a class="brand" href="${homeUrl}"><img src="${logoUrl}" alt="Spring Security Sample"/></a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<c:if test="${pageContext.request.remoteUser != null}">
<c:url var="logoutUrl" value="/logout"/> <c:url var="logoutUrl" value="/logout"/>
<form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form> <form:form class="navbar-form pull-right" action="${logoutUrl}" method="post"><input type="submit" value="Log out" /></form:form>
<p class="navbar-text pull-right"> <p class="navbar-text pull-right">
<c:out value="${pageContext.request.remoteUser}"/> <c:out value="${pageContext.request.remoteUser}"/>
</p> </p>
</c:if>
<ul class="nav"> <ul class="nav">
<c:url var="inboxUrl" value="/"/> <c:url var="inboxUrl" value="/"/>
<li><a href="${inboxUrl}">Inbox</a></li> <li><a href="${inboxUrl}">Inbox</a></li>