Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

spring mvc - Authentication-Flows: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

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) enter image description here

(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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are right; indeed it is a bug (since 2014...)

https://github.com/OhadR/Authentication-Flows/issues/13

However though, I've just try to reproduce it (forgot-password flow), and it works fine! Here is a link to YouTube, so you can see exactly what I did...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...