日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

saml2_向SAML响应中添加自定义声明–(如何为WSO2 Identity Server编写自定义声明处理程序)...

發布時間:2023/12/3 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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發送給依賴方的內容。

<saml2p:Response Destination="https://localhost:9444/acs" ID="faibaccbcepemkackalbbjkihlegenhhigcdjbjk"InResponseTo="kbedjkocfjdaaadgmjeipbegnclbelfffbpbophe" IssueInstant="2014-07-17T13:15:05.032Z"Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"xmlns:xs="http://www.w3.org/2001/XMLSchema"><saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">localhost</saml2:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">..........</ds:Signature><saml2p:Status><saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></saml2p:Status><saml2:Assertion ID="phmbbieedpcfdhcignelnepkemobepgaaipbjjdk" IssueInstant="2014-07-17T13:15:05.032Z" Version="2.0"xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema"><saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">localhost</saml2:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">.........</ds:Signature><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">Administrator</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml2:SubjectConfirmationData InResponseTo="kbedjkocfjdaaadgmjeipbegnclbelfffbpbophe"NotOnOrAfter="2014-07-17T13:20:05.032Z"Recipient="https://localhost:9444/acs"/></saml2:SubjectConfirmation></saml2:Subject><saml2:Conditions NotBefore="2014-07-17T13:15:05.032Z" NotOnOrAfter="2014-07-17T13:20:05.032Z"><saml2:AudienceRestriction><saml2:Audience>carbonServer2</saml2:Audience></saml2:AudienceRestriction></saml2:Conditions><saml2:AuthnStatement AuthnInstant="2014-07-17T13:15:05.033Z"><saml2:AuthnContext><saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml2:AuthnContextClassRef></saml2:AuthnContext></saml2:AuthnStatement><saml2:AttributeStatement><saml2:Attribute Name="http://wso2.org/claims/role"NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Internal/carbonServer2,Internal/everyone</saml2:AttributeValue></saml2:Attribute><saml2:AttributeStatement><saml2:Attribute Name="http://pushpalanka.org/claims/keplerNumber"NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">E90836W19881010</saml2:AttributeValue></saml2:Attribute><saml2:Attribute Name="http://pushpalanka.org/claims/status"NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">active</saml2:AttributeValue></saml2:Attribute></saml2:AttributeStatement></saml2:AttributeStatement></saml2:Assertion> </saml2p:Response>

在此響應中,我們具有一個本地屬性(即角色)和另外兩個屬性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;} }
  • 將已編譯的OSGI捆綁軟件放在IS_HOME / repository / components / dropins中。 (我們將其開發為OSGI捆綁軟件,因為我們還需要使用RealmService獲得本地聲明。 您可以在此處找到完整的捆綁軟件和源代碼 )
  • 使WSO2 Identity Server使用我們擁有的新的自定義實現。
  • 在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编写自定义声明处理程序)...的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。