diff --git a/common/src/main/java/org/cloudfoundry/identity/uaa/codestore/ExpiringCodeStore.java b/common/src/main/java/org/cloudfoundry/identity/uaa/codestore/ExpiringCodeStore.java
index e9ba15d3246..483a9899089 100644
--- a/common/src/main/java/org/cloudfoundry/identity/uaa/codestore/ExpiringCodeStore.java
+++ b/common/src/main/java/org/cloudfoundry/identity/uaa/codestore/ExpiringCodeStore.java
@@ -12,10 +12,10 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.codestore;
-import java.sql.Timestamp;
-
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
+import java.sql.Timestamp;
+
public interface ExpiringCodeStore {
/**
@@ -26,7 +26,7 @@ public interface ExpiringCodeStore {
* @throws java.lang.NullPointerException if data or expiresAt is null
* @throws java.lang.IllegalArgumentException if expiresAt is in the past
*/
- public ExpiringCode generateCode(String data, Timestamp expiresAt);
+ ExpiringCode generateCode(String data, Timestamp expiresAt);
/**
* Retrieve a code and delete it if it exists.
@@ -35,12 +35,12 @@ public interface ExpiringCodeStore {
* @return code or null if the code is not found
* @throws java.lang.NullPointerException if the code is null
*/
- public ExpiringCode retrieveCode(String code);
+ ExpiringCode retrieveCode(String code);
/**
* Set the code generator for this store.
*
* @param generator Code generator
*/
- public void setGenerator(RandomValueStringGenerator generator);
+ void setGenerator(RandomValueStringGenerator generator);
}
diff --git a/login/src/main/java/org/cloudfoundry/identity/uaa/login/ResetPasswordController.java b/login/src/main/java/org/cloudfoundry/identity/uaa/login/ResetPasswordController.java
index 3f16ff58ba2..db9df9ddb05 100644
--- a/login/src/main/java/org/cloudfoundry/identity/uaa/login/ResetPasswordController.java
+++ b/login/src/main/java/org/cloudfoundry/identity/uaa/login/ResetPasswordController.java
@@ -16,6 +16,8 @@
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.identity.uaa.authentication.Origin;
import org.cloudfoundry.identity.uaa.authentication.UaaPrincipal;
+import org.cloudfoundry.identity.uaa.codestore.ExpiringCode;
+import org.cloudfoundry.identity.uaa.codestore.ExpiringCodeStore;
import org.cloudfoundry.identity.uaa.error.UaaException;
import org.cloudfoundry.identity.uaa.scim.ScimUser;
import org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException;
@@ -36,9 +38,9 @@
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
-import java.util.Map;
-import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
+import java.sql.Timestamp;
+import java.util.regex.Pattern;
@Controller
public class ResetPasswordController {
@@ -50,14 +52,21 @@ public class ResetPasswordController {
private final UaaUrlUtils uaaUrlUtils;
private final String brand;
private final Pattern emailPattern;
-
- public ResetPasswordController(ResetPasswordService resetPasswordService, MessageService messageService, TemplateEngine templateEngine, UaaUrlUtils uaaUrlUtils, String brand) {
+ private final ExpiringCodeStore codeStore;
+
+ public ResetPasswordController(ResetPasswordService resetPasswordService,
+ MessageService messageService,
+ TemplateEngine templateEngine,
+ UaaUrlUtils uaaUrlUtils,
+ String brand,
+ ExpiringCodeStore codeStore) {
this.resetPasswordService = resetPasswordService;
this.messageService = messageService;
this.templateEngine = templateEngine;
this.uaaUrlUtils = uaaUrlUtils;
this.brand = brand;
emailPattern = Pattern.compile("^\\S+@\\S+\\.\\S+$");
+ this.codeStore = codeStore;
}
@RequestMapping(value = "/forgot_password", method = RequestMethod.GET)
@@ -139,8 +148,20 @@ public String emailSentPage(@ModelAttribute("code") String code) {
}
@RequestMapping(value = "/reset_password", method = RequestMethod.GET, params = { "email", "code" })
- public String resetPasswordPage() {
- return "reset_password";
+ public String resetPasswordPage(Model model,
+ HttpServletResponse response,
+ @RequestParam("code") String code,
+ @RequestParam("email") String email) {
+
+ ExpiringCode expiringCode = codeStore.retrieveCode(code);
+ if (expiringCode==null) {
+ return handleUnprocessableEntity(model, response, "message_code", "bad_code");
+ } else {
+ Timestamp fiveMinutes = new Timestamp(System.currentTimeMillis()+(1000*60*5));
+ model.addAttribute("code", codeStore.generateCode(expiringCode.getData(), fiveMinutes).getCode());
+ model.addAttribute("email", email);
+ return "reset_password";
+ }
}
@RequestMapping(value = "/reset_password.do", method = RequestMethod.POST)
@@ -162,11 +183,9 @@ public String resetPassword(Model model,
try {
ScimUser user = resetPasswordService.resetPassword(code, password);
-
UaaPrincipal uaaPrincipal = new UaaPrincipal(user.getId(), user.getUserName(), user.getPrimaryEmail(), Origin.UAA, null, IdentityZoneHolder.get().getId());
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(uaaPrincipal, null, UaaAuthority.USER_AUTHORITIES);
SecurityContextHolder.getContext().setAuthentication(token);
-
return "redirect:home";
} catch (UaaException e) {
return handleUnprocessableEntity(model, response, "message_code", "bad_code");
diff --git a/login/src/main/resources/login-ui.xml b/login/src/main/resources/login-ui.xml
index a77eb407086..ec61839a649 100644
--- a/login/src/main/resources/login-ui.xml
+++ b/login/src/main/resources/login-ui.xml
@@ -470,6 +470,7 @@
+
@@ -477,7 +478,7 @@
-
+
diff --git a/login/src/main/resources/templates/web/reset_password.html b/login/src/main/resources/templates/web/reset_password.html
index 2f57d9ecfb7..4b5c4eb7cb4 100644
--- a/login/src/main/resources/templates/web/reset_password.html
+++ b/login/src/main/resources/templates/web/reset_password.html
@@ -8,10 +8,10 @@
Reset Password
-
Email: user@example.com
+
Email: user@example.com