2 // System.Security.Principal.WindowsIdentity
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Sebastien Pouliot (spouliot@motus.com)
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
13 using System.Runtime.Serialization;
15 namespace System.Security.Principal {
19 public class WindowsIdentity : IIdentity, IDeserializationCallback {
21 public class WindowsIdentity : IIdentity, IDeserializationCallback, ISerializable {
23 private IntPtr _token;
25 private WindowsAccountType _account;
26 private bool _authenticated;
29 public WindowsIdentity (IntPtr userToken)
30 : this (userToken, "NTLM", WindowsAccountType.Normal, false) {}
32 public WindowsIdentity (IntPtr userToken, string type)
33 : this (userToken, type, WindowsAccountType.Normal, false) {}
35 public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType)
36 : this (userToken, type, acctType, false) {}
38 public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
40 if (userToken == IntPtr.Zero)
41 throw new ArgumentException ("Invalid token");
46 _authenticated = isAuthenticated;
50 public WindowsIdentity (string sUserPrincipalName)
51 : this (sUserPrincipalName, null) {}
54 public WindowsIdentity (string sUserPrincipalName, string type)
56 if (sUserPrincipalName == null)
57 throw new NullReferenceException ("sUserPrincipalName");
59 throw new ArgumentException ("only for Windows Server 2003 +");
63 public WindowsIdentity (SerializationInfo info, StreamingContext context) {}
73 public static WindowsIdentity GetAnonymous ()
75 WindowsIdentity id = new WindowsIdentity ((IntPtr)1, String.Empty, WindowsAccountType.Anonymous, false);
77 id._token = IntPtr.Zero;
78 id._name = String.Empty;
83 public static WindowsIdentity GetCurrent ()
85 throw new NotImplementedException ();
90 public virtual WindowsImpersonationContext Impersonate ()
92 return new WindowsImpersonationContext (_token);
95 public static WindowsImpersonationContext Impersonate (IntPtr userToken)
97 return new WindowsImpersonationContext (userToken);
102 public virtual string AuthenticationType
104 get { return _type; }
107 public virtual bool IsAnonymous
109 get { return (_account == WindowsAccountType.Anonymous); }
112 public virtual bool IsAuthenticated
114 get { return _authenticated; }
117 public virtual bool IsGuest
119 get { return (_account == WindowsAccountType.Guest); }
122 public virtual bool IsSystem
124 get { return (_account == WindowsAccountType.System); }
127 [MonoTODO ("resolve missing")]
128 public virtual string Name
132 // TODO: resolve name from token
133 throw new NotImplementedException ();
139 public virtual IntPtr Token
141 get { return _token; }
145 void IDeserializationCallback.OnDeserialization (object sender)
147 throw new NotImplementedException ();
151 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
153 throw new NotImplementedException ();