[Test] Avoid MethodInfoTest.GetMethodBody failure when executed on a release (IL...
[mono.git] / mcs / class / corlib / System.Security.Principal / WindowsIdentity.cs
index d2fb73269503e3ec072d08742540b7576be66d55..8c431515299405def6f815633129ca93eafda67a 100644 (file)
@@ -37,14 +37,8 @@ using System.Security.Permissions;
 namespace System.Security.Principal {
 
        [Serializable]
-#if NET_1_0
-       public class WindowsIdentity : IIdentity, IDeserializationCallback {
-#elif NET_2_0
        [ComVisible (true)]
        public class WindowsIdentity : IIdentity, IDeserializationCallback, ISerializable, IDisposable {
-#else
-       public class WindowsIdentity : IIdentity, IDeserializationCallback, ISerializable {
-#endif
                private IntPtr _token;
                private string _type;
                private WindowsAccountType _account;
@@ -53,8 +47,6 @@ namespace System.Security.Principal {
                private SerializationInfo _info;
 
                static private IntPtr invalidWindows = IntPtr.Zero;
-               // that seems to be the value used for (at least) AIX and MacOSX
-               static private IntPtr invalidPosix = (IntPtr) unchecked (-2);
 
                [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
                public WindowsIdentity (IntPtr userToken) 
@@ -84,7 +76,7 @@ namespace System.Security.Principal {
                        // last - as it can override some fields
                        SetToken (userToken);
                }
-#if !NET_1_0
+
                [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
                public WindowsIdentity (string sUserPrincipalName) 
                        : this (sUserPrincipalName, null)
@@ -99,7 +91,7 @@ namespace System.Security.Principal {
 
                        // TODO: Windows 2003 compatibility should be done in runtime
                        IntPtr token = GetUserToken (sUserPrincipalName);
-                       if ((!IsPosix) && (token == IntPtr.Zero)) {
+                       if ((!Environment.IsUnix) && (token == IntPtr.Zero)) {
                                throw new ArgumentException ("only for Windows Server 2003 +");
                        }
 
@@ -115,9 +107,7 @@ namespace System.Security.Principal {
                {
                        _info = info;
                }
-#endif
 
-#if NET_2_0
                [ComVisible (false)]
                public void Dispose ()
                {
@@ -129,20 +119,12 @@ namespace System.Security.Principal {
                {
                        _token = IntPtr.Zero;
                }
-#else
-               ~WindowsIdentity ()
-               {
-                       // clear our copy but don't close it
-                       // http://www.develop.com/kbrown/book/html/whatis_windowsprincipal.html
-                       _token = IntPtr.Zero;
-               }
-#endif
                // static methods
 
                public static WindowsIdentity GetAnonymous ()
                {
                        WindowsIdentity id = null;
-                       if (IsPosix) {
+                       if (Environment.IsUnix) {
                                id = new WindowsIdentity ("nobody");
                                // special case
                                id._account = WindowsAccountType.Anonymous;
@@ -161,7 +143,6 @@ namespace System.Security.Principal {
                {
                        return new WindowsIdentity (GetCurrentToken (), null, WindowsAccountType.Normal, true);
                }
-#if NET_2_0
                [MonoTODO ("need icall changes")]
                public static WindowsIdentity GetCurrent (bool ifImpersonating)
                {
@@ -173,7 +154,6 @@ namespace System.Security.Principal {
                {
                        throw new NotImplementedException ();
                }
-#endif
                // methods
 
                public virtual WindowsImpersonationContext Impersonate ()
@@ -189,11 +169,7 @@ namespace System.Security.Principal {
 
                // properties
 
-#if NET_2_0
                public string AuthenticationType {
-#else
-               public virtual string AuthenticationType {
-#endif
                        get { return _type; }
                }
 
@@ -232,7 +208,6 @@ namespace System.Security.Principal {
                {
                        get { return _token; }
                }
-#if NET_2_0
                [MonoTODO ("not implemented")]
                public IdentityReferenceCollection Groups {
                        get { throw new NotImplementedException (); }
@@ -255,7 +230,6 @@ namespace System.Security.Principal {
                public SecurityIdentifier User {
                        get { throw new NotImplementedException (); }
                }
-#endif
                void IDeserializationCallback.OnDeserialization (object sender)
                {
                        _token = (IntPtr) _info.GetValue ("m_userToken", typeof (IntPtr));
@@ -270,14 +244,14 @@ namespace System.Security.Principal {
                        else {
                                // validate token by getting name
                                _name = GetTokenName (_token);
-                               if ((_name == String.Empty) || (_name == null))
+                               if (_name == null)
                                        throw new SerializationException ("Token doesn't match a user.");
                        }
                        _type = _info.GetString ("m_type");
                        _account = (WindowsAccountType) _info.GetValue ("m_acctType", typeof (WindowsAccountType));
                        _authenticated = _info.GetBoolean ("m_isAuthenticated");
                }
-#if !NET_1_0
+
                void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) 
                {
                        info.AddValue ("m_userToken", _token);
@@ -287,16 +261,10 @@ namespace System.Security.Principal {
                        info.AddValue ("m_acctType", _account);
                        info.AddValue ("m_isAuthenticated", _authenticated);
                }
-#endif
-               private static bool IsPosix {
-                       get { return ((int) Environment.Platform == 128); }
-               }
 
                private void SetToken (IntPtr token) 
                {
-                       if (IsPosix) {
-                               if (token == invalidPosix)
-                                       throw new ArgumentException ("Invalid token");
+                       if (Environment.IsUnix) {
 
                                _token = token;
                                // apply defaults