Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
2007-11-27 Atsushi Enomoto <atsushi@ximian.com>
* X509CertificateClaimSet.cs : the semantics of the members has
changed after I practically touched this type last time.
2007-04-05 Atsushi Enomoto <atsushi@ximian.com>
* Claim.cs : added serialized fields.
2007-02-05 Atsushi Enomoto <atsushi@ximian.com>
* X509CertificateClaimSet.cs : removed extraneous claims.
2006-10-07 Atsushi Enomoto <atsushi@ximian.com>
* ClaimSet.cs : implemented System.
* Claim.cs : implement everything except for windows specific stuff.
* DefaultClaimSet.cs : implemented Initialize().
* X509CertificateClaimSet.cs : implemented some members.
2006-09-12 Atsushi Enomoto <atsushi@ximian.com>
* ClaimSet.cs : warning cleanup.
2006-09-07 Atsushi Enomoto <atsushi@ximian.com>
* Claim.cs, Rights.cs : mostly implemented.
2006-09-04 Atsushi Enomoto <atsushi@ximian.com>
* ClaimTypes.cs, DefaultClaimSet.cs, Claim.cs :
updated namespace URI.
2006-08-28 Atsushi Enomoto <atsushi@ximian.com>
* ClaimTypes.cs : implemented.
2006-07-04 Atsushi Enomoto <atsushi@ximian.com>
* ClaimSetBase.cs, DefaultClaimSet.cs : renamed from former to latter.
2006-07-04 Atsushi Enomoto <atsushi@ximian.com>
* ClaimSetBase.cs, WindowsClaimSet.cs, ClaimSet.cs, Claim.cs,
ClaimTypes.cs, X509CertificateClaimSet.cs : June CTP updates.
2006-03-22 Atsushi Enomoto <atsushi@ximian.com>
* WindowsClaimSet.cs X509CertificateClaimSet.cs : new files.
* ClaimSetBase.cs Rights.cs ClaimSet.cs Claim.cs : several updates
to match Feb. CTP.
2006-02-23 Atsushi Enomoto <atsushi@ximian.com>
* Claim.cs ClaimSet.cs ClaimSetBase.cs :
Moving namespaces to System.IdentityModel.*.
2006-02-23 Atsushi Enomoto <atsushi@ximian.com>
* Claim.cs ClaimSet.cs ClaimSetBase.cs : moved from
System.ServiceModel (via System.IdentityModel.Policy).

View File

@@ -0,0 +1,184 @@
//
// Claim.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
namespace System.IdentityModel.Claims
{
[DataContract (Namespace="http://schemas.xmlsoap.org/ws/2005/05/identity")]
public class Claim
{
class ClaimComparer : IEqualityComparer<Claim>
{
public bool Equals (Claim c1, Claim c2)
{
if (c1 == null)
return c2 == null;
else if (c2 == null)
return false;
return c1.ClaimType == c2.ClaimType &&
c1.Right == c2.Right &&
c1.Resource != null ? c1.Resource.Equals (c2.Resource) : c2.Resource == null;
}
public int GetHashCode (Claim c)
{
return c.ClaimType.GetHashCode () << 24 +
c.Right.GetHashCode () << 16 +
(c.Resource != null ? c.Resource.GetHashCode () << 8 : 0);
}
}
// static members
static readonly ClaimComparer default_comparer = new ClaimComparer ();
static readonly Claim system = new Claim (ClaimTypes.System, "System", Rights.Identity);
public static IEqualityComparer<Claim> DefaultComparer {
get { return default_comparer; }
}
public static Claim System {
get { return system; }
}
public static Claim CreateDnsClaim (string dns)
{
return new Claim (ClaimTypes.Dns, dns, Rights.PossessProperty);
}
[MonoTODO]
public static Claim CreateDenyOnlyWindowsSidClaim (SecurityIdentifier identifier)
{
throw new NotImplementedException ();
}
public static Claim CreateHashClaim (byte [] hash)
{
return new Claim (ClaimTypes.Hash, hash, Rights.PossessProperty);
}
public static Claim CreateMailAddressClaim (
MailAddress mailAddress)
{
return new Claim (ClaimTypes.Email, mailAddress, Rights.PossessProperty);
}
public static Claim CreateNameClaim (string name)
{
return new Claim (ClaimTypes.Name, name, Rights.PossessProperty);
}
public static Claim CreateRsaClaim (RSA rsa)
{
return new Claim (ClaimTypes.Rsa, rsa, Rights.PossessProperty);
}
public static Claim CreateSpnClaim (string spn)
{
return new Claim (ClaimTypes.Spn, spn, Rights.PossessProperty);
}
public static Claim CreateThumbprintClaim (byte [] thumbprint)
{
return new Claim (ClaimTypes.Thumbprint, thumbprint, Rights.PossessProperty);
}
public static Claim CreateUpnClaim (string upn)
{
return new Claim (ClaimTypes.Upn, upn, Rights.PossessProperty);
}
public static Claim CreateUriClaim (Uri uri)
{
return new Claim (ClaimTypes.Uri, uri, Rights.PossessProperty);
}
public static Claim CreateWindowsSidClaim (
SecurityIdentifier sid)
{
return new Claim (ClaimTypes.Sid, sid, Rights.PossessProperty);
}
public static Claim CreateX500DistinguishedNameClaim (
X500DistinguishedName x500DistinguishedName)
{
return new Claim (ClaimTypes.X500DistinguishedName, x500DistinguishedName, Rights.PossessProperty);
}
// since those public properties do not expose attributes,
// here I use them on the fields instead ...
[DataMember (Name = "ClaimType")]
string claim_type;
[DataMember (Name = "Resource")]
object resource;
[DataMember (Name = "Right")]
string right;
public Claim (string claimType, object resource,
string right)
{
this.claim_type = claimType;
this.resource = resource;
this.right = right;
}
public object Resource {
get { return resource; }
}
public string ClaimType {
get { return claim_type; }
}
public string Right {
get { return right; }
}
public override string ToString ()
{
return String.Concat (Right, ": ", ClaimType);
}
public override bool Equals (object obj)
{
Claim c = obj as Claim;
return c != null && DefaultComparer.Equals (this, c);
}
public override int GetHashCode ()
{
return DefaultComparer.GetHashCode (this);
}
}
}

View File

@@ -0,0 +1,83 @@
//
// ClaimSet.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace System.IdentityModel.Claims
{
[DataContract (Namespace="http://schemas.xmlsoap.org/ws/2005/05/identity")]
public abstract class ClaimSet : IEnumerable<Claim>, IEnumerable
{
static ClaimSet system = DefaultClaimSet.CreateSystemClaimSet ();
static ClaimSet win;
public static ClaimSet System {
get { return system; }
}
[MonoTODO]
public static ClaimSet Windows {
get { return win; }
}
protected ClaimSet ()
{
}
public abstract int Count { get; }
public abstract ClaimSet Issuer { get; }
public abstract Claim this [int index] { get; }
public virtual bool ContainsClaim (Claim claim)
{
return ContainsClaim (claim, Claim.DefaultComparer);
}
public virtual bool ContainsClaim (Claim claim, IEqualityComparer<Claim> comparer)
{
foreach (Claim c in this)
if (comparer.Equals (claim, c))
return true;
return false;
}
public abstract IEnumerable<Claim> FindClaims (
string resourceType, string right);
public abstract IEnumerator<Claim> GetEnumerator ();
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
}

View File

@@ -0,0 +1,158 @@
//
// ClaimTypes.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.IdentityModel.Claims
{
public static class ClaimTypes
{
public static string Anonymous {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/anonymous"; }
}
public static string Authentication {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authentication"; }
}
public static string AuthorizationDecision {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authorizationdecision"; }
}
public static string Country {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country"; }
}
public static string DateOfBirth {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth"; }
}
public static string DenyOnlySid {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/denyonlysid"; }
}
public static string Dns {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns"; }
}
public static string Email {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"; }
}
public static string Gender {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/gender"; }
}
public static string GivenName {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname"; }
}
public static string Hash {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/hash"; }
}
public static string HomePhone {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/homephone"; }
}
public static string Locality {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/locality"; }
}
public static string MobilePhone {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone"; }
}
public static string Name {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; }
}
public static string NameIdentifier {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"; }
}
public static string OtherPhone {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/otherphone"; }
}
public static string PostalCode {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/postalcode"; }
}
public static string PPID {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier"; }
}
public static string Rsa {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/rsa"; }
}
public static string Sid {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid"; }
}
public static string Spn {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/spn"; }
}
public static string StateOrProvince {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/stateorprovince"; }
}
public static string StreetAddress {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/streetaddress"; }
}
public static string Surname {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname"; }
}
public static string System {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/system"; }
}
public static string Thumbprint {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint"; }
}
public static string Upn {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"; }
}
public static string Uri {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uri"; }
}
public static string Webpage {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/webpage"; }
}
public static string X500DistinguishedName {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/x500distinguishedname"; }
}
}
}

View File

@@ -0,0 +1,147 @@
//
// DefaultClaimSet.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace System.IdentityModel.Claims
{
[DataContract (Namespace="http://schemas.xmlsoap.org/ws/2005/05/identity")]
public class DefaultClaimSet : ClaimSet
{
internal static DefaultClaimSet CreateSystemClaimSet ()
{
DefaultClaimSet s = new DefaultClaimSet ();
s.Initialize (s, new Claim [] {Claim.System, new Claim (ClaimTypes.System, "System", Rights.PossessProperty)});
return s;
}
List<Claim> list = new List<Claim> ();
ClaimSet issuer;
// Constructors
internal DefaultClaimSet ()
{
}
public DefaultClaimSet (params Claim[] claims)
{
list.AddRange (claims);
}
public DefaultClaimSet (IList<Claim> claims)
{
list.AddRange (claims);
}
public DefaultClaimSet (ClaimSet issuer, params Claim[] claims)
{
this.issuer = issuer;
list.AddRange (claims);
}
public DefaultClaimSet (ClaimSet issuer, IList<Claim> claims)
{
this.issuer = issuer;
list.AddRange (claims);
}
// Properties
public override int Count {
get { return list.Count; }
}
public override ClaimSet Issuer {
get { return issuer; }
}
public override Claim this [int index] {
get { return list [index]; }
}
// Methods
public override bool ContainsClaim (Claim claim)
{
return base.ContainsClaim (claim);
}
public override IEnumerable<Claim> FindClaims (
string claimType, string right)
{
return new ClaimListFilter (this, claimType);
}
public override IEnumerator<Claim> GetEnumerator ()
{
return list.GetEnumerator ();
}
protected void Initialize (ClaimSet issuer, IList<Claim> claims)
{
this.issuer = issuer;
foreach (Claim c in claims)
list.Add (c);
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
// Types
class ClaimListFilter : IEnumerable<Claim>
{
DefaultClaimSet source;
string claim_type;
public ClaimListFilter (DefaultClaimSet source, string claimType)
{
claim_type = claimType;
this.source = source;
}
public IEnumerator<Claim> GetEnumerator ()
{
foreach (Claim c in source)
if (c.ClaimType == claim_type)
yield return c;
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
}
}

View File

@@ -0,0 +1,42 @@
//
// Rights.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.IdentityModel.Claims
{
public static class Rights
{
public static string Identity {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/right/identity"; }
}
public static string PossessProperty {
get { return "http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty"; }
}
}
}

View File

@@ -0,0 +1,114 @@
//
// WindowsClaimSet.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Principal;
namespace System.IdentityModel.Claims
{
public class WindowsClaimSet : ClaimSet, IDisposable
{
WindowsIdentity identity;
DateTime expiration_time;
// Constructors
[MonoTODO]
public WindowsClaimSet (WindowsIdentity identity)
{
throw new NotImplementedException ();
}
[MonoTODO]
public WindowsClaimSet (WindowsIdentity identity, bool includeWindowsGroups)
{
throw new NotImplementedException ();
}
[MonoTODO]
public WindowsClaimSet (WindowsIdentity identity, DateTime expirationTime)
{
throw new NotImplementedException ();
}
[MonoTODO]
public WindowsClaimSet (WindowsIdentity identity, bool includeWindowsGroups, DateTime expirationTime)
{
throw new NotImplementedException ();
}
// Properties
public override int Count {
get { throw new NotImplementedException (); }
}
public override ClaimSet Issuer {
get { throw new NotImplementedException (); }
}
public override Claim this [int index] {
get { throw new NotImplementedException (); }
}
public DateTime ExpirationTime {
get { return expiration_time; }
}
public WindowsIdentity WindowsIdentity {
get { return identity; }
}
// Methods
[MonoTODO]
public void Dispose ()
{
}
[MonoTODO]
public override IEnumerable<Claim> FindClaims (
string claimType, string right)
{
throw new NotImplementedException ();
}
[MonoTODO]
public override IEnumerator<Claim> GetEnumerator ()
{
throw new NotImplementedException ();
}
public override string ToString ()
{
return base.ToString ();
}
}
}

View File

@@ -0,0 +1,128 @@
//
// X509CertificateClaimSet.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace System.IdentityModel.Claims
{
public class X509CertificateClaimSet : ClaimSet, IDisposable
{
X509Certificate2 cert;
ClaimSet issuer;
List<Claim> claims = new List<Claim> ();
// Constructors
class X509IdentityClaimSet : DefaultClaimSet
{
public X509IdentityClaimSet (Claim c)
{
Initialize (this, new Claim [] {c});
}
}
public X509CertificateClaimSet (X509Certificate2 certificate)
{
if (certificate == null)
throw new ArgumentNullException ("certificate");
this.cert = certificate;
Claim ident = new Claim (ClaimTypes.Thumbprint, cert.Thumbprint, Rights.Identity);
// issuer = new X509IdentityClaimSet (ident);
claims.Add (ident);
//claims.Add (Claim.CreateX500DistinguishedNameClaim (cert.SubjectName));
//claims.Add (Claim.CreateNameClaim (cert.SubjectName.Name));
RSA rsa = cert.PublicKey.Key as RSA;
if (rsa != null)
claims.Add (Claim.CreateRsaClaim (rsa));
claims.Add (Claim.CreateThumbprintClaim (cert.GetCertHash ()));
// FIXME: where is DNS info for X509 cert?
claims.Add (Claim.CreateDnsClaim (null));
}
// Properties
public override int Count {
get { return claims.Count; }
}
public override ClaimSet Issuer {
get {
if (issuer == null) {
X509Chain chain = new X509Chain ();
chain.Build (cert);
if (chain.ChainElements.Count <= 1)
throw new InvalidOperationException ("hmm, the certificate chain does not contain enough information");
issuer = new X509CertificateClaimSet (chain.ChainElements [1].Certificate);
}
return issuer;
}
}
public override Claim this [int index] {
get { return claims [index]; }
}
[MonoTODO ("use ParseExact")]
public DateTime ExpirationTime {
get { return DateTime.Parse (cert.GetExpirationDateString ()); }
}
public X509Certificate2 X509Certificate {
get { return cert; }
}
// Methods
[MonoTODO]
public void Dispose ()
{
}
[MonoTODO]
public override IEnumerable<Claim> FindClaims (
string claimType, string right)
{
throw new NotImplementedException ();
}
public override IEnumerator<Claim> GetEnumerator ()
{
return claims.GetEnumerator ();
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
}
}