2013-01-18 27 views
6

Mamy aplikację, która została oryginalnie zbudowana przy użyciu .NET 4.0 i WIF 3.5 (1.0?). Jestem w trakcie przekształcania go, aby korzystać z WIF 4.5, ponieważ zaktualizowaliśmy aplikację do .NET 4.5. Mam wszystkie zmiany w kodzie i walczę z ustawieniami konfiguracji. Mój obecny dylemat to element <claimTypeRequired>. Według this documentation powinno być dzieckiem <identityConfiguration>, ale kiedy zmodyfikować mój config wyglądać tenKonfiguracja Windows Identity Foundation 4.5 Konfiguracja

<system.identityModel> 
    <identityConfiguration> 
    <claimTypeRequired> 
     ... 
    </claimTypeRequired> 

pojawia się następujący błąd w czasie wykonywania

Parser Error Message: Unrecognized element 'claimTypeRequired'. 

Gdybym tylko komentarz out <claimTypeRequired> blok I przeszedł ten błąd, ale potem jestem przedstawiony z innym problemem. Mieliśmy zmodyfikował maximumClockSkew w istniejącej aplikacji za pomocą następującej konfiguracji

<securityTokenHandlerConfiguration> 
    <maximumClockSkew value="1" /> 
</securityTokenHandlerConfiguration> 

Dokumentacja konfiguracji odwołuje wcześniej nawet nie wspominając o maximumClockSkew. Pomyślałem, że spróbuję zostawić to, żeby zobaczyć, co się stanie. Co się dzieje, jest

Parser Error Message: Property 'maximumClockSkew' is not a ConfigurationElement. 

Ale kiedy patrzę na klasy SecurityTokenHandlerConfigurationElement użyciu JustDecompile widzę właściwość:

[ConfigurationProperty("maximumClockSkew", IsRequired=false, DefaultValue="00:05:00")] 
[IdentityModelTimeSpanValidator(MinValueString="00:00:00")] 
[TypeConverter(typeof(TimeSpanOrInfiniteConverter))] 
public TimeSpan MaximumClockSkew... 

więc wydaje się, że spodziewa się go tam być.

To prawie tak, jak Microsoft nie chce, abyśmy używali tych rzeczy.

Odpowiedz

0

byłaś prawie blisko to jest odpowiedź na ustawienie go w config

<securityTokenHandlerConfiguration saveBootstrapContext="true" maximumClockSkew="00:35:00" > 

Działa ona ustawia go do wartości 35 minut tutaj. hh: mm: ss

4

Oto dekompilacja IdentityConfigurationElement z Resharper. Zauważ, że typ żądania nie jest już członkiem tego elementu. Wygląda na to, że claimTypeRequired nie jest częścią schematu, mimo że znajduje się w dokumentacji Microsoft.

// Type: System.IdentityModel.Configuration.IdentityConfigurationElement 
// Assembly: System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.IdentityModel.dll 

using System; 
using System.ComponentModel; 
using System.Configuration; 
using System.Runtime; 

namespace System.IdentityModel.Configuration 
{ 
    /// <summary> 
    /// Represents an &lt;identityConfiguration&gt; element in a configuration file. This class cannot be inherited. 
    /// </summary> 
    public sealed class IdentityConfigurationElement : ConfigurationElement 
    { 
    /// <summary> 
    /// Initializes a new instance of the <see cref="T:System.IdentityModel.Configuration.IdentityConfigurationElement"/> class. 
    /// </summary> 
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 
    public IdentityConfigurationElement(); 
    /// <summary> 
    /// Gets or sets the name of the identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The name of the identity configuration. 
    /// </returns> 
    [ConfigurationProperty("name", Options = ConfigurationPropertyOptions.IsKey)] 
    [StringValidator(MinLength = 0)] 
    public string Name { get; set; } 
    /// <summary> 
    /// Gets the <see cref="T:System.IdentityModel.Configuration.AudienceUriElementCollection"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The collection of audience URIs that are configured for this identity configuration element. 
    /// </returns> 
    [ConfigurationProperty("audienceUris", IsRequired = false)] 
    public AudienceUriElementCollection AudienceUris { get; } 
    /// <summary> 
    /// Gets or sets the <see cref="T:System.IdentityModel.Configuration.IdentityModelCachesElement"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The element that configures the token replay cache and the session security token cache for this identity configuration element. 
    /// </returns> 
    [ConfigurationProperty("caches", IsRequired = false)] 
    public IdentityModelCachesElement Caches { get; set; } 
    /// <summary> 
    /// Gets or sets the <see cref="T:System.IdentityModel.Configuration.X509CertificateValidationElement"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The element that configures the certificate validator and its properties for this identity configuration element. 
    /// </returns> 
    [ConfigurationProperty("certificateValidation", IsRequired = false)] 
    public X509CertificateValidationElement CertificateValidation { get; set; } 
    /// <summary> 
    /// Gets or sets the claims authentication manager that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// A custom type element that specifies the <see cref="T:System.Type"/> of the claims authentication manager. The type must derive from <see cref="T:System.Security.Claims.ClaimsAuthenticationManager"/>. 
    /// </returns> 
    [ConfigurationProperty("claimsAuthenticationManager", IsRequired = false)] 
    public CustomTypeElement ClaimsAuthenticationManager { get; set; } 
    /// <summary> 
    /// Gets or sets the claims authorization manager that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// A custom type element that specifies the <see cref="T:System.Type"/> of the claims authorization manager. The type must derive from <see cref="T:System.Security.Claims.ClaimsAuthorizationManager"/>. 
    /// </returns> 
    [ConfigurationProperty("claimsAuthorizationManager", IsRequired = false)] 
    public CustomTypeElement ClaimsAuthorizationManager { get; set; } 
    /// <summary> 
    /// Gets or sets the <see cref="T:System.IdentityModel.Configuration.IssuerNameRegistryElement"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The element that configures the issuer name registry for this identity configuration element. 
    /// </returns> 
    [ConfigurationProperty("issuerNameRegistry", IsRequired = false)] 
    public IssuerNameRegistryElement IssuerNameRegistry { get; set; } 
    /// <summary> 
    /// Gets or sets the issuer token resolver that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// A custom type element that specifies the <see cref="T:System.Type"/> of the issuer token resolver. The type must derive from <see cref="T:System.IdentityModel.Selectors.SecurityTokenResolver"/>. 
    /// </returns> 
    [ConfigurationProperty("issuerTokenResolver", IsRequired = false)] 
    public CustomTypeElement IssuerTokenResolver { get; set; } 
    /// <summary> 
    /// Gets or sets the maximum clock skew that is configured for this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The maximum clock skew. 
    /// </returns> 
    [TypeConverter(typeof (TimeSpanOrInfiniteConverter))] 
    [ConfigurationProperty("maximumClockSkew", DefaultValue = "00:05:00", IsRequired = false)] 
    [IdentityModelTimeSpanValidator(MinValueString = "00:00:00")] 
    public TimeSpan MaximumClockSkew { get; set; } 
    /// <summary> 
    /// Gets or sets a value that indicates whether to save the bootstrap context in claims identities and session security tokens created by the handlers configured in this identity collection. 
    /// </summary> 
    /// 
    /// <returns> 
    /// true to save the <see cref="T:System.IdentityModel.Tokens.BootstrapContext"/>; otherwise, false. 
    /// </returns> 
    [ConfigurationProperty("saveBootstrapContext", DefaultValue = false, IsRequired = false)] 
    public bool SaveBootstrapContext { get; set; } 
    /// <summary> 
    /// Gets or sets the service token resolver that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// A custom type element that specifies the <see cref="T:System.Type"/> of the service token resolver. The type must derive from <see cref="T:System.IdentityModel.Selectors.SecurityTokenResolver"/>. 
    /// </returns> 
    [ConfigurationProperty("serviceTokenResolver", IsRequired = false)] 
    public CustomTypeElement ServiceTokenResolver { get; set; } 
    /// <summary> 
    /// Gets or sets the <see cref="T:System.IdentityModel.Configuration.TokenReplayDetectionElement"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The element that specifies whether token replay detection is enabled and specifies the maximum expiration period for tokens in the token replay cache. 
    /// </returns> 
    [ConfigurationProperty("tokenReplayDetection", IsRequired = false)] 
    public TokenReplayDetectionElement TokenReplayDetection { get; set; } 
    /// <summary> 
    /// Gets or sets the <see cref="T:System.IdentityModel.Configuration.SecurityTokenHandlerSetElementCollection"/> that is associated with this identity configuration element. 
    /// </summary> 
    /// 
    /// <returns> 
    /// The security token handler collections configured for this identity configuration element.. 
    /// </returns> 
    [ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)] 
    public SecurityTokenHandlerSetElementCollection SecurityTokenHandlerSets { get; } 
    } 
} 
+0

To jest niesamowite. W System.IdentityModel.Services.Serialization.ConfigurationConstants nadal mają stałą dla niego i klasy wewnętrznej nadal istnieje, aby go reprezentować (System.IdentityModel.Services.Serialization.ClaimTypeRequiredElement). To naprawdę nie ma znaczenia, że ​​był mniej niepokojący niż MaximumClockSkew, który skończyliśmy, robiąc programowo. –

+0

możesz wypróbować opcję poniżej Craig W.Dzięki temu można go konfigurować i nie wymaga twardego kodowania –

2

Nawiasem mówiąc, jeśli nie dowiedział się już o atrybucie claimTypeRequired w formacie XML, można to wykorzystać jako obejście:

na górze pliku konfiguracyjnego, umieścić to:

<section name="system.identityModel.services.serialization" type="System.IdentityModel.Services.Serialization , System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 

a następnie wokół claimTypeRequired, oto przykład:

<system.identityModel.services.serialization> 
     <claimTypeRequired> 
      <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" optional="true"/> 
      <claimType type="http://schemas.microsoft.com/ws/2008/06/identity/claims/role" optional="true"/> 
     </claimTypeRequired> 
    </system.identityModel.services.serialization> 

poważaniem