Java 如何将自定义错误消息返回到KeyClope(3.4.3)中自定义spnego验证器的前端?
我正在keydove中构建一个自定义验证器,它不仅将用户登录到keydoves SSO实例中,而且还通过rest调用将用户登录到遗留(SAP-)系统中 现在,我从这个遗留API获得错误消息,我想在通过自定义身份验证程序登录时向最终用户显示这些消息(被调用方参数国际化),但我还不知道如何做到这一点 我认为这与以下几行有关: 将.error()-值更改为“test!”时,会记录此错误,但显示给用户的错误也是无效凭据行。 所以,AuthenticationFlowError似乎是一个枚举,我认为它不能处理来自第三方的动态国际化消息。但是有没有办法告诉我的authenticationcontext从我的第三方系统返回错误消息Java 如何将自定义错误消息返回到KeyClope(3.4.3)中自定义spnego验证器的前端?,java,keycloak,keycloak-services,Java,Keycloak,Keycloak Services,我正在keydove中构建一个自定义验证器,它不仅将用户登录到keydoves SSO实例中,而且还通过rest调用将用户登录到遗留(SAP-)系统中 现在,我从这个遗留API获得错误消息,我想在通过自定义身份验证程序登录时向最终用户显示这些消息(被调用方参数国际化),但我还不知道如何做到这一点 我认为这与以下几行有关: 将.error()-值更改为“test!”时,会记录此错误,但显示给用户的错误也是无效凭据行。 所以,AuthenticationFlowError似乎是一个枚举,我认为它不能
非常感谢您提供的任何帮助因此,通过查看KeyClope源代码(开源ftw!),我发现了如何做到这一点: 可以这样做,而不是上面的几行:
else {
//errorresponse from restcall to thirdparty-api (just removing prefix here)
responseString = responseString.replace("sap_error_", "");
//actually I try to do a somewhat silent idplogin, so this might fit.
//you can change this error to the errormsg from thirdparty, too,
// so its collected in the logs error=-part.
context.getEvent().error(Errors.IDENTITY_PROVIDER_ERROR);
//here we're building the actual responseHandler.
//One might even want to set the status to status from thirdparty.
Response challengeResponse = context.form().setError(responseString)
.createErrorPage(Response.Status.INTERNAL_SERVER_ERROR);
//And in the end we apply the failureChallenge to the Context
context.failureChallenge(AuthenticationFlowError.IDENTITY_PROVIDER_ERROR,
challengeResponse);
}
我对代码进行了注释,以明确所做的工作
编辑:由于这个问题刚刚获得了一个正面投票:请小心!.setError()-内容必须是有效的,有没有办法只将错误添加到表单中的单个字段,而不是创建新页面?谢谢
else {
//errorresponse from restcall to thirdparty-api (just removing prefix here)
responseString = responseString.replace("sap_error_", "");
//actually I try to do a somewhat silent idplogin, so this might fit.
//you can change this error to the errormsg from thirdparty, too,
// so its collected in the logs error=-part.
context.getEvent().error(Errors.IDENTITY_PROVIDER_ERROR);
//here we're building the actual responseHandler.
//One might even want to set the status to status from thirdparty.
Response challengeResponse = context.form().setError(responseString)
.createErrorPage(Response.Status.INTERNAL_SERVER_ERROR);
//And in the end we apply the failureChallenge to the Context
context.failureChallenge(AuthenticationFlowError.IDENTITY_PROVIDER_ERROR,
challengeResponse);
}