2003-12-25 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / corlib / System.Security.Principal / WindowsIdentity.cs
1 //
2 // System.Security.Principal.WindowsIdentity
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 using System;
13 using System.Runtime.Serialization;
14
15 namespace System.Security.Principal {
16
17         [Serializable]
18 #if NET_1_0
19         public class WindowsIdentity : IIdentity, IDeserializationCallback {
20 #else
21         public class WindowsIdentity : IIdentity, IDeserializationCallback, ISerializable {
22 #endif
23                 private IntPtr _token;
24                 private string _type;
25                 private WindowsAccountType _account;
26                 private bool _authenticated;
27
28                 public WindowsIdentity (IntPtr userToken)
29                 {
30                         _token = userToken;
31                         _type = "NTLM";
32                         _account = WindowsAccountType.Normal;
33                         _authenticated = false;
34                 }
35
36                 public WindowsIdentity (IntPtr userToken, string type)
37                 {
38                         _token = userToken;
39                         _type = type;
40                         _account = WindowsAccountType.Normal;
41                         _authenticated = false;
42                 }
43
44                 public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType)
45                 {
46                         _token = userToken;
47                         _type = type;
48                         _account = acctType;
49                         _authenticated = false;
50                 }
51
52                 public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
53                 {
54                         _token = userToken;
55                         _type = type;
56                         _account = acctType;
57                         _authenticated = isAuthenticated;
58                 }
59 #if !NET_1_0
60                 [MonoTODO]
61                 public WindowsIdentity (string sUserPrincipalName) 
62                 {
63                         throw new ArgumentException ("only for Windows Server 2003 +");
64                 }
65
66                 [MonoTODO]
67                 public WindowsIdentity (string sUserPrincipalName, string type)
68                 {
69                         throw new ArgumentException ("only for Windows Server 2003 +");
70                 }
71
72                 [MonoTODO]
73                 public WindowsIdentity (SerializationInfo info, StreamingContext context) {}
74 #endif
75                 [MonoTODO]
76                 ~WindowsIdentity ()
77                 {
78                         _token = (IntPtr) 0;
79                 }
80
81                 // methods
82
83                 [MonoTODO]
84                 public static WindowsIdentity GetAnonymous ()
85                 {
86                         throw new NotImplementedException ();
87                 }
88
89                 [MonoTODO]
90                 public static WindowsIdentity GetCurrent ()
91                 {
92                         throw new NotImplementedException ();
93                 }
94
95                 public virtual WindowsImpersonationContext Impersonate ()
96                 {
97                         return new WindowsImpersonationContext (_token);
98                 }
99
100                 public static WindowsImpersonationContext Impersonate (IntPtr userToken)
101                 {
102                         return new WindowsImpersonationContext (userToken);
103                 }
104
105                 // properties
106
107                 public virtual string AuthenticationType
108                 {
109                         get { return _type; }
110                 }
111
112                 public virtual bool IsAnonymous
113                 {
114                         get { return (_account == WindowsAccountType.Anonymous); }
115                 }
116
117                 public virtual bool IsAuthenticated
118                 {
119                         get { return _authenticated; }
120                 }
121
122                 public virtual bool IsGuest
123                 {
124                         get { return (_account == WindowsAccountType.Guest); }
125                 }
126
127                 public virtual bool IsSystem
128                 {
129                         get { return (_account == WindowsAccountType.System); }
130                 }
131
132                 [MonoTODO]
133                 public virtual string Name
134                 {
135                         get {
136                                 throw new NotImplementedException ();
137                         }
138                 }
139
140                 public virtual IntPtr Token
141                 {
142                         get { return _token; }
143                 }
144
145                 [MonoTODO]
146                 void IDeserializationCallback.OnDeserialization (object sender)
147                 {
148                         throw new NotImplementedException ();
149                 }
150 #if !NET_1_0
151                 [MonoTODO]
152                 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) 
153                 {
154                         throw new NotImplementedException ();
155                 }
156 #endif
157         }
158 }
159