I'm refer to project of OhadR, He is using Spring security to login and set new password by email.
this link:
Authentication-Flows: https://github.com/OhadR/Authentication-Flows
I have finished some steps as:
1. create account
2. confirm account by email
3. login sucess
4. change or set new password (this step happened exception)
But when I input new password and confirm new password, I received an exception following as:
SEVERE: Servlet.service() for servlet [action] in context with path [] threw exception [Request processing failed; nested exception is java.lang.StringIndexOutOfBoundsException: String index out of range: -1] with root cause
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at com.ohadR.web.crypto.service.CryptoService.getDecodedStringFromEncodedBased64String(CryptoService.java:244)
at com.ohadR.web.crypto.service.CryptoService.extractStringAndDate(CryptoService.java:107)
at com.ohadR.web.auth_flows.core.AuthenticationFlowsProcessorImpl.handleSetNewPassword(AuthenticationFlowsProcessorImpl.java:279)
at com.ohadR.web.auth_flows.web.UserActionController.setNewPassword(UserActionController.java:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
This is scope code cause exception:
@Override
public String handleSetNewPassword(
String encUserAndTimestamp,
String password,
String retypedPassword) throws AuthenticationFlowsException
{
validateRetypedPassword(password, retypedPassword);
ImmutablePair<Date, String> stringAndDate =
cryptoService.extractStringAndDate( encUserAndTimestamp );
validateExpiration(stringAndDate.getLeft());
String email = stringAndDate.getRight();
//after validations, make the work: validate password constraints, and update DB:
//validate the input:
AuthenticationPolicy settings = getAuthenticationSettings();
validatePassword(password, settings);
String encodedPassword = encodeString(email, password);
// go to the DB and: (1) update the password, and (2) activate the account:
setPassword(email, encodedPassword);
return email;
}
Set values to debug: (Updated)
(Updated)
get and set value when debug:
value of link in email:
http://localhost:9999/rp?uts=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw
When click this link, it will redirect to URL(set new password screen):
http://localhost:9999/login/setNewPassword.jsp?enc=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw
and then input value in encUserAndTimestamp parameter in debug
finally, I received an message error:
Failed to decrypt URL content http://localhost:9999/login/setNewPassword.jsp?enc=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw
It seem my URL is wrong !!
How to fix this exception, thank so much!
See Question&Answers more detail:
os