Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94d0e65

Browse files
Implemented logout
1 parent b8592c8 commit 94d0e65

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎src/main/java/com/naturalprogrammer/spring5tutorial/config/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ protected void configure(HttpSecurity http) throws Exception {
1515
.authorizeRequests()
1616
.anyRequest().authenticated()
1717
.and()
18-
.formLogin().loginPage("/login").permitAll();
18+
.formLogin().loginPage("/login").permitAll()
19+
.and().logout().permitAll();
1920
}
2021
// @formatter:on
2122
}

‎src/main/webapp/WEB-INF/jsp/includes/header.jsp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2+
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
23
<!DOCTYPE html>
34
<html lang="en">
45
<head>
@@ -67,7 +68,14 @@
6768
<li class="dropdown">
6869
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
6970
<ul class="dropdown-menu">
70-
<li><a href="#">Action</a></li>
71+
<li>
72+
<form:form id="logoutForm" action="/logout">
73+
</form:form>
74+
<a href="#" onclick="document.getElementById('logoutForm').submit()">
75+
<span class="glyphicon glyphicon-log-out"></span>
76+
Sign out
77+
</a>
78+
</li>
7179
<li><a href="#">Another action</a></li>
7280
<li><a href="#">Something else here</a></li>
7381
<li role="separator" class="divider"></li>

‎src/main/webapp/WEB-INF/jsp/login.jsp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
<h3 class="panel-title">Please sign in</h3>
99
</div>
1010
<div class="panel-body">
11+
12+
<c:if test="${param.logout != null}">
13+
<div class="alert alert-success">
14+
You have been logged out
15+
</div>
16+
</c:if>
17+
18+
<c:if test="${param.error != null}">
19+
<div class="alert alert-danger">
20+
Failed to login.
21+
<c:if test="${SPRING_SECURITY_LAST_EXCEPTION != null}">
22+
Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
23+
</c:if>
24+
</div>
25+
</c:if>
26+
1127
<form:form>
1228

1329
<div class="form-group">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /