Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Claims / Claim.cs / 1305376 / Claim.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Claims { using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net.Mail; using System.Runtime.Serialization; using System.Security.Principal; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; // Examples: // ClaimType ResourceValue ResourceRight // --------------- ---------------- ------------------ // "File" "boot.ini" "Read" // "HairColor" "Brown" "PossessProperty" // "UserName" "[....]" "PossessProperty" // "Service" "MailService" "Access" // "Operation" "ReadMail" "Invoke" // ClaimType: // DESC: The type of resource for which rights are granted // XrML: ClaimSet/Resource // SAML: SamlAttributeStatement/Attribute/@Name/..., SamlAuthorizationDecisionStatement/Action/@Namespace/... // ResourceValue: // DESC: Value identifying the resource for which rights are granted // XrML: ClaimSet/Resource/... // SAML: SamlAttributeStatement/Attribute/..., SamlAuthorizationDecisionStatement/@Resource/... // Right: // DESC: Rights expressed about a resource // XRML: ClaimSet/Right // SAML: SamlAttributeStatement (aka. "PossessProperty") or, SamlAuthorizationDecisionStatement/Action/... [DataContract(Namespace = XsiConstants.Namespace)] public class Claim { static Claim system; [DataMember(Name = "ClaimType")] string claimType; [DataMember(Name = "Resource")] object resource; [DataMember(Name = "Right")] string right; IEqualityComparercomparer; Claim(string claimType, object resource, string right, IEqualityComparer comparer) { if (claimType == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("claimType"); if (claimType.Length <= 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("claimType", SR.GetString(SR.ArgumentCannotBeEmptyString)); if (right == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("right"); if (right.Length <= 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("right", SR.GetString(SR.ArgumentCannotBeEmptyString)); this.claimType = claimType; this.resource = resource; this.right = right; this.comparer = comparer; } public Claim(string claimType, object resource, string right) : this(claimType, resource, right, null) { } public static IEqualityComparer DefaultComparer { get { return EqualityComparer .Default; } } public static Claim System { get { if (system == null) system = new Claim(ClaimTypes.System, XsiConstants.System, Rights.Identity); return system; } } public object Resource { get { return this.resource; } } public string ClaimType { get { return this.claimType; } } public string Right { get { return this.right; } } // Turn key claims public static Claim CreateDnsClaim(string dns) { if (dns == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dns"); return new Claim(ClaimTypes.Dns, dns, Rights.PossessProperty, ClaimComparer.Dns); } public static Claim CreateDenyOnlyWindowsSidClaim(SecurityIdentifier sid) { if (sid == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("sid"); return new Claim(ClaimTypes.DenyOnlySid, sid, Rights.PossessProperty); } public static Claim CreateHashClaim(byte[] hash) { if (hash == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("hash"); return new Claim(ClaimTypes.Hash, SecurityUtils.CloneBuffer(hash), Rights.PossessProperty, ClaimComparer.Hash); } public static Claim CreateMailAddressClaim(MailAddress mailAddress) { if (mailAddress == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("mailAddress"); return new Claim(ClaimTypes.Email, mailAddress, Rights.PossessProperty); } public static Claim CreateNameClaim(string name) { if (name == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); return new Claim(ClaimTypes.Name, name, Rights.PossessProperty); } public static Claim CreateRsaClaim(RSA rsa) { if (rsa == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rsa"); return new Claim(ClaimTypes.Rsa, rsa, Rights.PossessProperty, ClaimComparer.Rsa); } public static Claim CreateSpnClaim(string spn) { if (spn == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("spn"); return new Claim(ClaimTypes.Spn, spn, Rights.PossessProperty); } public static Claim CreateThumbprintClaim(byte[] thumbprint) { if (thumbprint == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("thumbprint"); return new Claim(ClaimTypes.Thumbprint, SecurityUtils.CloneBuffer(thumbprint), Rights.PossessProperty, ClaimComparer.Thumbprint); } public static Claim CreateUpnClaim(string upn) { if (upn == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upn"); return new Claim(ClaimTypes.Upn, upn, Rights.PossessProperty, ClaimComparer.Upn); } public static Claim CreateUriClaim(Uri uri) { if (uri == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri"); return new Claim(ClaimTypes.Uri, uri, Rights.PossessProperty); } public static Claim CreateWindowsSidClaim(SecurityIdentifier sid) { if (sid == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("sid"); return new Claim(ClaimTypes.Sid, sid, Rights.PossessProperty); } public static Claim CreateX500DistinguishedNameClaim(X500DistinguishedName x500DistinguishedName) { if (x500DistinguishedName == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("x500DistinguishedName"); return new Claim(ClaimTypes.X500DistinguishedName, x500DistinguishedName, Rights.PossessProperty, ClaimComparer.X500DistinguishedName); } public override bool Equals(object obj) { if (comparer == null) comparer = ClaimComparer.GetComparer(this.claimType); return comparer.Equals(this, obj as Claim); } public override int GetHashCode() { if (comparer == null) comparer = ClaimComparer.GetComparer(this.claimType); return comparer.GetHashCode(this); } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "{0}: {1}", this.right, this.claimType); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Claims { using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net.Mail; using System.Runtime.Serialization; using System.Security.Principal; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; // Examples: // ClaimType ResourceValue ResourceRight // --------------- ---------------- ------------------ // "File" "boot.ini" "Read" // "HairColor" "Brown" "PossessProperty" // "UserName" "[....]" "PossessProperty" // "Service" "MailService" "Access" // "Operation" "ReadMail" "Invoke" // ClaimType: // DESC: The type of resource for which rights are granted // XrML: ClaimSet/Resource // SAML: SamlAttributeStatement/Attribute/@Name/..., SamlAuthorizationDecisionStatement/Action/@Namespace/... // ResourceValue: // DESC: Value identifying the resource for which rights are granted // XrML: ClaimSet/Resource/... // SAML: SamlAttributeStatement/Attribute/..., SamlAuthorizationDecisionStatement/@Resource/... // Right: // DESC: Rights expressed about a resource // XRML: ClaimSet/Right // SAML: SamlAttributeStatement (aka. "PossessProperty") or, SamlAuthorizationDecisionStatement/Action/... [DataContract(Namespace = XsiConstants.Namespace)] public class Claim { static Claim system; [DataMember(Name = "ClaimType")] string claimType; [DataMember(Name = "Resource")] object resource; [DataMember(Name = "Right")] string right; IEqualityComparer comparer; Claim(string claimType, object resource, string right, IEqualityComparer comparer) { if (claimType == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("claimType"); if (claimType.Length <= 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("claimType", SR.GetString(SR.ArgumentCannotBeEmptyString)); if (right == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("right"); if (right.Length <= 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("right", SR.GetString(SR.ArgumentCannotBeEmptyString)); this.claimType = claimType; this.resource = resource; this.right = right; this.comparer = comparer; } public Claim(string claimType, object resource, string right) : this(claimType, resource, right, null) { } public static IEqualityComparer DefaultComparer { get { return EqualityComparer .Default; } } public static Claim System { get { if (system == null) system = new Claim(ClaimTypes.System, XsiConstants.System, Rights.Identity); return system; } } public object Resource { get { return this.resource; } } public string ClaimType { get { return this.claimType; } } public string Right { get { return this.right; } } // Turn key claims public static Claim CreateDnsClaim(string dns) { if (dns == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dns"); return new Claim(ClaimTypes.Dns, dns, Rights.PossessProperty, ClaimComparer.Dns); } public static Claim CreateDenyOnlyWindowsSidClaim(SecurityIdentifier sid) { if (sid == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("sid"); return new Claim(ClaimTypes.DenyOnlySid, sid, Rights.PossessProperty); } public static Claim CreateHashClaim(byte[] hash) { if (hash == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("hash"); return new Claim(ClaimTypes.Hash, SecurityUtils.CloneBuffer(hash), Rights.PossessProperty, ClaimComparer.Hash); } public static Claim CreateMailAddressClaim(MailAddress mailAddress) { if (mailAddress == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("mailAddress"); return new Claim(ClaimTypes.Email, mailAddress, Rights.PossessProperty); } public static Claim CreateNameClaim(string name) { if (name == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); return new Claim(ClaimTypes.Name, name, Rights.PossessProperty); } public static Claim CreateRsaClaim(RSA rsa) { if (rsa == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rsa"); return new Claim(ClaimTypes.Rsa, rsa, Rights.PossessProperty, ClaimComparer.Rsa); } public static Claim CreateSpnClaim(string spn) { if (spn == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("spn"); return new Claim(ClaimTypes.Spn, spn, Rights.PossessProperty); } public static Claim CreateThumbprintClaim(byte[] thumbprint) { if (thumbprint == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("thumbprint"); return new Claim(ClaimTypes.Thumbprint, SecurityUtils.CloneBuffer(thumbprint), Rights.PossessProperty, ClaimComparer.Thumbprint); } public static Claim CreateUpnClaim(string upn) { if (upn == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upn"); return new Claim(ClaimTypes.Upn, upn, Rights.PossessProperty, ClaimComparer.Upn); } public static Claim CreateUriClaim(Uri uri) { if (uri == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri"); return new Claim(ClaimTypes.Uri, uri, Rights.PossessProperty); } public static Claim CreateWindowsSidClaim(SecurityIdentifier sid) { if (sid == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("sid"); return new Claim(ClaimTypes.Sid, sid, Rights.PossessProperty); } public static Claim CreateX500DistinguishedNameClaim(X500DistinguishedName x500DistinguishedName) { if (x500DistinguishedName == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("x500DistinguishedName"); return new Claim(ClaimTypes.X500DistinguishedName, x500DistinguishedName, Rights.PossessProperty, ClaimComparer.X500DistinguishedName); } public override bool Equals(object obj) { if (comparer == null) comparer = ClaimComparer.GetComparer(this.claimType); return comparer.Equals(this, obj as Claim); } public override int GetHashCode() { if (comparer == null) comparer = ClaimComparer.GetComparer(this.claimType); return comparer.GetHashCode(this); } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "{0}: {1}", this.right, this.claimType); } } } // 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
- Ref.cs
- Menu.cs
- X509ChainElement.cs
- XmlEnumAttribute.cs
- CompiledQueryCacheKey.cs
- PropertyItem.cs
- WebAdminConfigurationHelper.cs
- TransformValueSerializer.cs
- RsaSecurityTokenAuthenticator.cs
- PagePropertiesChangingEventArgs.cs
- log.cs
- PlanCompilerUtil.cs
- SHA256Managed.cs
- ProxyGenerator.cs
- FileAuthorizationModule.cs
- TransformProviderWrapper.cs
- RotationValidation.cs
- thaishape.cs
- OrthographicCamera.cs
- X509CertificateValidationMode.cs
- TrustLevel.cs
- TransactionFlowBindingElementImporter.cs
- Utils.cs
- RootBuilder.cs
- LinkedList.cs
- TemplateXamlParser.cs
- BindingExpressionBase.cs
- PeerApplication.cs
- HwndSourceParameters.cs
- CultureInfoConverter.cs
- KeySpline.cs
- RadioButton.cs
- Visitors.cs
- ScrollBarRenderer.cs
- Expressions.cs
- SourceFilter.cs
- CodeLinePragma.cs
- WindowsSpinner.cs
- AuthenticationSection.cs
- ReadOnlyCollectionBase.cs
- ElapsedEventArgs.cs
- Transform.cs
- DragStartedEventArgs.cs
- RSAOAEPKeyExchangeFormatter.cs
- SelectQueryOperator.cs
- PageContent.cs
- XmlQualifiedNameTest.cs
- RootBuilder.cs
- BitFlagsGenerator.cs
- HttpStreamFormatter.cs
- RenderData.cs
- ResourceIDHelper.cs
- OleDbError.cs
- CultureInfo.cs
- Parser.cs
- SafeNativeMethods.cs
- XsltContext.cs
- BufferBuilder.cs
- UserMapPath.cs
- XPathSelectionIterator.cs
- WorkflowViewManager.cs
- StoreItemCollection.Loader.cs
- Rect3D.cs
- NavigationCommands.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- CopyOnWriteList.cs
- PasswordRecoveryAutoFormat.cs
- OracleInfoMessageEventArgs.cs
- PreDigestedSignedInfo.cs
- XpsFixedPageReaderWriter.cs
- PageSettings.cs
- StatusBar.cs
- XmlSchemaObjectCollection.cs
- HScrollProperties.cs
- BinHexDecoder.cs
- UrlAuthFailedErrorFormatter.cs
- TextDecoration.cs
- ServiceDescriptionReflector.cs
- CodeSnippetTypeMember.cs
- TreeWalker.cs
- MediaTimeline.cs
- NameTable.cs
- MyContact.cs
- SimpleMailWebEventProvider.cs
- SystemNetworkInterface.cs
- SelectionRange.cs
- CommandID.cs
- SQLInt64.cs
- IntegerValidator.cs
- ThemeInfoAttribute.cs
- CellTreeSimplifier.cs
- ChameleonKey.cs
- ZipIOLocalFileDataDescriptor.cs
- GlyphRunDrawing.cs
- DataKeyCollection.cs
- ToolbarAUtomationPeer.cs
- RemoteArgument.cs
- DocumentScope.cs
- UnicastIPAddressInformationCollection.cs
- Normalization.cs