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;
// 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)
// 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 +");
}
{
_info = info;
}
-#endif
-#if NET_2_0
[ComVisible (false)]
public void Dispose ()
{
{
_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;
{
return new WindowsIdentity (GetCurrentToken (), null, WindowsAccountType.Normal, true);
}
-#if NET_2_0
[MonoTODO ("need icall changes")]
public static WindowsIdentity GetCurrent (bool ifImpersonating)
{
{
throw new NotImplementedException ();
}
-#endif
// methods
public virtual WindowsImpersonationContext Impersonate ()
// properties
-#if NET_2_0
public string AuthenticationType {
-#else
- public virtual string AuthenticationType {
-#endif
get { return _type; }
}
{
get { return _token; }
}
-#if NET_2_0
[MonoTODO ("not implemented")]
public IdentityReferenceCollection Groups {
get { throw new NotImplementedException (); }
public SecurityIdentifier User {
get { throw new NotImplementedException (); }
}
-#endif
void IDeserializationCallback.OnDeserialization (object sender)
{
_token = (IntPtr) _info.GetValue ("m_userToken", typeof (IntPtr));
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);
info.AddValue ("m_acctType", _account);
info.AddValue ("m_isAuthenticated", _authenticated);
}
-#endif
- private static bool IsPosix {
- get { return ((int) Environment.Platform == 128) || ((int)Environment.Platform == 4); }
- }
private void SetToken (IntPtr token)
{
- if (IsPosix) {
+ if (Environment.IsUnix) {
_token = token;
// apply defaults