我使用WSO2is-5.3.0 for OIDC与自定义身份验证器和自定义声明处理程序 .
我的自定义身份验证器使用第三方Web服务对用户进行身份验证,并在响应中获得一些声明 . 自定义声明处理程序将更多声明从数据库添加到id_token . 因此,SP收到的id_token具有“服务声明”“数据库声明” .
当我只有一个服务提供商(比方说SP1)时,一切都很好 . 我的问题从这里开始:
我添加了一个SP(作为OIDC)具有相同的配置(使用相同的自定义身份验证器),称为SP2 . 当用户在SP1中登录时,WSO2IS返回带有所有声明的id_token,现在用户在其他选项卡中打开SP2并直接登录而不需要进行身份验证(感谢SSO)但.... SP2 gets only the claims from database( from custom claim handler) 和 do not 获取任何声明从自定义身份验证器返回 . WSO2的日志中没有错误 .
所以基本上我的SSO根本不起作用 . 如果需要我可以共享我的代码,但我认为这里的问题是一个错误或一些缺少配置 . 任何想法的人????
Update: 经过一个小POC后,我发现"custom claim handler"再次被调用SP2并重新计算索赔 . 由于没有调用身份验证者,因此来自第三方服务的声明为空 . 以下是代码:
自定义身份验证器:方法processAuthenticationResponse
context.setProperty("customclaim1", restResponse.customclaim1);
context.setProperty("customclaim2", restResponse.customclaim2);
context.setProperty("customclaim3", restResponse.customclaim3);
自定义声明处理程序:方法handleLocalClaims
claims.put("customclaim4", "databaseResponse.customclaim4");
claims.put("customclaim5", "databaseResponse.customclaim5");
claims.put("customclaim1", (String) context.getProperty("customclaim1"));
claims.put("customclaim2", (String) context.getProperty("customclaim2"));
claims.put("customclaim3", (String) context.getProperty("customclaim3"));
对于SP2,由于未调用身份验证器,因此“customclaim1”,“customclaim2”和“customclaim3”的上下文中没有属性 . 因此SP2只接收“customclaim4”和“customclaim5”
知道如何处理这种情况???
Note: 验证者中使用的其余服务无法更改,只有在使用正确的用户名和密码调用时才会返回声明 .
Update: 基于以上观察,我还有一些问题:
-
如果用户在WSO2中有活动会话,为什么要再次调用声明处理程序?
-
WSO2是否将这些声明存储在数据库/缓存中?我们可以使用数据库下次在自定义声明处理程序中获取声明吗?
Update
在尝试Nilasini的解决方案后,我收到了这个错误:
问题是,我没有使用任何用户来验证用户 . 在我的自定义身份验证器中,我从登录页面获得了用户名和密码,并调用了第三方身份验证服务(包含一些额外的详细信息) . 如何处理这个案子?
1 回答
是身份服务器从数据库获取声明[1] . 您可以采取的措施是,创建自定义本地声明并映射到用户存储中可用的属性 .
例如: -
然后将这些声明映射到oidc声明 .
不要忘记将oidc声明添加到注册表中 .
按照上述步骤操作后,通过 custom authenticator 分配索赔http://test.wso2.org/claims/customname的值,如下所示 .
自定义身份验证器:方法processAuthenticationResponse
然后在 custom claim handler 中只添加您想要从数据库响应中添加的声明 .
自定义声明处理程序:方法handleLocalClaims
现在,如果您使用两个服务提供商执行sso,则两个服务提供商都将收到声明“keplerNumber”,“customname” .
您可以参考[2]和[3]来使用两个OIDC应用程序测试此场景 . 按照[4]获取两个OIDC示例应用程序(playground2,playground3),然后使用两个示例应用程序执行SSO,为两个应用程序调用userinfo .
[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/handler/claims/impl/DefaultClaimHandler.java#L595
[2] https://github.com/nilasini/CustomBasicAuthenticator
[3] https://github.com/nilasini/CustomClaimHandler
[4] https://docs.wso2.com/display/IS530/Session+Management+with+Playground