【问题标题】:Authentication-Flows: java.lang.StringIndexOutOfBoundsException: String index out of range: -1身份验证流:java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-1
【发布时间】:2017-08-21 10:18:18
【问题描述】:

我指的是 OhadR 的项目,他正在使用 Spring 安全性通过电子邮件登录并设置新密码。 这个链接:

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

我已经完成了一些步骤:

1. create account
2. confirm account by email
3. login sucess
4. change or set new password (this step happened exception)

但是当我输入新密码并确认新密码时,我收到如下异常:

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)

这是范围代码导致异常:

@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;
}

设置要调试的值:(更新

更新

调试时获取和设置值: 电子邮件中的链接值:

http://localhost:9999/rp?uts=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw

当点击此链接时,它将重定向到 URL(设置新密码屏幕):

http://localhost:9999/login/setNewPassword.jsp?enc=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw

然后在调试的encUserAndTimestamp参数中输入值

最后,我收到一条消息错误:

Failed to decrypt URL content http://localhost:9999/login/setNewPassword.jsp?enc=ap0wGvPL56FiYbMshHLe5Yh5PWEkz/kWEbJA32uJPSxw

我的网址好像错了!!

如何解决这个异常,非常感谢!

【问题讨论】:

  • 嗨@OhadR:我已经在调试中设置了值并且它出现了,我已经更新了图片..
  • 我还是看不到 encUserAndTimestamp 的值...
  • 是 encUserAndTimestamp 的值为空或 null,如何获取 encUserAndTimestamp 的值?
  • 我已经尝试获取 encUserAndTimestamp 的值,但不能,似乎这是一个错误 :(
  • 嗨@OhadR:我已经更新了我的结果

标签: spring-mvc spring-security authentication-flows


【解决方案1】:

你是对的;确实这是一个错误(自 2014 年以来...)

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

不过,我只是尝试重现它(忘记密码流程),它工作正常! Here is a link to YouTube,所以你可以确切地看到我做了什么......

【讨论】:

  • 嗨@OhadR:我回来了,因为我之前丢失了密码,我正在关注你在 youtube 上的链接
  • 一切都很好,如果你改进更多的欢迎屏幕和注销会很棒:)
猜你喜欢
  • 2019-05-22
  • 2012-03-02
  • 1970-01-01
  • 2012-08-02
  • 2016-02-25
  • 2018-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多