//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
// Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Runtime.Serialization;
+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
// 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)
: this (userToken, null, WindowsAccountType.Normal, false)
{
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type)
: this (userToken, type, WindowsAccountType.Normal, false)
{
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType)
: this (userToken, type, acctType, false)
{
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
{
_type = type;
SetToken (userToken);
}
#if !NET_1_0
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (string sUserPrincipalName)
: this (sUserPrincipalName, null)
{
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (string sUserPrincipalName, string type)
{
if (sUserPrincipalName == null)
SetToken (token);
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (SerializationInfo info, StreamingContext context)
{
_info = info;
}
#endif
+#if NET_2_0
+ [ComVisible (false)]
+ public void Dispose ()
+ {
+ _token = IntPtr.Zero;
+ }
+
+ [ComVisible (false)]
+ protected virtual void Dispose (bool disposing)
+ {
+ _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 ()
{
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 ();
+ }
+ [MonoTODO ("need icall changes")]
+ public static WindowsIdentity GetCurrent (TokenAccessLevels desiredAccess)
+ {
+ throw new NotImplementedException ();
+ }
+#endif
// methods
public virtual WindowsImpersonationContext Impersonate ()
return new WindowsImpersonationContext (_token);
}
+ [SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public static WindowsImpersonationContext Impersonate (IntPtr userToken)
{
return new WindowsImpersonationContext (userToken);
{
get { return _token; }
}
+#if NET_2_0
+ [MonoTODO ("not implemented")]
+ public IdentityReferenceCollection Groups {
+ get { throw new NotImplementedException (); }
+ }
+ [MonoTODO ("not implemented")]
+ [ComVisible (false)]
+ public TokenImpersonationLevel ImpersonationLevel {
+ get { throw new NotImplementedException (); }
+ }
+
+ [MonoTODO ("not implemented")]
+ [ComVisible (false)]
+ public SecurityIdentifier Owner {
+ get { throw new NotImplementedException (); }
+ }
+
+ [MonoTODO ("not implemented")]
+ [ComVisible (false)]
+ public SecurityIdentifier User {
+ get { throw new NotImplementedException (); }
+ }
+#endif
void IDeserializationCallback.OnDeserialization (object sender)
{
_token = (IntPtr) _info.GetValue ("m_userToken", typeof (IntPtr));