Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / GenericXmlSecurityToken.cs / 1305376 / GenericXmlSecurityToken.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System; using System.Collections.ObjectModel; using System.Globalization; using System.IO; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.Security.Cryptography; using System.Security.Principal; using System.Xml; using System.Runtime.Serialization; using System.Collections.Generic; public class GenericXmlSecurityToken : SecurityToken { const int SupportedPersistanceVersion = 1; string id; SecurityToken proofToken; SecurityKeyIdentifierClause internalTokenReference; SecurityKeyIdentifierClause externalTokenReference; XmlElement tokenXml; ReadOnlyCollectionauthorizationPolicies; DateTime effectiveTime; DateTime expirationTime; public GenericXmlSecurityToken( XmlElement tokenXml, SecurityToken proofToken, DateTime effectiveTime, DateTime expirationTime, SecurityKeyIdentifierClause internalTokenReference, SecurityKeyIdentifierClause externalTokenReference, ReadOnlyCollection authorizationPolicies ) { if (tokenXml == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenXml"); } this.id = GetId(tokenXml); this.tokenXml = tokenXml; this.proofToken = proofToken; this.effectiveTime = effectiveTime.ToUniversalTime(); this.expirationTime = expirationTime.ToUniversalTime(); this.internalTokenReference = internalTokenReference; this.externalTokenReference = externalTokenReference; this.authorizationPolicies = authorizationPolicies ?? EmptyReadOnlyCollection .Instance; } public override string Id { get { return this.id; } } public override DateTime ValidFrom { get { return this.effectiveTime; } } public override DateTime ValidTo { get { return this.expirationTime; } } public SecurityKeyIdentifierClause InternalTokenReference { get { return this.internalTokenReference; } } public SecurityKeyIdentifierClause ExternalTokenReference { get { return this.externalTokenReference; } } public XmlElement TokenXml { get { return this.tokenXml; } } public SecurityToken ProofToken { get { return this.proofToken; } } public ReadOnlyCollection AuthorizationPolicies { get { return this.authorizationPolicies; } } public override ReadOnlyCollection SecurityKeys { get { if (this.proofToken != null) return this.proofToken.SecurityKeys; else return EmptyReadOnlyCollection .Instance; } } public override string ToString() { StringWriter writer = new StringWriter(CultureInfo.InvariantCulture); writer.WriteLine("Generic XML token:"); writer.WriteLine(" validFrom: {0}", this.ValidFrom); writer.WriteLine(" validTo: {0}", this.ValidTo); if (this.internalTokenReference != null) writer.WriteLine(" InternalTokenReference: {0}", this.internalTokenReference); if (this.externalTokenReference != null) writer.WriteLine(" ExternalTokenReference: {0}", this.externalTokenReference); writer.WriteLine(" Token Element: ({0}, {1})", this.tokenXml.LocalName, this.tokenXml.NamespaceURI); return writer.ToString(); } static string GetId(XmlElement tokenXml) { if (tokenXml != null) { string id = tokenXml.GetAttribute(UtilityStrings.IdAttribute, UtilityStrings.Namespace); if ( string.IsNullOrEmpty( id ) ) { // special case SAML 1.1 as this is the only possible ID as // spec is closed. SAML 2.0 is xs:ID id = tokenXml.GetAttribute("AssertionID"); // if we are still null, "Id" if ( string.IsNullOrEmpty( id ) ) { id = tokenXml.GetAttribute("Id"); } } if ( !string.IsNullOrEmpty(id) ) { return id; } } return null; } public override bool CanCreateKeyIdentifierClause () { if (this.internalTokenReference != null && typeof(T) == this.internalTokenReference.GetType()) return true; if (this.externalTokenReference != null && typeof(T) == this.externalTokenReference.GetType()) return true; return false; } public override T CreateKeyIdentifierClause () { if (this.internalTokenReference != null && typeof(T) == this.internalTokenReference.GetType()) return (T)this.internalTokenReference; if (this.externalTokenReference != null && typeof(T) == this.externalTokenReference.GetType()) return (T)this.externalTokenReference; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.UnableToCreateTokenReference))); } public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) { if (this.internalTokenReference != null && this.internalTokenReference.Matches(keyIdentifierClause)) { return true; } else if (this.externalTokenReference != null && this.externalTokenReference.Matches(keyIdentifierClause)) { return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System; using System.Collections.ObjectModel; using System.Globalization; using System.IO; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.Security.Cryptography; using System.Security.Principal; using System.Xml; using System.Runtime.Serialization; using System.Collections.Generic; public class GenericXmlSecurityToken : SecurityToken { const int SupportedPersistanceVersion = 1; string id; SecurityToken proofToken; SecurityKeyIdentifierClause internalTokenReference; SecurityKeyIdentifierClause externalTokenReference; XmlElement tokenXml; ReadOnlyCollection authorizationPolicies; DateTime effectiveTime; DateTime expirationTime; public GenericXmlSecurityToken( XmlElement tokenXml, SecurityToken proofToken, DateTime effectiveTime, DateTime expirationTime, SecurityKeyIdentifierClause internalTokenReference, SecurityKeyIdentifierClause externalTokenReference, ReadOnlyCollection authorizationPolicies ) { if (tokenXml == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenXml"); } this.id = GetId(tokenXml); this.tokenXml = tokenXml; this.proofToken = proofToken; this.effectiveTime = effectiveTime.ToUniversalTime(); this.expirationTime = expirationTime.ToUniversalTime(); this.internalTokenReference = internalTokenReference; this.externalTokenReference = externalTokenReference; this.authorizationPolicies = authorizationPolicies ?? EmptyReadOnlyCollection .Instance; } public override string Id { get { return this.id; } } public override DateTime ValidFrom { get { return this.effectiveTime; } } public override DateTime ValidTo { get { return this.expirationTime; } } public SecurityKeyIdentifierClause InternalTokenReference { get { return this.internalTokenReference; } } public SecurityKeyIdentifierClause ExternalTokenReference { get { return this.externalTokenReference; } } public XmlElement TokenXml { get { return this.tokenXml; } } public SecurityToken ProofToken { get { return this.proofToken; } } public ReadOnlyCollection AuthorizationPolicies { get { return this.authorizationPolicies; } } public override ReadOnlyCollection SecurityKeys { get { if (this.proofToken != null) return this.proofToken.SecurityKeys; else return EmptyReadOnlyCollection .Instance; } } public override string ToString() { StringWriter writer = new StringWriter(CultureInfo.InvariantCulture); writer.WriteLine("Generic XML token:"); writer.WriteLine(" validFrom: {0}", this.ValidFrom); writer.WriteLine(" validTo: {0}", this.ValidTo); if (this.internalTokenReference != null) writer.WriteLine(" InternalTokenReference: {0}", this.internalTokenReference); if (this.externalTokenReference != null) writer.WriteLine(" ExternalTokenReference: {0}", this.externalTokenReference); writer.WriteLine(" Token Element: ({0}, {1})", this.tokenXml.LocalName, this.tokenXml.NamespaceURI); return writer.ToString(); } static string GetId(XmlElement tokenXml) { if (tokenXml != null) { string id = tokenXml.GetAttribute(UtilityStrings.IdAttribute, UtilityStrings.Namespace); if ( string.IsNullOrEmpty( id ) ) { // special case SAML 1.1 as this is the only possible ID as // spec is closed. SAML 2.0 is xs:ID id = tokenXml.GetAttribute("AssertionID"); // if we are still null, "Id" if ( string.IsNullOrEmpty( id ) ) { id = tokenXml.GetAttribute("Id"); } } if ( !string.IsNullOrEmpty(id) ) { return id; } } return null; } public override bool CanCreateKeyIdentifierClause () { if (this.internalTokenReference != null && typeof(T) == this.internalTokenReference.GetType()) return true; if (this.externalTokenReference != null && typeof(T) == this.externalTokenReference.GetType()) return true; return false; } public override T CreateKeyIdentifierClause () { if (this.internalTokenReference != null && typeof(T) == this.internalTokenReference.GetType()) return (T)this.internalTokenReference; if (this.externalTokenReference != null && typeof(T) == this.externalTokenReference.GetType()) return (T)this.externalTokenReference; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.UnableToCreateTokenReference))); } public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) { if (this.internalTokenReference != null && this.internalTokenReference.Matches(keyIdentifierClause)) { return true; } else if (this.externalTokenReference != null && this.externalTokenReference.Matches(keyIdentifierClause)) { return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLGuid.cs
- ListSortDescriptionCollection.cs
- AffineTransform3D.cs
- ActivityDesignerHelper.cs
- VerticalAlignConverter.cs
- ThreadExceptionEvent.cs
- InvokePattern.cs
- DataServices.cs
- TextTreeTextNode.cs
- XPathNodePointer.cs
- XsdBuildProvider.cs
- Token.cs
- BoolExpression.cs
- CodeChecksumPragma.cs
- InputLanguageManager.cs
- ReceiveContent.cs
- DbConnectionStringCommon.cs
- StatusBarAutomationPeer.cs
- VisualTreeUtils.cs
- MarkupCompilePass2.cs
- SHA256Cng.cs
- DrawingContextDrawingContextWalker.cs
- PassportAuthenticationEventArgs.cs
- PenCursorManager.cs
- ObjectMemberMapping.cs
- PaintEvent.cs
- ProgramNode.cs
- TemplateBamlRecordReader.cs
- PointKeyFrameCollection.cs
- FlowStep.cs
- AddInServer.cs
- DataGridViewRowCancelEventArgs.cs
- IsolationInterop.cs
- Misc.cs
- Line.cs
- CounterCreationData.cs
- ViewService.cs
- AutomationEvent.cs
- UIPropertyMetadata.cs
- DataBindingList.cs
- CollectionEditorDialog.cs
- UnsafeNativeMethods.cs
- WindowsListViewSubItem.cs
- CustomSignedXml.cs
- EdgeModeValidation.cs
- QueryPageSettingsEventArgs.cs
- DSASignatureDeformatter.cs
- SymmetricAlgorithm.cs
- InputLanguageEventArgs.cs
- WindowsUpDown.cs
- MissingSatelliteAssemblyException.cs
- FilterEventArgs.cs
- DataTableCollection.cs
- WebPartConnectVerb.cs
- HostingPreferredMapPath.cs
- KeyFrames.cs
- OracleParameterCollection.cs
- XPathEmptyIterator.cs
- DataTableNewRowEvent.cs
- CompilerGlobalScopeAttribute.cs
- PropertyMetadata.cs
- UpDownBase.cs
- CopyNamespacesAction.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- LinqDataSourceInsertEventArgs.cs
- SqlColumnizer.cs
- ContentFilePart.cs
- InlineObject.cs
- WsatStrings.cs
- Model3DGroup.cs
- HiddenField.cs
- ToolboxDataAttribute.cs
- IndexedDataBuffer.cs
- CssTextWriter.cs
- DesignerUtility.cs
- XmlBaseReader.cs
- MetadataArtifactLoader.cs
- OutputCacheSettingsSection.cs
- StylusDownEventArgs.cs
- CssStyleCollection.cs
- FormViewRow.cs
- LayoutManager.cs
- HttpResponseBase.cs
- DependentList.cs
- DataGridAddNewRow.cs
- Set.cs
- OpenCollectionAsyncResult.cs
- SyndicationFeed.cs
- DynamicDocumentPaginator.cs
- XmlAttributes.cs
- Listbox.cs
- SQLDateTimeStorage.cs
- GlyphInfoList.cs
- COM2PropertyPageUITypeConverter.cs
- MouseWheelEventArgs.cs
- SoapAttributeAttribute.cs
- Empty.cs
- GenericXmlSecurityToken.cs
- PeerCollaborationPermission.cs
- Privilege.cs