用户登录身份验证失败-WSO2身份服务器

时间:2019-09-10 13:36:49

标签: mysql jdbc oauth-2.0 wso2 wso2is

我们正在根据 Secondary Userstore(JDBC Userstore)创建用户。同样,我们在API Store中创建了一个名为MyApplication的应用程序。当用户尝试通过调用WSO2提供的MyApplication API来登录该/token时,即使使用正确的用户名(格式为 TESTDOMAIN / testuser )和密码,也要使用该API。有时通过返回带有400 Bad Request的响应来使登录失败:

 {
        "error_description": "Error when handling event : PRE_AUTHENTICATION",
        "error": "invalid_grant"
 }

而且,在IDM Audit.log中,错误如下所示:

WARN {AUDIT_LOG}-  Initiator=wso2.system.user Action=Authentication Target=TESTDOMAIN/testuser Data=null Outcome=Failure  Error={"Error Message":"Un-expected error while pre-authenticating, Error when handling event : PRE_AUTHENTICATION","Error Code":"31002"}

尝试5次用户登录后,用户可以成功登录,没有任何问题。 我没有任何线索,也不了解为什么这种登录失败是随机发生的。

请提供有关此问题的解决方案/想法。

已更新:

启用用户核心调试日志和一些其他与此问题似乎相关的日志之后。在身份验证失败期间,我可以看到以下wso2carbon.log:

DEBUG {org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager} -  Error occurred while checking existence of values.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 733,140 milliseconds ago.  The last packet sent successfully to the server was 733,140 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        Caused by: java.net.SocketException: Connection reset
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
        ... 113 more
DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} -  Error occurred while validating grant
org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception: Error when handling event : PRE_AUTHENTICATION
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 733,140 milliseconds ago.  The last packet sent successfully to the server was 733,140 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

1 个答案:

答案 0 :(得分:1)

如@senthalan在评论中所述,让我们尝试在连接URL的末尾添加“ autoReconnect = true”。

此外,请在master-datasources.xml中验证您的MySQL数据源的连接配置下是否具有以下建议值。 (如[1]中所述)

<definition type="RDBMS">
   <configuration>
       <url>jdbc:mysql://localhost:3306/umdb?autoReconnect=true</url>
       <username>regadmin</username>
       <password>regadmin</password>
       <driverClassName>com.mysql.jdbc.Driver</driverClassName>
       <maxActive>80</maxActive>
       <maxWait>60000</maxWait>
       <minIdle>5</minIdle>
       <testOnBorrow>true</testOnBorrow>
       <validationQuery>SELECT 1</validationQuery>
       <validationInterval>30000</validationInterval>
       <defaultAutoCommit>false</defaultAutoCommit>

此外,如[2]中所述,我们可以从数据库侧增加max_connections的数量。

mysql> SET GLOBAL max_connections = 500;
Query OK, 0 rows affected (0.00 sec)

[1] https://docs.wso2.com/display/ADMIN44x/Changing+to+MySQL

[2] https://stackoverflow.com/a/19991390/2910841