简体   繁体   English

WSO2 身份服务器自定义错误消息

[英]WSO2 Identity Server Custom error message

We are using WSO2 Identity Server 5.8.0.我们正在使用 WSO2 身份服务器 5.8.0。

We have made an extension to the org.wso2.carbon.identity.application.authenticator.samlsso.manager.DefaultSAML2SSOManager located in the project identity-outbound-auth-samlsso我们对位于项目identity-outbound-auth-samlssoorg.wso2.carbon.identity.application.authenticator.samlsso.manager.DefaultSAML2SSOManager进行了扩展

Basically we need to add some checks to the SAML Response when we use external IdPs based on SAML authentication.基本上,当我们使用基于 SAML 身份验证的外部 IdP 时,我们需要向 SAML 响应添加一些检查。

We made all the checks and all works good.我们进行了所有检查,一切正常。 We are facing one little issue.我们正面临一个小问题。 In some cases, when some access errors happem, we need to customize the error message to the user.在某些情况下,当发生一些访问错误时,我们需要自定义错误消息给用户。 I saw here I saw it's possible to customize error message and it's possible to configure WSO2 IS in order to pass error code in request param.我在这里看到我看到可以自定义错误消息,并且可以配置 WSO2 IS 以便在请求参数中传递错误代码。 So, what I wanted to do is to generate custom error code when one error happens.所以,我想做的是在发生一个错误时生成自定义错误代码。 I tried the previous configuration and then in the org.wso2.carbon.identity.application.authenticator.samlsso.SAMLSSOAuthenticator class I did the following我尝试了之前的配置,然后在org.wso2.carbon.identity.application.authenticator.samlsso.SAMLSSOAuthenticator class 我做了以下

@Override
protected void processAuthenticationResponse(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException {
    try{
        //Original code
    } catch (SPIDCheckException spe) {
        // whenever the code reaches here the subject identifier will be null. Therefore we can't pass AuthenticatedUser object with the exception. 
        AuthenticationFailedException afe = new AuthenticationFailedException(spe.getMessage(), spe);
        afe.setErrorCode("MY_CUSTOM_ERROR_CODE");
        throw afe;          
    } 
}

I was expecting that with the previous configuration my custom cose would apper in request parameter but it's not so.我期待在以前的配置中,我的自定义 cose 会出现在请求参数中,但事实并非如此。 So I had to find a workaround;所以我必须找到一种解决方法; my solution was to add a cookie to the response but I don't like it.我的解决方案是在响应中添加一个 cookie,但我不喜欢它。

Is there any chance to propagate a custom error code from SAMLSSOAuthenticator to the login error JSP page in a query string param?是否有机会将自定义错误代码从SAMLSSOAuthenticator传播到查询字符串参数中的登录错误 JSP 页面?

Am I missing anything?我错过了什么吗?

Thank you谢谢

Angelo安杰洛

         context.setProperty("AuthErrorCode", "666");
         context.setProperty("AuthErrorMessage", "extended class error message");

Set above in side the processAuthenticationResponse method's catch block.在上面的processAuthenticationResponse方法的 catch 块中设置。 Parameters will be passed to the retry page URL params.参数将传递给重试页面 URL 参数。

EDIT to cater new details of the comment.编辑以迎合评论的新细节。

The flow is as 'SAML -> SAML'.流程为“SAML -> SAML”。 But the above suggested improvement was only introduced in 'Oauth -> SAML/Oauth' flows.但上述建议的改进仅在“Oauth -> SAML/Oauth”流程中引入。 This was initially introduced to 5.3.0.这最初是在 5.3.0 中引入的。 But, I've just checked 5.8.0 as well, and it's there.但是,我也刚刚检查了 5.8.0,它就在那里。

The architecture is like this.架构是这样的。

Inbound Authenticator -> Framework -> Outbound Authenticator

In the original improvement, WSO2 has fixed the framework component and inbound Oauth components.在原来的改进中,WSO2 修复了框架组件和入站 Oauth 组件。 So that anyone can set those properties to the framework context.这样任何人都可以将这些属性设置为框架上下文。 And those will be propogated to the Inbound side.这些将被传播到入站端。 And if the inbound is Oauth, this will work by default as Oauth Inbound authenticator is also being addressed fro the same improvement.如果入站是 Oauth,则默认情况下这将起作用,因为 Oauth 入站验证器也正在通过相同的改进得到解决。

Since your inbound is not Oauth, but SAML, your default SAML inbound authenticator doesn't know how to read the set properties from the framework's context object.由于您的入站不是 Oauth,而是 SAML,因此您的默认 SAML 入站身份验证器不知道如何从框架的上下文 object 中读取设置的属性。

If you want to achieve this, you need to write a custom 'Inbound SAML Authenticator' as well.如果您想实现这一点,您还需要编写一个自定义的“入站 SAML 身份验证器”。 (As of now you've written an outbound SAML authenticator. We need that as well to populate the error message.) (到目前为止,您已经编写了一个出站 SAML 身份验证器。我们也需要它来填充错误消息。)

Extend the existing SAML inbound authenticator and write a new authenticator to read and set the error message.扩展现有的 SAML 入站身份验证器并编写一个新的身份验证器来读取和设置错误消息。

Improvement改进

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM