2014-10-02 4 views
0

Im пытается создать билет SAML2 с помощью OIOSAML.net.Тип определения атрибута/атрибута OIOSAML/SAML2?

У меня получилось 95% от правильной структуры, однако при создании xml у меня есть следующая проблема.

Результат:

<saml2:Attribute name="urn:x:names:federation:attributeName:systemversion" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"> 
      <saml2:AttributeValue>1.0</saml2:AttributeValue> 
</saml2:Attribute> 

Ожидаемое:

<saml2:Attribute Name="urn:x:names:federation:attributeName:systemversion" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"> 
      <saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">1.0</saml2:AttributeValue> 
</saml2:Attribute> 

Я отсутствует определение типа на моем AttributeValue. Из определения объекта я могу зачитать следующее.

/// <summary> 
/// Gets or sets the attribute value. 
/// Contains a value of the attribute. If an attribute contains more than one discrete value, it is 
/// RECOMMENDED that each value appear in its own &lt;AttributeValue&gt; element. If more than 
/// one &lt;AttributeValue&gt; element is supplied for an attribute, and any of the elements have a 
/// datatype assigned through xsi:type, then all of the &lt;AttributeValue&gt; elements must have 
/// the identical datatype assigned. 
/// </summary> 
/// <value>The attribute value.</value> 
[XmlElement("AttributeValue", IsNullable = true)] 
public string[] AttributeValue 
{ 
    get { return attributeValueField; } 
    set { attributeValueField = value; } 
} 

И им определение атрибута следующим образом:

var attr = new SamlAttribute() { 
    Name = StringConstants.SAML2_ATTRIBUTE_PREFIX + StringConstants.ATTRIBUTE_INFO_SYSTEMVERSION, 
    AttributeValue = new[] {this.SystemVersion}, 
    NameFormat = StringConstants.ATTRIBUTE_FORMAT 
}; 

Вопрос Как я могу получить мой <AttributeValue> определить xsi:type="xs:string"?

ответ

0

Мне пришлось создать пользовательский объект сериализации из-за того, что SP не обрабатывал синтаксический анализ из XSAnyImpl.

Чтобы добиться этого, мне пришлось добавить кое-что в SamlAttribute, который работал для моего конкретного случая. Я уверен, что должно быть лучшее решение, но это сработало для моего дела.

Сначала игнорировать значение по умолчанию в сериализации

[XmlIgnore] 
[XmlElement("AttributeValue", IsNullable = true)] 
public string[] AttributeValue 
{ 
    get { return attributeValueField; } 
    set { attributeValueField = value; } 
} 

Добавить новый пользовательский объект

[XmlElement("AttributeValue", IsNullable = true)] 
public ExtendedAttributeValue[] Values { get; set; } 


public class ExtendedAttributeValue { 
     [XmlAttribute("type", DataType = "string", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] 
     public string Type { get; set; } 

     [XmlText] 
     public string Value { get; set; } 
} 

типа Силе хз: строка

new SamlAttribute() { 
        Name = StringConstants.SAML2_ATTRIBUTE_PREFIX + StringConstants.ATTRIBUTE_INFO_SYSTEMVERSION, 
        Values = new [] {new SamlAttribute.ExtendedAttributeValue(){Type = "xs:string",Value = this.SystemVersion}}, 
        NameFormat = StringConstants.ATTRIBUTE_FORMAT 
}; 

Результат

<saml2:Attribute Name="urn:x:names:federation:attributeName:systemversion" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"> 
     <saml2:AttributeValue xsi:type="xs:string">1.0</saml2:AttributeValue> 
</saml2:Attribute> 

хз & XSI определено в корневом узле

<saml2:Assertion xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" Version="2.0" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"> 
Смежные вопросы