【问题标题】:Redshift JDBC connection fails authentication when user password with # character in it当用户密码中包含 # 字符时,Redshift JDBC 连接身份验证失败
【发布时间】:2017-08-23 11:16:45
【问题描述】:

我遇到了与 Redshift 的 JDBC 连接问题,我无法完全解决。使用文档中给出的示例,当用户使用纯密码时,我可以轻松连接到 Redshift 集群,但是当用户的密码中包含 # 字符时,我会遇到身份验证失败。我可以使用两组凭据使用 SQL Workbench/J 连接到集群。当我使用以下时,没有连接问题。

        DriverManager.setLoginTimeout(60);
        Properties props = new Properties();
        props.setProperty("user", "johndoe");
        props.setProperty("password", "superSecret");
        props.setProperty("tcpKeepAlive", "true");

        Connection connection = DriverManager.getConnection("jdbc:redshift://xxxxxxx.us-east-1.redshift.amazonaws.com:5439/dev", props);

当我使用以下内容时,

        DriverManager.setLoginTimeout(60);
        Properties props = new Properties();
        props.setProperty("user", "johndoehash");
        props.setProperty("password", "superDouble#Secret");
        props.setProperty("tcpKeepAlive", "true");

        Connection connection = DriverManager.getConnection("jdbc:redshift://xxxxxxx.us-east-1.redshift.amazonaws.com:5439/dev", props);

我收到身份验证错误

java.sql.SQLException: [Amazon](500310) Invalid operation: password authentication failed for user "johndoehash";
  at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(ErrorResponse.java:1830)
  at com.amazon.redshift.client.InboundDataHandler.read(InboundDataHandler.java:454)
  at com.amazon.support.channels.AbstractSocketChannel.readCallback(Unknown Source)
  at com.amazon.support.channels.PlainSocketChannel.read(Unknown Source)
Caused by: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: password authentication failed for user "johndoehash";

我可以使用 SQL Workbench/J 使用两个帐户登录集群,但由于某种原因,我无法通过我的应用程序进行连接。关于我做错了什么有什么想法吗?

【问题讨论】:

  • 您可以尝试将密码分配给一个变量,然后在 setproperty 中传递该密码。
  • 是的,我已经这样做了并且得到了相同的结果。考虑到 # 可能会因为它在 http 中的使用而导致某种问题(??只是一个猜测)我试过 URLEncoder.encode(password, "UTF8") 效果没有区别。
  • 对不起,我没有确切的解决方案,我不了解java,只是猜测,但有什么帮助,对吧?您是否尝试过使用 CHR(35)?

标签: java jdbc amazon-redshift


【解决方案1】:

我没有足够的积分来评论。我不知道这是否能解决你的问题。但是试试这个:

props.setProperty("密码", "superDouble& #35;Secret");

“&”和“#35;”之间没有空格

或者

props.setProperty("密码", "superDouble%23Secret");

【讨论】:

  • 我在密码上尝试了各种编码和转义,但没有任何效果。在云雀上,我也试过你的,可悲的是它没有任何区别。我开始怀疑它在于驱动程序的依赖项。我将探讨我的应用程序与其他可以成功使用带有# 的密码的应用程序之间的依赖关系差异。
【解决方案2】:

这真的很奇怪,但如果我在我的应用程序中使用一年前的 Java 8 版本

java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

问题消失了……去看看。

【讨论】:

    猜你喜欢
    • 2014-05-18
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2020-12-09
    • 2010-09-12
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    相关资源
    最近更新 更多