Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / InfocardClientCredentials.cs / 1 / InfocardClientCredentials.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.InfoCards { using System; using System.IdentityModel.Tokens; using System.IdentityModel.Selectors; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; using System.ServiceModel.Dispatcher; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; // // Summary // This class provides the credentials for authentication using self issued cards // internal class InfoCardServiceClientCredentials : ClientCredentials { InfoCard m_card; TokenFactoryCredential m_credentials; bool m_isSelfIssued; ProtocolProfile m_protocolProfile; RSATokenProvider m_endorsingSigTokenProvider; // // CTOR // public InfoCardServiceClientCredentials( TokenFactoryCredential creds, ProtocolProfile profile ) { m_credentials = creds; m_protocolProfile = profile; } public InfoCardServiceClientCredentials(InfoCardServiceClientCredentials other, ProtocolProfile profile ) : base(other) { m_credentials = other.m_credentials; m_endorsingSigTokenProvider = other.m_endorsingSigTokenProvider; m_protocolProfile = profile; } public InfoCard SelectedCard { get{ return m_card; } set{ m_card = value; } } public bool IsSelfIssuedCred { get { return m_isSelfIssued; } set { m_isSelfIssued = value; } } public RSATokenProvider EndorsingSignatureTokenProvider { get { return m_endorsingSigTokenProvider; } set { m_endorsingSigTokenProvider = value; } } public ProtocolProfile ProtocolVersionProfile { get { return m_protocolProfile; } } protected override ClientCredentials CloneCore() { return new InfoCardServiceClientCredentials( this, m_protocolProfile ); } public override void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior) { } public override SecurityTokenManager CreateSecurityTokenManager() { return new InfoCardServiceClientCredentialsSecurityTokenManager(this); } class InfoCardServiceClientCredentialsSecurityTokenManager : ClientCredentialsSecurityTokenManager { InfoCard m_card; TokenFactoryCredential m_credentials; ProtocolProfile m_protocolProfile; public InfoCardServiceClientCredentialsSecurityTokenManager(InfoCardServiceClientCredentials creds) : base(creds) { m_card = creds.SelectedCard; m_credentials = creds.m_credentials; m_protocolProfile = creds.ProtocolVersionProfile; } public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement) { if (tokenRequirement == null) { throw IDT.ThrowHelperArgumentNull("tokenRequirement"); } string tokenType = tokenRequirement.TokenType; bool needUseKey = null != ((InfoCardServiceClientCredentials)ClientCredentials).EndorsingSignatureTokenProvider; // // Check if the credential type that is requested matches the one in the selcted card. // If sucessful, return the appropriate tokenprovider. // if (IsIssuedSecurityTokenRequirement(tokenRequirement)) { if (m_credentials.CredentialType != TokenFactoryCredentialType.SelfIssuedCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } IssuedSecurityTokenParameters itp = tokenRequirement.GetProperty(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty); EndpointAddress target = tokenRequirement.GetProperty (ServiceModelSecurityTokenRequirement.TargetAddressProperty); if( itp.IssuerAddress != null && Utility.CompareUri( itp.IssuerAddress.Uri, XmlNames.WSIdentity.SelfIssuerUriValue ) ) { return new CustomTokenProvider( itp, m_card, target, ((InfoCardServiceClientCredentials)base.ClientCredentials).IsSelfIssuedCred, m_protocolProfile ); } else { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.InvalidIssuerForIssuedToken))); } } else if (tokenType == SecurityTokenTypes.X509Certificate) { if (tokenRequirement.KeyUsage == SecurityKeyUsage.Signature) { if (m_credentials.CredentialType != TokenFactoryCredentialType.X509CertificateCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } return new RemoteCryptoTokenProvider(this.ClientCredentials.ClientCertificate.Certificate); } else { return base.CreateSecurityTokenProvider(tokenRequirement); } } else if (tokenType == ServiceModelSecurityTokenTypes.MutualSslnego) { if (m_credentials.CredentialType != TokenFactoryCredentialType.X509CertificateCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } return base.CreateSecurityTokenProvider(tokenRequirement); } else if (tokenType == ServiceModelSecurityTokenTypes.AnonymousSslnego) { return base.CreateSecurityTokenProvider(tokenRequirement); } else if (tokenType == ServiceModelSecurityTokenTypes.SecureConversation) { return base.CreateSecurityTokenProvider(tokenRequirement); } else if (tokenType == SecurityTokenTypes.Kerberos || tokenType == ServiceModelSecurityTokenTypes.Spnego) { if (m_credentials.CredentialType != TokenFactoryCredentialType.KerberosCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } return base.CreateSecurityTokenProvider(tokenRequirement); } else if (tokenType == SecurityTokenTypes.UserName) { if (m_credentials.CredentialType != TokenFactoryCredentialType.UserNamePasswordCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } return base.CreateSecurityTokenProvider(tokenRequirement); } else if (tokenType == ServiceModelSecurityTokenTypes.SspiCredential) { if (m_credentials.CredentialType != TokenFactoryCredentialType.KerberosCredential && m_credentials.CredentialType != TokenFactoryCredentialType.UserNamePasswordCredential) { throw IDT.ThrowHelperError(new TokenCreationException(SR.GetString(SR.CardDoesNotMatchRequiredAuthType))); } return base.CreateSecurityTokenProvider(tokenRequirement); } else if( tokenType == SecurityTokenTypes.Rsa && needUseKey ) { // // If this is being asked for it is to prove posession of a private key associated with a public // key passed in the UseKey field of an RST. // InfoCardServiceClientCredentials icClientCreds = (InfoCardServiceClientCredentials)ClientCredentials; return icClientCreds.EndorsingSignatureTokenProvider; } else { return base.CreateSecurityTokenProvider( tokenRequirement ); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RootAction.cs
- CallbackValidatorAttribute.cs
- DesignerDataColumn.cs
- WindowsSolidBrush.cs
- WindowsServiceCredential.cs
- XmlNamespaceMapping.cs
- ImageSource.cs
- RenderDataDrawingContext.cs
- GridViewUpdatedEventArgs.cs
- WebConfigurationHostFileChange.cs
- ConnectionPoint.cs
- HtmlInputPassword.cs
- ErrorFormatter.cs
- Expression.DebuggerProxy.cs
- DelegateBodyWriter.cs
- StructuralType.cs
- TableSectionStyle.cs
- Normalization.cs
- DataTransferEventArgs.cs
- ReadOnlyTernaryTree.cs
- DataViewManagerListItemTypeDescriptor.cs
- StackOverflowException.cs
- MeasurementDCInfo.cs
- UserInitiatedNavigationPermission.cs
- XmlSchemaNotation.cs
- StaticTextPointer.cs
- Tuple.cs
- StandardToolWindows.cs
- DbMetaDataFactory.cs
- XmlTypeMapping.cs
- Point3D.cs
- mediaeventshelper.cs
- InputMethod.cs
- ToolBar.cs
- ChannelFactoryRefCache.cs
- HttpInputStream.cs
- COAUTHIDENTITY.cs
- ArithmeticException.cs
- SoapAttributes.cs
- SamlEvidence.cs
- metadatamappinghashervisitor.cs
- NamedPipeAppDomainProtocolHandler.cs
- _TimerThread.cs
- ScrollChrome.cs
- DbCommandTree.cs
- IdentityModelDictionary.cs
- SHA512Managed.cs
- XmlSchemaAnnotated.cs
- InvalidPipelineStoreException.cs
- XhtmlConformanceSection.cs
- SoapMessage.cs
- EntityDesignerDataSourceView.cs
- AddingNewEventArgs.cs
- RecordBuilder.cs
- DataGridViewCheckBoxCell.cs
- ZipIOCentralDirectoryFileHeader.cs
- RegexGroupCollection.cs
- WasAdminWrapper.cs
- MouseEvent.cs
- InputReportEventArgs.cs
- ConfigXmlSignificantWhitespace.cs
- SqlDataRecord.cs
- cache.cs
- XmlILCommand.cs
- DynamicQueryableWrapper.cs
- Thickness.cs
- FileChangesMonitor.cs
- DependencyObject.cs
- SudsParser.cs
- TextParagraphView.cs
- UnauthorizedAccessException.cs
- ConnectionManagementElement.cs
- CommonRemoteMemoryBlock.cs
- SafeUserTokenHandle.cs
- VBIdentifierName.cs
- TextTabProperties.cs
- diagnosticsswitches.cs
- TcpPortSharing.cs
- PageContentCollection.cs
- ExtentKey.cs
- XmlTextReaderImpl.cs
- Mappings.cs
- DependencySource.cs
- EntityWithChangeTrackerStrategy.cs
- OpenTypeLayoutCache.cs
- TreeChangeInfo.cs
- ConfigurationCollectionAttribute.cs
- ParsedRoute.cs
- Bold.cs
- NopReturnReader.cs
- PickBranchDesigner.xaml.cs
- PrivateFontCollection.cs
- IntMinMaxAggregationOperator.cs
- RecommendedAsConfigurableAttribute.cs
- UriParserTemplates.cs
- MissingMethodException.cs
- InstanceNormalEvent.cs
- XmlComment.cs
- XmlRootAttribute.cs
- TextParentUndoUnit.cs