WSO2 身份服务器 (WSO2IS) SSO 登录的自定义身份验证器
💡一则或许对你有用的小广告
欢迎加入小哈的星球 ,你将获得:专属的项目实战(已更新的所有项目都能学习) / 1v1 提问 / Java 学习路线 / 学习打卡 / 每月赠书 / 社群讨论
- 新开坑项目:《Spring AI 项目实战》 正在持续爆肝中,基于 Spring AI + Spring Boot 3.x + JDK 21..., 点击查看 ;
- 《从零手撸:仿小红书(微服务架构)》 已完结,基于
Spring Cloud Alibaba + Spring Boot 3.x + JDK 17...,点击查看项目介绍 ;演示链接: http://116.62.199.48:7070 ;- 《从零手撸:前后端分离博客项目(全栈开发)》 2 期已完结,演示链接: http://116.62.199.48/ ;
截止目前, 星球 内专栏累计输出 100w+ 字,讲解图 4013+ 张,还在持续爆肝中.. 后续还会上新更多项目,目标是将 Java 领域典型的项目都整一波,如秒杀系统, 在线商城, IM 即时通讯,权限管理,Spring Cloud Alibaba 微服务等等,已有 3700+ 小伙伴加入学习 ,欢迎点击围观
在 sso 登录中,您可以将不同的自定义身份验证器插入 wso2is。有两种主要类型。一种是本地验证器,另一种是联合验证器。当您需要向另一个 idp 提供基于浏览器的重定向时,就需要联合身份验证器。例如 salesforce、google、facebook idps。 (更多细节来自 这里 )。在其他情况下,我们可以实现本地验证器。
wso2is 的默认身份验证器是基本身份验证器,它也是本地身份验证器,使用提供的用户名和密码对连接的用户存储的最终用户进行身份验证。
在这篇文章中,让我们尝试通过扩展基本身份验证器来为 wso2is 实现本地身份验证器。
让我们采取以下两个示例要求。
1. 使用“openid connect”登录的用户必须通过用户存储进行身份验证,并且必须获得授权。在授权中,必须验证用户是否已分配给名为“openidconnectrole”的特定角色
2. 来自应用程序(服务提供商)“soasecurity.org”的用户必须通过用户存储进行身份验证并且必须获得授权。在授权中,必须验证用户是否包含特定属性。例如,用户包含域为“soasecurity.org”的邮件
第 1 步 。扩展基本验证器并实现新的验证器。
由于我们只担心授权,因此可以在基本身份验证器级别进行身份验证。我们需要在认证后添加授权逻辑。因此我们只需要在基本认证器中扩展一个方法,即 “processauthenticationresponse()”
此外,我们需要通过扩展 “getfriendlyname() ”和 “getname()” 方法来修改身份验证器名称。
您可以从 此处 对扩展验证器源进行罚款。
第 2 步 。从您的扩展身份验证器创建 osgi 包。可以从 这里 找到示例项目。您可以使用 maven3 构建项目
第 3 步。 通过复制到 /repository/components/dropins 目录,在 wso2 身份服务器(或 apim)中部署 osgi 包。
第 4 步。 您需要使用新的身份验证器名称编辑 /repository/deployment/server/webapps/authenticationendpoint/login.jsp 页面。
因为目前它被设置为“basicauthenticator”。您可以通过添加检查“basiccustomauthenticator”来修改它如下
if(localauthenticatornames.contains("basicauthenticator") | localauthenticatornames.contains("basiccustomauthenticator")){
if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || } else if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || localauthenticatornames.contains("basiccustomauthenticator"))) {localauthenticatornames.contains("basiccustomauthenticator"))) {
第 5 步 。 (可选) 如果您需要将其作为所有服务提供商的默认身份验证器,您可以使用 /repository/conf/identity/service-providers/default.xml 文件对其进行配置。
此文件默认配置为“basicauthenticator”...您可以通过更改以下两个属性将其修改为“basiccustomauthenticator”。
if(localauthenticatornames.contains("basicauthenticator") | localauthenticatornames.contains("basiccustomauthenticator")){
if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || } else if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || localauthenticatornames.contains("basiccustomauthenticator"))) {localauthenticatornames.contains("basiccustomauthenticator"))) {
进入
if(localauthenticatornames.contains("basicauthenticator") | localauthenticatornames.contains("basiccustomauthenticator")){
if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || } else if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || localauthenticatornames.contains("basiccustomauthenticator"))) {localauthenticatornames.contains("basiccustomauthenticator"))) {
步骤 6. 重新启动服务器。
第 7 步 。您可以登录管理控制台并使用 “本地和出站身份验证配置” 为每个服务提供商配置新的身份验证器
步骤 8. 试用。
您可以通过在调试模式下启动服务器来调试自定义身份验证器源。
if(localauthenticatornames.contains("basicauthenticator") | localauthenticatornames.contains("basiccustomauthenticator")){
if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || } else if(localauthenticatornames.size()>0 && (localauthenticatornames.contains("basicauthenticator") || localauthenticatornames.contains("basiccustomauthenticator"))) {localauthenticatornames.contains("basiccustomauthenticator"))) {
谢谢阅读…!!!