【问题标题】:Custom "statusMsg" not working as expected自定义 \"statusMsg\" 未按预期工作
【发布时间】:2022-11-11 13:02:11
【问题描述】:

添加以下自适应身份验证脚本后,如果用户名不符合格式,我应该会收到自定义状态消息,Access Denied, invalid username format. 但我会收到默认状态消息,Something went wrong during the authentication process. Please try signing in again.

function onLoginRequest(context) {
    executeStep(1, {
        onSuccess: function(context) {
            var user = context.currentKnownSubject;
            if(user!= null && user.username != null && !user.username.equals('')) {
                Log.info("username: " + user.username);
            } else {
                sendError('',{'status':'AUTHENTICATION USERNAME ERROR', 'statusMsg': 'Access denied, invalid username format.'});
            }
        }
    });
}

此外,wso2carbon.log 文件中也出现以下错误。

TID: [-1234] [authenticationendpoint] [2022-10-05 15:44:12,715] [37951f7d-8240-48d4-ad4f-1d4c8a6a3ec4] ERROR {org.wso2.carbon.identity.application.authentication.endpoint.util.AuthContextAPIClient} - Sending GET request to URL : https://dev.wso2istemp.com/api/identity/auth/v1.1/data/AuthenticationError/0b0efc37-819d-4b39-85b2-517126c3c9cb, failed. java.io.IOException: Server returned HTTP response code: 401 for URL: https://dev.wso2istemp.com/api/identity/auth/v1.1/data/AuthenticationError/0b0efc37-819d-4b39-85b2-517126c3c9cb
...
org.wso2.carbon.identity.application.authentication.endpoint.util.AuthContextAPIClient.getContextProperties(AuthContextAPIClient.java:70)
        at org.apache.jsp.retry_jsp._jspService(retry_jsp.java:194)
...
org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter.doFilter(ContentTypeBasedCachePreventionFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
...
org.wso2.carbon.identity.application.authentication.endpoint.util.filter.AuthenticationEndpointFilter.doFilter(AuthenticationEndpointFilter.java:190)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
...

[server] 的 <IS_HOME>/repository/conf/deployment.toml 配置如下。

[server]
hostname = "dev.wso2istemp.com"
node_ip = "127.0.0.1"
base_path = "https://$ref{server.hostname}:${carbon.management.port}"

wso2carbon.log 中出现以下问题的原因是什么以及自定义状态消息未正确显示的原因是什么?

【问题讨论】:

    标签: wso2 wso2-identity-server


    【解决方案1】:

    运行自适应身份验证脚本时,这些值将被传递到加密的 Identity Server(IS)。在上述情况下,加密的数据块被传递给 IS,

    https://dev.wso2istemp.com/api/identity/auth/v1.1/data/AuthenticationError/24e56d99-9494-4989-a3e2-4008b73ebd9b

    URL的最后一段是数据块。当服务器尝试通过 GET 请求获取该数据块时,会抛出未经授权的代码 java.io.IOException: Server returned HTTP response code: 401 for URL。由于未正确接收该数据块,因此将显示默认状态消息而不是自定义状态消息。下面给出了解决此问题的步骤。

    1. 首先明确你使用的dev.wso2istemp.com是否没有映射到/etc/hosts文件中的localhost。
    2. 转到<IS_HOME>/repository/conf/deployment.toml文件并检查以下配置[identity.auth_framework.endpoint]并通过mutual_ssl_manager_enabled=false检查双向SSL是否设置为false
    3. 如果是这样,请通过评论 mutual_ssl_manager_enabled=false 启用它,因为建议对 IS 使用相互 SSL。如果你去<IS_HOME>/repository/resources/conf/default.json file,你会注意到mutual_ssl_manager_enabled的默认值是true
    4. 在多节点的情况下,如果没有启用双向 SSL,可能会出现上述错误,如果不能解决问题,则必须检查 internal_hostname 是否已正确设置,以便内部 API呼叫正在正确发送。
    5. 为此,如果您尚未将以下配置添加到<IS_HOME>/repository/conf/deployment.toml 文件中,您可以通过检查<ServerHostName>localhost</ServerHostName> 来检查它是否已正确应用于<IS_HOME>/repository/conf/identity/identity.xml
      [server]
      internal_hostname="localhost"
      
      1. 如果您使用的是多节点部署,则应在生成证书时将此 localhost 值添加到证书的 SAN (-ext SAN=dns:localhost)
      keytool -genkey -alias newcert -keyalg RSA -keysize 2048 -keystore newkeystore.jks -dname "CN=dev.wso2istemp.com, OU=Is,O=Wso2,L=SL,S=WS,C=LK" -storepass mypassword -keypass mypassword -ext SAN=dns:localhost
      
      1. 但是如果您使用的是单个节点,您可以将以下配置添加到deployment.toml 并检查它是否可以解决问题。 (在单节点情况下,internal_hostname 应该类似于hostname)
      [server]
      hostname = "dev.wso2istemp.com"
      internal_hostname = "dev.wso2istemp.com"
      
      1. 如果这不起作用[https://github.com/wso2/product-is/issues/11878] 然后转到<IS_HOME>/repository/deployment/server/webapps/authenticationendpoint/WEB-INF/web.xml 并取消注释以下注释的sn-p。
      <!--context-param>
          <param-name>AuthenticationRESTEndpointURL</param-name>
          <param-value>https://localhost:9443/api/identity/auth/v1.1/</param-value>
      </context-param-->
      
      1. 这可能会路由 internal_hostname 反映在请求上,因为当服务器的 hostname 被替换而不是内部 API 调用的 internal_hostname (https://dev.wso2istemp.com/api/identity/auth/v1.1/data/AuthenticationError/24e56d99-9494-4989-a3e2-4008b73ebd9b) 时,内部 API 调用被阻止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-09
      • 2017-01-01
      • 2021-10-22
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      相关资源
      最近更新 更多