saml2_向SAML响应中添加自定义声明–(如何为WSO2 Identity Server编写自定义声明处理程序)...
saml2
總覽
最新版本的WSO2 Identity Server(版本5.0.0)配備了“應用程序身份驗證框架”,該框架提供了很大的靈活性,可以對使用異構協議的各種服務提供商的用戶進行身份驗證。 它具有幾個擴展點,可用于滿足企業系統中常見的幾個自定義要求。 在這篇文章中,我將分享使用這樣一個擴展點的細節。
功能擴展
在企業系統中使用SAML單一登錄時,依賴方通過SAML響應來了解用戶是否已通過身份驗證。 在這一點上,依賴方尚不知道其為業務和授權目的可能需要的已認證用戶的其他屬性。 為了向依賴方提供這些屬性詳細信息,SAML規范允許在SAML響應中也發送屬性。 WSO2 Identity Server通過為管理員提供的GUI開箱即用地支持此功能。 有關此功能和配置的詳細信息,請參閱[1]。
當我們需要向SAML響應中添加除下劃線用戶存儲中可用的屬性之外的其他屬性時,此特定擴展提供的靈活性會派上用場。 為了提供依賴方請求的所有屬性,可能需要尋找外部數據源。
在這里我要描述的樣本中,我們將研究一個場景,該系統需要提供一些存儲在用戶存儲中的用戶本地屬性,以及一些我希望從外部數據源中檢索到的其他屬性。
遵循SAML響應是我們需要從WSO2 IS發送給依賴方的內容。
在此響應中,我們具有一個本地屬性(即角色)和另外兩個屬性http://pushpalanka.org/claims/keplerNumber和http://pushpalanka.org/claims/status,這些屬性已從其他方法中檢索出在我們的擴展名中定義。
怎么樣?
- 定制實現應實現接口“ org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler”或擴展接口“ org.wso2.carbon.identity.application.authentication”的默認實現。 framework.handler.claims.impl.DefaultClaimHandler”。
- 在方法“ public Map <String,String> handleClaimMappings”處返回的地圖應包含我們要添加到SAML響應中的所有屬性。
以下是我按照上面編寫的示例代碼。 外部聲明可能已從數據庫中查詢,從文件中讀取或根據需要使用任何其他機制。
public class CustomClaimHandler implements ClaimHandler {private static Log log = LogFactory.getLog(CustomClaimHandler.class);private static volatile CustomClaimHandler instance;private String connectionURL = null;private String userName = null;private String password = null;private String jdbcDriver = null;private String sql = null;public static CustomClaimHandler getInstance() {if (instance == null) {synchronized (CustomClaimHandler.class) {if (instance == null) {instance = new CustomClaimHandler();}}}return instance;}public Map<String, String> handleClaimMappings(StepConfig stepConfig,AuthenticationContext context, Map<String, String> remoteAttributes,boolean isFederatedClaims) throws FrameworkException {String authenticatedUser = null;if (stepConfig != null) {//calling from StepBasedSequenceHandlerauthenticatedUser = stepConfig.getAuthenticatedUser();} else {//calling from RequestPathBasedSequenceHandlerauthenticatedUser = context.getSequenceConfig().getAuthenticatedUser();}Map<String, String> claims = handleLocalClaims(authenticatedUser, context);claims.putAll(handleExternalClaims(authenticatedUser));return claims;}/*** @param context* @return* @throws FrameworkException*/protected Map<String, String> handleLocalClaims(String authenticatedUser,AuthenticationContext context) throws FrameworkException {....}private Map<String, String> getFilteredAttributes(Map<String, String> allAttributes,Map<String, String> requestedClaimMappings, boolean isStandardDialect) {....}protected String getDialectUri(String clientType, boolean claimMappingDefined) {....}/*** Added method to retrieve claims from external sources. This results will be merged to the local claims when* returning final claim list, to be added to the SAML response, that is sent back to the SP.** @param authenticatedUser : The user for whom we require claim values* @return*/private Map<String, String> handleExternalClaims(String authenticatedUser) throws FrameworkException {Map<String, String> externalClaims = new HashMap<String, String>();externalClaims.put("http://pushpalanka.org/claims/keplerNumber","E90836W19881010");externalClaims.put("http://pushpalanka.org/claims/status","active");return externalClaims;} }在IS_HOME / repository / conf / security / applicationauthentication.xml中,配置新的處理程序名稱。 (在“ ApplicationAuthentication.Extensions.ClaimHandler”元素中。)
<ClaimHandler>com.wso2.sample.claim.handler.CustomClaimHandler</ClaimHandler>現在,如果查看生成的SAML響應,我們將看到添加的外部屬性。
干杯!
[1] – https://docs.wso2.com/display/IS500/Adding+a+Service+Provider
翻譯自: https://www.javacodegeeks.com/2014/08/adding-custom-claims-to-the-saml-response-how-to-write-a-custom-claim-handler-for-wso2-identity-server.html
saml2
總結
以上是生活随笔為你收集整理的saml2_向SAML响应中添加自定义声明–(如何为WSO2 Identity Server编写自定义声明处理程序)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑壁纸高清(电脑壁纸高清全屏可爱)
- 下一篇: win101909磁盘占用50%蓝屏DP