Re-enable csrf in booking-faces

This commit is contained in:
Rossen Stoyanchev
2018-02-07 17:22:59 -05:00
parent 758596d08c
commit b1674203b3
8 changed files with 24 additions and 20 deletions

View File

@@ -5,8 +5,6 @@ import org.springframework.security.config.annotation.authentication.builders.Au
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
@Configuration
@EnableWebSecurity
@@ -14,7 +12,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/spring/login")
@@ -24,15 +21,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.and()
.logout()
.logoutUrl("/spring/logout")
.logoutSuccessUrl("/spring/logoutSuccess")
.and()
// Disable CSRF (won't work with JSF) but ensure last HTTP POST request is saved
// See https://jira.springsource.org/browse/SEC-2498
.csrf().disable()
.requestCache()
.requestCache(new HttpSessionRequestCache());
.logoutSuccessUrl("/spring/logoutSuccess");
}
@Override

View File

@@ -129,6 +129,9 @@
</p>
</div>
</div>
<div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</div>
<div>
<p:commandButton id="proceed" action="proceed" value="Proceed" update="@form" />
<p:commandButton id="cancel" value="Cancel" action="cancel" immediate="true" />

View File

@@ -71,6 +71,9 @@
</p>
</div>
</div>
<div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</div>
<div>
<p:commandButton id="confirm" value="Confirm" action="confirm"/>&#160;
<p:commandButton id="revise" value="Revise" action="revise"/>&#160;

View File

@@ -31,7 +31,8 @@
</h:panelGrid>
<p:tooltip for="searchString" targetPosition="topRight" position="bottomLeft"
value="Search hotels by name, address, city, or zip." style="cream" />
</h:form>
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
</h:form>
</p:panel>
<p:panel id="bookings" header="Your Hotel Bookings" rendered="#{currentUser!=null}" toggleable="true" toggleSpeed="100" style="margin-top: 10px">
@@ -67,7 +68,8 @@
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
</h:form>
</p:panel>
</ui:define>

View File

@@ -34,6 +34,9 @@
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</div>
<div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</div>
<div>
<p:commandButton id="book" action="book" value="Book Hotel" ajax="false" />
<p:commandButton id="cancel" action="cancel" value="Back to Search"/>

View File

@@ -47,6 +47,7 @@
</p:commandButton>
</p:column>
</p:dataTable>
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
</h:form>
</ui:define>
</ui:composition>

View File

@@ -31,7 +31,11 @@
<div>
<h4 class="alt bottom">
<c:if test="${not empty currentUser.name}">
Welcome, ${currentUser.name} | <a href="${request.contextPath}/spring/logout">Logout</a>
<form name="f" action="${request.contextPath}/spring/logout" method="post">
<div><input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></div>
Welcome, ${currentUser.name}
<input name="submit" type="submit" value="Logout" />
</form>
</c:if>
<c:if test="${empty currentUser.name}">
<a href="${request.contextPath}/spring/login">Login</a>

View File

@@ -24,8 +24,7 @@
<div class="span-10 append-2 last">
<c:if test="${not empty param.login_error}">
<div class="error">
Your login attempt was not successful, try again.<br />
Reason: #{sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}
Your login attempt was not successful, try again.
</div>
</c:if>
<form name="f" action="${request.contextPath}/spring/loginProcess" method="post">
@@ -34,9 +33,6 @@
<p>
User:
<br />
<c:if test="${not empty param.login_error}">
<c:set var="username" value="${sessionScope.SPRING_SECURITY_LAST_USERNAME}"/>
</c:if>
<input type="text" name="username" value="#{username}"/>
</p>
<p>
@@ -48,6 +44,9 @@
<input type="checkbox" name="_spring_security_remember_me"/>
Don't ask for my password for two weeks:
</p>
<div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</div>
<p>
<input name="submit" type="submit" value="Login" />
</p>