合作伙伴SAML认证-WebUI方式
引导式阅读
Java
合作伙伴SAML认证-WebUI方式
作者
C***
上架时间
2021-08-09 11:04:18

版本说明

本示例不涉及SDK示例代码。

功能介绍

客户在伙伴销售平台登录后,可以直接跳转到华为云完成云服务购买、云服务资源管理等。伙伴销售平台需完成SAML认证,与华为云建立信任关系。

前提条件

  • 合作伙伴已经完成接入配置

SAML认证-Web UI方式

合作伙伴销售平台与华为云进行SAML认证的流程如图1所示:

图1: SAML认证流程

1. 合作伙伴客户通过浏览器调用华为云登录链接,IAM发起samlRequest请求。

  • a. 合作伙伴客户通过浏览器调用华为云登录链接(https://auth.huaweicloud.com/authui/saml/login?xAccountType=ZXT&isFirstLogin=false&service=https%3a%2f%2fconsole.huaweicloud.com%2fiam%2f)
参数 是否必填 说明 示例
xAccountType 合作伙伴销售平台标识,全局唯一。该标识的具体值由华为分配。合作伙伴在合作伙伴中心完成接入配置后,即可生成该标识。获取方法请参见如何获取xaccountType的取值 ZXT
isFirstLogin 未绑定华为云账号,此参数必填且为true,其他可不填或为false。<br>成功调用“创建客户”接口后,华为云CBC已经将合作伙伴客户的合作伙伴销售平台账号和华为云账号进行了绑定。 false
service 登录后的跳转地址。<br>需要使用encodeURIComponent编码。 https%3a%2f%2fconsole.huaweicloud.com%2fiam%2f
  • b. IAM服务收到合作伙伴客户的登录请求, 根据xAccountType的取值, 查找对应IDP Metadata.xml配置, 找出SingleSignOnService配置项,向此路径发送samlRequest请求。

图2: samlRequest请求

参数 描述
SAMLRequest 返回消息体。<br>此消息为应答xml,IAM对此请求进行了“压缩 > base64加密 > url编码”。<br> 如果合作伙伴使用SAML库,可直接使用此参数值,不必完全解出xml。<br> 如果合作伙伴想解出xml,需要进行“解url > 解base64 > 解压缩(zip.inflate)”,可参考解出SAMLRequest的代码示例
RelayState SAML协议返回参数。
SigAlg 签名使用的签名算法(华为默认使用SHA256算法进行签名)。<br>HTTP://WWW.W3.ORG/2001/04/XMLDSIG-MORE#RSA-SHA256
Signature 签名值。通过签名机制来验证请求的发起方。<br>华为云发起请求时将请求https://www.test.com/saml/login?SAMLRequest={SAMLRequest }&RelayState={ RelayState} &SigAlg={ SigAlg}&Signature={ Signature }中的“SAMLRequest={ SAMLRequest }&RelayState={ RelayState } &SigAlg={ SigAlg }”使用私钥签名(签名算法为SigAlg字段指定的算法),之后再做一次Base64编码作为签名值。<br>接收方收到请求后通过华为云提供的公钥(SP Metadata.xml文件中<ds:X509Certificate></ds:X509Certificate>标签内的值)来验证签名。签名验证通过,则表明是华为云发送的请求可以进行后续操作,否则请求非法。

2. 合作伙伴销售平台生成samlResponse,并返回给华为云IAM。

  • a. 合作伙伴销售平台读取SP Metadata.xml文件获取华为云公钥及samlResponse返回路径。具体请参见获取SP Metadata.xml 中“示例及公钥、应答路径说明”的说明。

  • b. 合作伙伴销售平台构建samlResponse返回体。 此返回体为xml格式,正确返回体及参数说明请参见如下内容。

    须知

    • 如下屏显内容仅作为校验比对。除注释中描述的信息必须修改外,SAML自身定义的时间和ID也是变化的,因此不建议直接修改此response内容,应由SAML相关类库生成。
&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;saml2p:Response Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" ID="_d794dc393ae6724e236003bf0b917cf0" Destination=” https://auth.huaweicloud.com/authui/saml/SAMLAssertionConsumer”InResponseTo="_dck4mm08qmdhc8k4nuir07hghetdqqg8umg5" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"&gt; &lt;saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"&gt;https://www.test.com&lt;/saml2:Issuer&gt; &lt;saml2p:Status&gt; &lt;saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /&gt; &lt;saml2p:StatusMessage&gt;urn:oasis:names:tc:SAML:2.0:status:Success&lt;/saml2p:StatusMessage&gt; &lt;/saml2p:Status&gt; &lt;saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;saml2:Issuer&gt;https://www.test.com&lt;/saml2:Issuer&gt; &lt;ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt; &lt;ds:SignedInfo&gt; &lt;ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /&gt; &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /&gt; &lt;ds:Reference URI="#_2320c40ac7b5e857b2d0d4ea0c8758c3"&gt; &lt;ds:Transforms&gt; &lt;ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /&gt; &lt;ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"&gt; &lt;ec:InclusiveNamespaces PrefixList="xsd" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" /&gt; &lt;/ds:Transform&gt; &lt;/ds:Transforms&gt; &lt;ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /&gt; &lt;ds:DigestValue&gt;rFxrycznfGNYOnprZIFJJou4ro0Mz65+43MIR5F0+H4=&lt;/ds:DigestValue&gt; &lt;/ds:Reference&gt; &lt;/ds:SignedInfo&gt; &lt;ds:SignatureValue&gt; YqTWQngAPfGqQmWa610PM7LeefqWdKuveUVINrqL67NoHJIDa2WxLwdVzoJIlJh64QiNPr6+ndmL DCMgIC5F/9ijuzhIICZcc6lHNIjy6EsPkKRjfo9oeoVAqLgG/kmVQYeHLBID0y11RNXXpAVY4nhJ 26KiIVGt7ywyKAmhichE+eW/UYAGiOI5vkfgD2gZUGV+yPkv64k7xK4yAH3mL2NaCPuw/90e4enm iUx0YuazDwM5FiRUSMpcJs0rcNmS6clWAUcCzbOx+y2vJGtTjHb7k3UsmpnTop5eYNp94+sDPEat 8FaV4SgafMEL5z54gpe8+//9yOWEvlBs1b0RYg== &lt;/ds:SignatureValue&gt; &lt;ds:KeyInfo&gt; &lt;ds:X509Data&gt; &lt;ds:X509Certificate&gt; MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhK3L160NjP9EhBGQOC2s4r+Wc62bkRkc nUxfhiZwCwJdQCykzuLOAoATnfoEamV5W25xtSS5kFs+4OC0mYVpKcI3SWoydX+UE5Qik5UfJ8Dt G1AvSEKhSluyO9axrV5Uv089jMxBnlm/R+xND73WcZM11yIbKJEZSTCEDfh+KnFbMw108umFMden RZCrNWUJoSp/90XeG0V2Nmj7Fkq72skSifwIASLRq9KqLbmh1QwUX+AoWpHK/jRUBustMBmG1n1i AqpD4EBjjBOB27k1wXZ30+IoJt8IZmfSZRFoNn5VFWXNeEmZ1aQvGSvd3Tyyw2/Wr+w/8Mags69C mpeX6QIDAQAB &lt;/ds:X509Certificate&gt; &lt;/ds:X509Data&gt; &lt;/ds:KeyInfo&gt; &lt;/ds:Signature&gt; &lt;saml2:Subject&gt; &lt;saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="https://auth.huaweicloud.com/"&gt;Some NameID value&lt;/saml2:NameID&gt; &lt;saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"&gt; &lt;saml2:SubjectConfirmationData InResponseTo="_dck4mm08qmdhc8k4nuir07hghetdqqg8umg5" NotBefore="2018-10-28T08:21:41.740Z" NotOnOrAfter="2018-11-01T08:21:41.740Z" Recipient="https://auth.huaweicloud.com/authui/saml/SAMLAssertionConsumer" /&gt; &lt;/saml2:SubjectConfirmation&gt; &lt;/saml2:Subject&gt; &lt;saml2:Conditions NotBefore="2018-10-28T08:21:41.740Z" NotOnOrAfter="2018-11-01T08:21:41.740Z"&gt; &lt;saml2:AudienceRestriction&gt; &lt;saml2:Audience&gt;https://auth.huaweicloud.com/&lt;/saml2:Audience&gt; &lt;/saml2:AudienceRestriction&gt; &lt;/saml2:Conditions&gt; &lt;saml2:AttributeStatement&gt; &lt;saml2:Attribute FriendlyName="xUserId" Name="xUserId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string"&gt;*******&lt;/saml2:AttributeValue&gt; &lt;/saml2:Attribute&gt; &lt;saml2:Attribute FriendlyName="xAccountId" Name="xAccountId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string"&gt;********&lt;/saml2:AttributeValue&gt; &lt;/saml2:Attribute&gt; &lt;saml2:Attribute FriendlyName="bpId" Name="bpId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string"&gt;******&lt;/saml2:AttributeValue&gt; &lt;/saml2:Attribute&gt; &lt;saml2:Attribute FriendlyName="email" Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string" /&gt; &lt;/saml2:Attribute&gt; &lt;saml2:Attribute FriendlyName="name" Name="name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string"&gt;******&lt;/saml2:AttributeValue&gt; &lt;/saml2:Attribute&gt; &lt;saml2:Attribute FriendlyName="mobile" Name="mobile" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"&gt; &lt;saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string"&gt;*****&lt;/saml2:AttributeValue&gt; &lt;/saml2:Attribute&gt; &lt;/saml2:AttributeStatement&gt; &lt;saml2:AuthnStatement AuthnInstant="2018-10-30T08:21:41.741Z"&gt; &lt;saml2:SubjectLocality Address="https://auth.huaweicloud.com/" /&gt; &lt;saml2:AuthnContext&gt; &lt;saml2:AuthnContextClassRef&gt;urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified&lt;/saml2:AuthnContextClassRef&gt; &lt;/saml2:AuthnContext&gt; &lt;/saml2:AuthnStatement&gt; &lt;/saml2:Assertion&gt; &lt;/saml2p:Response&gt;

合作伙伴签名值使用标准的XML签名方式,签名类型为enveloped-signature。建议优先使用第三方提供的SAML库进行签名。

签名步骤如下:

  1. 获取签名对象 (Assertion)
&lt;saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; ...... &lt;/saml2:Assertion&gt; ``` 2. 获取标签对象 (Signature)
    &lt;ds:Signature
        xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt;
        &lt;ds:SignedInfo&gt;
            &lt;ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /&gt;
            &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha256" /&gt;
            &lt;ds:Reference URI="#_2320c40ac7b5e857b2d0d4ea0c8758c3"&gt;
                &lt;ds:Transforms&gt;
                    &lt;ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /&gt;
                    &lt;ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"&gt;
                        &lt;ec:InclusiveNamespaces
                            xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
                                          PrefixList="xs" /&gt;
                        &lt;/ds:Transform&gt;
                    &lt;/ds:Transforms&gt;
                    &lt;ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /&gt;
                    &lt;ds:DigestValue&gt;......&lt;/ds:DigestValue&gt;
                &lt;/ds:Reference&gt;
            &lt;/ds:SignedInfo&gt;
            
            &lt;ds:SignatureValue&gt; 
            ...... 
          &lt;/ds:SignatureValue&gt;
            &lt;ds:KeyInfo&gt;
                &lt;ds:X509Data&gt;
                    
                    &lt;ds:X509Certificate&gt; 
                ...... 
              &lt;/ds:X509Certificate&gt;
                &lt;/ds:X509Data&gt;
            &lt;/ds:KeyInfo&gt;
        &lt;/ds:Signature&gt;

   ```
  1. 对签名对象Assertion生成“DigestValue”摘要值
    1. 对Assertion按照Signature的Transform子标签中的算法进行标准化转换;
    2. 将1)转换后的对象按照DigestMethod中的算法生成摘要;
    3. 将生成的摘要值放在DigestValue标签中。
4. 使用生成证书中步骤6的私钥对SignedInfo对象签名生成“SignatureValue”值
   1. 对SignedInfo按照 CanonicalizationMethod 中的算法进行标准化转换;
   2. 将1)转换后的对象按照SignatureMethod中的签名算法进行签名,签名值放在SignatureValue中

5. 将 “DigestValue”和“SignatureValue”值组成最终的Signature对象,将Signature放置于Assertion对象中,作为其子元素。

签名后的屏显如下:

&lt;saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; ...... &lt;ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt; ...... &lt;ds:SignatureValue&gt; ...... &lt;/ds:SignatureValue&gt; &lt;ds:KeyInfo&gt; &lt;ds:X509Data&gt; &lt;ds:X509Certificate&gt; ...... &lt;/ds:X509Certificate&gt; &lt;/ds:X509Data&gt; &lt;/ds:KeyInfo&gt; &lt;/ds:Signature&gt; &lt;/saml2:Assertion&gt;
  • <saml2:AttributeValue></saml2:AttributeValue>之间的取值说明
参数 描述
xUserId 合作伙伴客户在合作伙伴销售平台的用户ID,即xAccountId的取值。
xAccountId 合作伙伴客户在合作伙伴销售平台的账号ID。
bpId 如果客户需要关联至经销商伙伴或华为云伙伴能力中心(一级经销商),则此处需填写经销商伙伴或华为云伙伴能力中心的伙伴ID,获取方法请参见如何获取合作伙伴ID(partner_id)。如果客户需要关联至精英服务商(二级经销商),则此处需填写精英服务商的伙伴ID,获取方法请参见查询精英服务商列表。
email 邮箱内容。<br>内容非必填。<br>校验规则:<br>客户间判重。<br>最大长度:64<br>使用正则表达式校验:"^[azA-Z0-9.!#$%&'+\\/=?^_`{/}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[azA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)$"
name 合作伙伴销售平台传递的客户名称。<br>内容非必填。<br>请与“创建客户 "接口请求参数中的“domain_name”取值保持一致。
mobile 手机号码,格式为“国家码-手机号码”。<br>内容非必填。<br>手机号码请与“创建客户”接口请求参数中的“mobile_phone”保持一致。
说明
  • 表1中有账号ID和用户ID的定义是因为华为云IAM有账号和用户的概念。关于两个概念的具体介绍请参见身份管理 中的“账号”和“IAM用户”的描述。

  • c. 如果客户已在合作伙伴销售平台登录,则直接返回samlResponse消息。如果未登录,则登录后返回samlResponse消息。向2.a中华为云应答路径AssertionConsumerService发送POST请求,参数使用Form Data形式。

图3: samlResponse请求

参数 描述
SAMLResponse 2.b中samlResponse返回体经过base64加密后的字符串。
RelayState samlRequest中相同参数值。

3. IAM解析SAMLResponse。由于在调用“创建客户”接口时,华为云CBC将客户在合作伙伴销售平台上的账号与华为云账号进行了绑定,所以此时可直接登录到service重定向的页面,完成云服务的购买和管理。

参考

更多信息请参考合作伙伴中心

修订记录

发布日期 文档版本 修订说明
2021-06-02 1.0.1 SAML-WebUI接入 demo第一个版本发布