Saml核心协议结构 - littleboy12580/learning_python GitHub Wiki

SAML的XML结构

SAML组件关系

一个经典的SAML组件关系图如下所示:
saml-component

一个SAML断言里包含有认证信息与一些其他信息,而这个SAML断言一般都包含在一个SAML响应中,而这个响应信息是携带在某种传输协议上的;

断言schema语法

xml namespace

  • saml:表示断言相关的元素
  • samlp:表示协议相关的元素
  • ds:表示签名语法定义相关的元素
  • xenc: 加密语法定义相关
  • xs:xml默认
  • xsi:xml实例相关

Datatype

  • String——》xs:string
  • URI——》xs:anyURI
  • Time——》xs:dataTime
  • ID——》xs:ID

Assertions

  • authentication:何时用何种方法主体被认证
  • attribute:主体提供的属性
  • authorization decision:授权

Protocols

  • RequestAbstractType
  • StatusResponseType
  • AttributeQueryType

断言,主体,与声明的结构

<saml:Assertion xmlns:saml=”urn:oasis:names:tc:SAML:2.0:assertion”                            #命名空间声明
   Version="2.0"                                                                                                                                             #SAML协议版本
   IssueInstant="2005-01-31T12:00:00Z">                                                                                         #断言创造时间
   <saml:Issuer Format=urn:oasis:names:SAML:2.0:nameid-format:entity>                     #断言发布者
     http://idp.example.org                                                                                           
   </saml:Issuer> 
   <saml:Subject>                                                                                                                                         #断言主体
     <saml:NameID                                                                                                                                        #名称标识
       Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">                  #标识格式
         [email protected]                                        
     </saml:NameID>
   </saml:Subject>
   <saml:Conditions
     NotBefore="2005-01-31T12:00:00Z"
     NotOnOrAfter="2005-01-31T12:10:00Z">
   </saml:Conditions>
   <saml:AuthnStatement
     AuthnInstant="2005-01-31T12:00:00Z" SessionIndex="67775277772">
     <saml:AuthnContext>
       <saml:AuthnContextClassRef>
         urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
       </saml:AuthnContextClassRef>
     </saml:AuthnContext>
   </saml:AuthnStatement>
 </saml:Assertion>

上面是一个XML片段,该XML描述了一个拥有单点认证声明的断言,该断言具有如下特征元素:

  1. Version(Required):协议版本号
  2. ID(Required):断言编号
  3. IssueInstant(Required):断言发布时间
  4. Issuer(Required):断言发布方
  5. Signature(Optional):签名
  6. Subject(Optional):断言宣言的主体
  7. Conditions(Optional):断言的有效期
  8. AuthnStatement(Optional):认证声明
  9. AuthzDecisionStatement(Optional):授权决定声明
  10. AttributeStatement(Optional):属性声明

对应的schema文档如下:

<element name="Assertion" type="saml:AssertionType"/>
<complexType name="AssertionType">
    <sequence>
        <element ref="saml:Issuer"/>
        <element ref="ds:Signature" minOccurs="0"/>
        <element ref="saml:Subject" minOccurs="0"/>
        <element ref="saml:Conditions" minOccurs="0"/>
        <element ref="saml:Advice" minOccurs="0"/>
        <choice minOccurs="0" maxOccurs="unbounded">
            <element ref="saml:Statement"/>
            <element ref="saml:AuthnStatement"/>
            <element ref="saml:AuthzDecisionStatement"/>
            <element ref="saml:AttributeStatement"/>
        </choice>
    </sequence>
    <attribute name="Version" type="string" use="required"/>
    <attribute name="ID" type="ID" use="required"/>
    <attribute name="IssueInstant" type="dateTime" use="required"/>
</complexTyp

saml protocols

RequestAbstractType

请求类型具有如下特征元素:

  1. Version(Required):协议版本号
  2. ID(Required):请求编号
  3. IssueInstant(Required):请求发起时间
  4. Destination(Optional):请求目的地址URI的引用,可以防止恶意攻击
  5. Issuer(Optional):请求发起人
  6. Signature(Optional):认证请求方的签名

对应的schema文档如下:

<complexType name="RequestAbstractType" abstract="true">
    <sequence>
        <element ref="saml:Issuer" minOccurs="0"/>
        <element ref="ds:Signature" minOccurs="0"/>
        <element ref="samlp:Extensions" minOccurs="0"/>
    </sequence>
    <attribute name="ID" type="ID" use="required"/>
    <attribute name="Version" type="string" use="required"/>
    <attribute name="IssueInstant" type="dateTime" use="required"/>
    <attribute name="Destination" type="anyURI" use="optional"/>
    <attribute name="Consent" type="anyURI" use="optional"/>
</complexType>
<element name="Extensions" type="samlp:ExtensionsType"/>
<complexType name="ExtensionsType">
<sequence>
<any namespace="##other" processContents="lax" maxOccurs="unbounded"/>
</sequence>
</complexType>
⚠️ **GitHub.com Fallback** ⚠️