Skip to content

Commit b167420

Browse files
committed
Re-enable csrf in booking-faces
1 parent 758596d commit b167420

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

booking-faces/src/main/java/org/springframework/webflow/samples/booking/config/SecurityConfig.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
66
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
77
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8-
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
9-
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
108

119
@Configuration
1210
@EnableWebSecurity
1311
public class SecurityConfig extends WebSecurityConfigurerAdapter {
1412

1513
@Override
1614
protected void configure(HttpSecurity http) throws Exception {
17-
1815
http
1916
.formLogin()
2017
.loginPage("/spring/login")
@@ -24,15 +21,7 @@ protected void configure(HttpSecurity http) throws Exception {
2421
.and()
2522
.logout()
2623
.logoutUrl("/spring/logout")
27-
.logoutSuccessUrl("/spring/logoutSuccess")
28-
.and()
29-
30-
// Disable CSRF (won't work with JSF) but ensure last HTTP POST request is saved
31-
// See https://jira.springsource.org/browse/SEC-2498
32-
33-
.csrf().disable()
34-
.requestCache()
35-
.requestCache(new HttpSessionRequestCache());
24+
.logoutSuccessUrl("/spring/logoutSuccess");
3625
}
3726

3827
@Override

booking-faces/src/main/webapp/WEB-INF/flows/booking/enterBookingDetails.xhtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
</p>
130130
</div>
131131
</div>
132+
<div>
133+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
134+
</div>
132135
<div>
133136
<p:commandButton id="proceed" action="proceed" value="Proceed" update="@form" />
134137
<p:commandButton id="cancel" value="Cancel" action="cancel" immediate="true" />

booking-faces/src/main/webapp/WEB-INF/flows/booking/reviewBooking.xhtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
</p>
7272
</div>
7373
</div>
74+
<div>
75+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
76+
</div>
7477
<div>
7578
<p:commandButton id="confirm" value="Confirm" action="confirm"/>&#160;
7679
<p:commandButton id="revise" value="Revise" action="revise"/>&#160;

booking-faces/src/main/webapp/WEB-INF/flows/main/enterSearchCriteria.xhtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
</h:panelGrid>
3232
<p:tooltip for="searchString" targetPosition="topRight" position="bottomLeft"
3333
value="Search hotels by name, address, city, or zip." style="cream" />
34-
</h:form>
34+
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
35+
</h:form>
3536
</p:panel>
3637

3738
<p:panel id="bookings" header="Your Hotel Bookings" rendered="#{currentUser!=null}" toggleable="true" toggleSpeed="100" style="margin-top: 10px">
@@ -67,7 +68,8 @@
6768
</p:column>
6869
</p:dataTable>
6970
</p:outputPanel>
70-
</h:form>
71+
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
72+
</h:form>
7173
</p:panel>
7274

7375
</ui:define>

booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotel.xhtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<f:convertNumber type="currency" currencySymbol="$"/>
3535
</h:outputText>
3636
</div>
37+
<div>
38+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
39+
</div>
3740
<div>
3841
<p:commandButton id="book" action="book" value="Book Hotel" ajax="false" />
3942
<p:commandButton id="cancel" action="cancel" value="Back to Search"/>

booking-faces/src/main/webapp/WEB-INF/flows/main/reviewHotels.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</p:commandButton>
4848
</p:column>
4949
</p:dataTable>
50+
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
5051
</h:form>
5152
</ui:define>
5253
</ui:composition>

booking-faces/src/main/webapp/WEB-INF/layouts/standard.xhtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
<div>
3232
<h4 class="alt bottom">
3333
<c:if test="${not empty currentUser.name}">
34-
Welcome, ${currentUser.name} | <a href="${request.contextPath}/spring/logout">Logout</a>
34+
<form name="f" action="${request.contextPath}/spring/logout" method="post">
35+
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
36+
Welcome, ${currentUser.name}
37+
<input name="submit" type="submit" value="Logout" />
38+
</form>
3539
</c:if>
3640
<c:if test="${empty currentUser.name}">
3741
<a href="${request.contextPath}/spring/login">Login</a>

booking-faces/src/main/webapp/WEB-INF/login.xhtml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
<div class="span-10 append-2 last">
2525
<c:if test="${not empty param.login_error}">
2626
<div class="error">
27-
Your login attempt was not successful, try again.<br />
28-
Reason: #{sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}
27+
Your login attempt was not successful, try again.
2928
</div>
3029
</c:if>
3130
<form name="f" action="${request.contextPath}/spring/loginProcess" method="post">
@@ -34,9 +33,6 @@
3433
<p>
3534
User:
3635
<br />
37-
<c:if test="${not empty param.login_error}">
38-
<c:set var="username" value="${sessionScope.SPRING_SECURITY_LAST_USERNAME}"/>
39-
</c:if>
4036
<input type="text" name="username" value="#{username}"/>
4137
</p>
4238
<p>
@@ -48,6 +44,9 @@
4844
<input type="checkbox" name="_spring_security_remember_me"/>
4945
Don't ask for my password for two weeks:
5046
</p>
47+
<div>
48+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
49+
</div>
5150
<p>
5251
<input name="submit" type="submit" value="Login" />
5352
</p>

0 commit comments

Comments
 (0)