WSO2 XACML如何获取自定义属性并复用认证请求参数执行策略?
实现方案
以下两种方案均可满足需求,可根据业务对属性时效性的要求选择:
方案1:认证阶段透传参数(改造成本最低)
直接在现有自定义联邦认证器的认证流程中,把所需参数和接口返回的属性提前存入认证用户的临时属性,透传到XACML授权环节:
- 先在WSO2 Identity Server中创建3个自定义声明,声明URI可自定义为:
http://your-org.org/claims/request-iphttp://your-org.org/claims/request-idhttp://your-org.org/claims/appname
- 修改你现有代码的
processAuthenticationResponse方法,将三个请求参数和调用callGetUserAttributes返回的属性都加入用户属性集合:
// 原有代码中初始化claims Map后添加以下逻辑 String requestIp = httpServletRequest.getRemoteHost(); String requestId = httpServletRequest.getParameter(CustomFedAuthenticatorConstants.ID); String appName = httpServletRequest.getParameter(CustomFedAuthenticatorConstants.APPNAME); // 写入三个请求参数到用户属性 claims.put(ClaimMapping.build("http://your-org.org/claims/request-ip", "http://your-org.org/claims/request-ip", null, true), requestIp); claims.put(ClaimMapping.build("http://your-org.org/claims/request-id", "http://your-org.org/claims/request-id", null, true), requestId); claims.put(ClaimMapping.build("http://your-org.org/claims/appname", "http://your-org.org/claims/appname", null, true), appName); // 如需提前拉取XACML所需用户属性,调用接口后也直接写入claims即可 String userAttrs = callGetUserAttributes(requestIp, httpServletRequest.getParameter(CustomFedAuthenticatorConstants.APP_ID), requestId); // 解析userAttrs后按上述格式加入claims
- 在对应服务提供商的声明配置中,开启上述自定义声明的传递权限,后续XACML执行时可直接读取这些属性作为策略判断条件,无需二次调用接口。
方案2:自定义XACML PIP属性查找器(适用于属性需实时拉取的场景)
如果业务要求XACML执行时必须实时调用接口获取最新属性,可基于WSO2的PIP扩展点实现:
- 实现
org.wso2.carbon.identity.entitlement.pip.AbstractPIPAttributeFinder接口,重写属性获取逻辑:从请求上下文或会话中提取IP、ID、appname三个参数,调用指定Web服务获取所需属性返回给XACML引擎。 - 将扩展包放入WSO2的
repository/components/dropins目录,在entitlement.properties中启用自定义PIP扩展,后续XACML策略命中对应属性时会自动触发你的拉取逻辑。
内容的提问来源于stack exchange,提问作者ashok
相关产品推荐
相关产品推荐

