关于sap:SAP-电商云-Spartacus-UI-userID-即邮件地址中的加号问题

3次阅读

共计 1726 个字符,预计需要花费 5 分钟才能阅读完成。

如果用户登录名或明码蕴含符号 +,它将被替换为空格,因为 Content-Type 等于 application/x-www-form-urlencoded。

上面是一个例子:

https://<host>:9002/occ/v2/electronics-spa/forgottenpasswordtokens?lang=en&curr=USD

我输出了蕴含 + 号的邮件地址后,点击 Submit,发送一个 HTTP POST 申请到后盾,响应为 202:

从 Form Data 区域,咱们能够发现,这个 userId 显示为 a @sap.com, 邮箱地址里蕴含了空格符号:

找到 Reset Password Component 的 selector:cx-forgot-password

Component 名称为:ForgotPasswordComponent

通过 Service 实现:

依赖于 UserPasswordFacade:

调用 userProfileConnector 实现:

connector 调用 userProfileAdapter:

这是一个 abstract class,咱们调用 OCCUserProfileAdapter 实现:

OccUserProfileAdapter 最终调用 HTTP Client 的 post 操作:

咱们在后盾打印 Angular HTTP client 发送过去的申请,发现的确 + 号被转换成了空格:

https://github.com/angular/an…

这个文件首先应用浏览器的 encodeURIComponent() 办法,但随后复原了几个字符的编码,包含 + 号。

一种比拟正当的设计是:

感激 @meeque 参加探讨这个话题。Angular 的确不反对洁净的编码 / 解码,这就是为什么咱们没有为各种字符(@:$,;+=?/)取得正确的编码。我浏览了与此主题相干的各种资源,但我不确定为什么会跳过这些字符。

  • 实现一个仅应用来自浏览器的 encodeURIComponent 和 decodeURIComponent 的 HttpParameterCodec
  • 在咱们应用 HttpParameters 的任何中央都应用编码器,但至多在创立用户和明码方面
  • 容许通过 DI 或通过在配置模块中配置类来笼罩此行为

能够先在前台进行 encode:

const pass = encodeURIComponent(password.value);
this.auth.authorize(userId.value.toLowerCase(), pass);

而后在 Hybris 后盾 decode:

if (credential instanceof String) {
    // if credential is a string use URLDecode class. 
    credential = URLDecoder.decode(String.valueOf(credential), StandardCharsets.UTF_8);
    if (!user.checkPassword((String) credential)) {throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
    }
} else {if (!(credential instanceof LoginToken)) {throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
    }
   if (!user.checkPassword((LoginToken) credential)) {throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
     }
}

后续修复进度,请跟踪这个 Github issue.

正文完
 0