Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit ed9887b

Browse files
authored
Merge pull request #1170 from stormpath/issue/1138
Issue/1138
2 parents 1ca0e27 + 63dbe8c commit ed9887b

15 files changed

Lines changed: 439 additions & 136 deletions

File tree

examples/servlet/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@
116116
<configuration>
117117
<skip>${skipITs}</skip>
118118
<container>
119-
<containerId>tomcat7x</containerId>
119+
<containerId>tomcat8x</containerId>
120120
<zipUrlInstaller>
121121
<url>
122-
http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/7.0.69/tomcat-7.0.69.zip
122+
http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip
123123
</url>
124124
</zipUrlInstaller>
125125
</container>

examples/spring-security-spring-boot-webmvc-bare-bones/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3939
<slf4j.version>1.7.21</slf4j.version>
4040
<spring.boot.version>1.4.0.RELEASE</spring.boot.version>
41-
<tomcat.version>7.0.59</tomcat.version>
41+
<tomcat.version>8.5.9</tomcat.version>
4242
</properties>
4343

4444
<dependencies>

examples/spring-security-spring-boot-webmvc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4040
<slf4j.version>1.7.21</slf4j.version>
4141
<spring.boot.version>1.4.0.RELEASE</spring.boot.version>
42-
<tomcat.version>7.0.59</tomcat.version>
42+
<tomcat.version>8.5.9</tomcat.version>
4343
</properties>
4444

4545
<dependencies>

examples/spring-security-webmvc/pom.xml

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<slf4j.version>1.7.21</slf4j.version>
4242
<spring.version>4.3.2.RELEASE</spring.version>
4343
<spring.security.version>4.1.2.RELEASE</spring.security.version>
44-
<tomcat.version>7.0.59</tomcat.version>
44+
<tomcat.version>8.5.9</tomcat.version>
4545
</properties>
4646

4747
<dependencies>
@@ -189,38 +189,44 @@
189189
</executions>
190190
</plugin>
191191
<plugin>
192-
<groupId>org.mortbay.jetty</groupId>
193-
<artifactId>jetty-maven-plugin</artifactId>
194-
<version>8.1.16.v20140903</version>
195-
196-
<!-- https://github.com/stormpath/stormpath-sdk-java/issues/270 -->
197-
<!-- When dropping Java 1.6 support, we can switch to jetty-maven-plugin 9.3.7.v20160115 -->
198-
<!--<groupId>org.eclipse.jetty</groupId>-->
199-
<!--<artifactId>jetty-maven-plugin</artifactId>-->
200-
<!--<version>9.3.7.v20160115</version>-->
201-
192+
<groupId>org.codehaus.cargo</groupId>
193+
<artifactId>cargo-maven2-plugin</artifactId>
194+
<version>1.4.18</version>
202195
<configuration>
203-
<scanIntervalSeconds>30</scanIntervalSeconds>
204-
205-
<stopPort>8081</stopPort>
206-
<stopKey>STOP</stopKey>
207-
<daemon>true</daemon>
208-
<webApp>
209-
<contextPath>/</contextPath>
210-
</webApp>
196+
<skip>${skipITs}</skip>
197+
<container>
198+
<containerId>tomcat8x</containerId>
199+
<zipUrlInstaller>
200+
<url>
201+
http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip
202+
</url>
203+
</zipUrlInstaller>
204+
</container>
205+
<deployables>
206+
<deployable>
207+
<groupId>com.stormpath.spring</groupId>
208+
<artifactId>stormpath-sdk-examples-spring-security-webmvc</artifactId>
209+
<properties>
210+
<context>/</context>
211+
</properties>
212+
</deployable>
213+
</deployables>
214+
<configuration>
215+
<properties>
216+
<cargo.tomcat.ajp.port>8010</cargo.tomcat.ajp.port>
217+
</properties>
218+
</configuration>
211219
</configuration>
212220
<executions>
213221
<execution>
214-
<id>start-jetty</id>
222+
<id>start-server</id>
215223
<phase>pre-integration-test</phase>
216224
<goals>
217-
<!-- stop any previous instance to free up the port -->
218-
<goal>stop</goal>
219225
<goal>start</goal>
220226
</goals>
221227
</execution>
222228
<execution>
223-
<id>stop-jetty</id>
229+
<id>stop-server</id>
224230
<phase>post-integration-test</phase>
225231
<goals>
226232
<goal>stop</goal>

extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/ChangePasswordController.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import com.stormpath.sdk.servlet.form.Form;
2828
import com.stormpath.sdk.servlet.http.MediaType;
2929
import com.stormpath.sdk.servlet.http.Saver;
30+
import org.apache.http.HttpStatus;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3033

3134
import javax.servlet.http.HttpServletRequest;
3235
import javax.servlet.http.HttpServletResponse;
36+
import java.net.URLEncoder;
3337
import java.util.ArrayList;
3438
import java.util.Collections;
3539
import java.util.HashMap;
@@ -41,6 +45,8 @@
4145
*/
4246
public class ChangePasswordController extends FormController {
4347

48+
private static final Logger log = LoggerFactory.getLogger(ChangePasswordController.class);
49+
4450
private String forgotPasswordUri;
4551
private String loginUri;
4652
private String loginNextUri;
@@ -212,7 +218,7 @@ protected ViewModel onValidSubmit(HttpServletRequest request, HttpServletRespons
212218
String sptoken = form.getFieldValue("sptoken");
213219

214220
if (isJsonPreferred(request, response)) {
215-
Map<String, Object> model = new HashMap<String, Object>();
221+
Map<String, Object> model = new HashMap<>();
216222
try {
217223
Account account = application.resetPassword(sptoken, password);
218224
if (autoLogin) {
@@ -237,11 +243,22 @@ protected ViewModel onValidSubmit(HttpServletRequest request, HttpServletRespons
237243
if (autoLogin) {
238244
final AuthenticationResult result = new TransientAuthenticationResult(account);
239245
this.authenticationResultSaver.set(request, response, result);
240-
next = loginNextUri;
246+
next = this.loginNextUri;
241247
} else {
242248
next = this.nextUri;
243249
}
250+
} catch (ResourceException e) {
251+
// 404 is invalid, expired or used sptoken
252+
if (e.getCode() == HttpStatus.SC_NOT_FOUND) {
253+
next = this.errorUri;
254+
} else {
255+
// resolves https://github.com/stormpath/stormpath-sdk-java/issues/1138
256+
// TODO This breaks i18n. Fix when Stormpath backend returns specific password policy failure codes.
257+
ErrorModel errorModel = errorModelFactory.toError(request, e);
258+
next = getUri() + "?sptoken=" + sptoken + "&error=" + URLEncoder.encode(errorModel.getMessage(), "UTF-8");
259+
}
244260
} catch (Exception e) {
261+
log.error("Caught exception: {}. Redirecting to: {}", e.getMessage(), errorUri, e);
245262
next = errorUri;
246263
}
247264

extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/FormController.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
import com.stormpath.sdk.servlet.form.DefaultForm;
3131
import com.stormpath.sdk.servlet.form.Field;
3232
import com.stormpath.sdk.servlet.form.Form;
33+
import org.apache.http.HttpStatus;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
3536

3637
import javax.servlet.http.HttpServletRequest;
3738
import javax.servlet.http.HttpServletResponse;
39+
import javax.servlet.http.HttpSession;
3840
import java.util.ArrayList;
3941
import java.util.List;
4042
import java.util.Map;
@@ -130,17 +132,23 @@ protected ViewModel doGet(HttpServletRequest request, HttpServletResponse respon
130132
@SuppressWarnings("unchecked")
131133
protected Map<String,?> createModel(HttpServletRequest request, HttpServletResponse response) {
132134
List<ErrorModel> errors = null;
133-
// session null check fixes https://github.com/stormpath/stormpath-sdk-java/issues/908
134-
if (request.getParameter("error") != null && request.getSession(false) != null) {
135-
//The login page is being re-rendered after an unsuccessful authentication attempt from Spring Security
136-
//Fix for https://github.com/stormpath/stormpath-sdk-java/issues/648
137-
//See StormpathAuthenticationFailureHandler
135+
if (request.getParameter("error") != null) {
138136
errors = new ArrayList<>();
139-
ErrorModel error =
140-
(ErrorModel) request.getSession(false).getAttribute(SPRING_SECURITY_AUTHENTICATION_FAILED_KEY);
141-
if (error != null) {
142-
errors.add(error);
137+
ErrorModel error = null;
138+
HttpSession session = request.getSession(false);
139+
// session null check fixes https://github.com/stormpath/stormpath-sdk-java/issues/908
140+
if (session != null && session.getAttribute(SPRING_SECURITY_AUTHENTICATION_FAILED_KEY) != null) {
141+
//The login page is being re-rendered after an unsuccessful authentication attempt from Spring Security
142+
//Fix for https://github.com/stormpath/stormpath-sdk-java/issues/648
143+
//See StormpathAuthenticationFailureHandler
144+
error = (ErrorModel) session.getAttribute(SPRING_SECURITY_AUTHENTICATION_FAILED_KEY);
145+
} else {
146+
//Fix for https://github.com/stormpath/stormpath-sdk-java/issues/1138
147+
//TODO This breaks i18n. Fix when Stormpath backend returns specific password policy failure codes.
148+
error = ErrorModel.builder()
149+
.setStatus(HttpStatus.SC_BAD_REQUEST).setMessage(request.getParameter("error")).build();
143150
}
151+
errors.add(error);
144152
}
145153
return createModel(request, response, null, errors);
146154
}

extensions/spring/boot/stormpath-spring-security-webmvc-spring-boot-starter/pom.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
<name>Stormpath :: Spring :: Boot :: Spring Security :: Web MVC Starter</name>
2828
<description>Spring Boot WebMVC Starter for Stormpath with Spring Security</description>
2929

30-
<properties>
31-
<tomcat.version>8.5.0</tomcat.version>
32-
</properties>
33-
3430
<dependencies>
3531

3632
<dependency>
@@ -58,24 +54,6 @@
5854
<artifactId>stormpath-sdk-httpclient</artifactId>
5955
<scope>runtime</scope>
6056
</dependency>
61-
62-
<!--
63-
We need to force Tomcat 7 for the ITs to run in Java 6.
64-
Otherwise Tomcat 8.0.15 is used and it throws:
65-
javax/servlet/ServletContext : Unsupported major.minor version 51.0
66-
-->
67-
<dependency>
68-
<groupId>org.apache.tomcat.embed</groupId>
69-
<artifactId>tomcat-embed-core</artifactId>
70-
<version>${tomcat.version}</version>
71-
<scope>test</scope>
72-
</dependency>
73-
<dependency>
74-
<groupId>org.apache.tomcat.embed</groupId>
75-
<artifactId>tomcat-embed-el</artifactId>
76-
<version>${tomcat.version}</version>
77-
<scope>test</scope>
78-
</dependency>
7957
<dependency>
8058
<groupId>com.stormpath.spring</groupId>
8159
<artifactId>stormpath-spring</artifactId>

extensions/spring/boot/stormpath-webmvc-spring-boot-starter/pom.xml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
<name>Stormpath :: Spring :: Boot :: Web MVC</name>
2828
<description>Stormpath WebMVC Spring Boot Starter</description>
2929

30-
<properties>
31-
<tomcat.version>7.0.59</tomcat.version>
32-
</properties>
33-
3430
<dependencies>
3531

3632
<dependency>
@@ -75,23 +71,6 @@
7571
<artifactId>javax.servlet-api</artifactId>
7672
</dependency>
7773

78-
<!--
79-
We need to force Tomcat 7 for the ITs to run in Java 6.
80-
Otherwise Tomcat 8.0.15 is used and it throws:
81-
javax/servlet/ServletContext : Unsupported major.minor version 51.0
82-
-->
83-
<dependency>
84-
<groupId>org.apache.tomcat.embed</groupId>
85-
<artifactId>tomcat-embed-core</artifactId>
86-
<version>${tomcat.version}</version>
87-
<scope>test</scope>
88-
</dependency>
89-
<dependency>
90-
<groupId>org.apache.tomcat.embed</groupId>
91-
<artifactId>tomcat-embed-el</artifactId>
92-
<version>${tomcat.version}</version>
93-
<scope>test</scope>
94-
</dependency>
9574
<dependency>
9675
<groupId>com.stormpath.spring</groupId>
9776
<artifactId>stormpath-spring</artifactId>

extensions/spring/stormpath-spring-security-webmvc/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<name>Stormpath :: Spring :: Spring Security :: Web MVC</name>
2828
<description>Web MVC support for Stormpath-enabled Spring Security applications.</description>
2929

30+
<properties>
31+
<restassured.version>2.9.0</restassured.version>
32+
<jsoup.version>1.9.2</jsoup.version>
33+
</properties>
34+
3035
<dependencies>
3136

3237
<!-- Required dependencies: -->
@@ -92,6 +97,24 @@
9297
<artifactId>hamcrest-core</artifactId>
9398
<scope>test</scope>
9499
</dependency>
100+
<dependency>
101+
<groupId>com.jayway.restassured</groupId>
102+
<artifactId>rest-assured</artifactId>
103+
<version>${restassured.version}</version>
104+
<scope>test</scope>
105+
<exclusions>
106+
<exclusion>
107+
<groupId>commons-logging</groupId>
108+
<artifactId>commons-logging</artifactId>
109+
</exclusion>
110+
</exclusions>
111+
</dependency>
112+
<dependency>
113+
<groupId>org.jsoup</groupId>
114+
<artifactId>jsoup</artifactId>
115+
<version>${jsoup.version}</version>
116+
</dependency>
117+
95118

96119
</dependencies>
97120

0 commit comments

Comments
 (0)