wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
748 stars 728 forks source link

Adaptive script client error getting logged as server errors #21084

Open Yoshani opened 2 months ago

Yoshani commented 2 months ago

Describe the Issue: Below client errors were logged as a result of client errors in the adaptive script. TID: [39009] Tenant: [xxxxxx] [2024-09-09 05:20:58,074] [20240909T052057Z-r17fd4bbf4fxbxg7xsw8rsnf700000000gdg00000000a3kt] : iam-cloud-carbon : ERROR {org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilder} - Event handler : authenticationOptions is not a function : [object Array]

TID: [39009] Tenant: [xxxxxx] [2024-09-09 05:20:57,456] [20240909T052057Z-r17fd4bbf4f6c5scnutqyq3v980000000fm000000001htcd] : iam-cloud-carbon : ERROR {org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsClaims} - Error when getting claim : http://wso2.org/claims/identity/country of user: DEFAULT/***org.wso2.carbon.user.core.UserStoreException: org.wso2.carbon.user.core.UserStoreClientException: Mapped attribute cannot be found for claim : http://wso2.org/claims/identity/country in user store : DEFAULT| at org.wso2.carbon.user.core.common.AbstractUserStoreManager.callSecure(AbstractUserStoreManager.java:264) ~[org.wso2.carbon.user.core_4.10.21.jar:?]| at

Tenant: [xxxxxx] [2024-09-10 05:15:48,820] [20240910T051548Z-r1b66d49558h9vk8w7xu77f11n0000000tag00000000dur0] : iam-cloud-carbon : ERROR {org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsLogger} - Failed to assign roles to the user.

Expected behavior: The core exception is UserStoreClientException and therefore it should not be logged as a server error.

sadilchamishka commented 2 days ago

There are occurrences in this file [1], need to decide we have to log them as errors or warnings.

[1] - https://github.com/wso2/carbon-identity-framework/blob/master/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/openjdk/nashorn/JsOpenJdkNashornGraphBuilder.java#L914

We could have catch server error and log it. When returning UserStoreClientException we can simply return null.

[2] - https://github.com/wso2/carbon-identity-framework/blob/master/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsClaims.java#L437

inthirakumaaran commented 2 days ago

AFAIU, this specific UserStoreClientException might occur due to misconfigurations or connectivity issues with remote user stores. To manage this, we can filter out UserStoreClientException using another catch block(before the UserStoreException[1]). Something similar to setLocalUserClaim in [2], but instead of logging these as errors or debug logs, they can be recorded as warnings, reducing unnecessary error noise. Additionally, we should ensure these warnings are visible in the console diagnostic logs, accessible to tenant or organization admins, as they will need to address any queries arising from end users in such cases.

+1 to change the log severity in places like [3] as well.

[1] https://github.com/wso2/carbon-identity-framework/blob/master/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsClaims.java#L437 [2] https://github.com/wso2/carbon-identity-framework/blob/master/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsClaims.java#L246 [3] https://github.com/wso2/carbon-identity-framework/blob/master/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/openjdk/nashorn/JsOpenJdkNashornGraphBuilder.java#L914

cc: @sadilchamishka @Yoshani