[Mono-bugs] [Bug 52530][Cri] New - Cannot find type `WindowsPrincipal'

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 24 Dec 2003 00:43:43 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by xiaoming.lin@longshine.com.

http://bugzilla.ximian.com/show_bug.cgi?id=52530

--- shadow/52530	2003-12-24 00:43:43.000000000 -0500
+++ shadow/52530.tmp.13422	2003-12-24 00:43:43.000000000 -0500
@@ -0,0 +1,189 @@
+Bug#: 52530
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 040 One week
+Priority: Critical
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: xiaoming.lin@longshine.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Cannot find type `WindowsPrincipal'
+
+Steps to reproduce the problem:
+1. I have a file can't compile
+//===================================================================
+// 
+// Copyright (C) Longshine Corporation. All rights reserved.
+// 
+// Project:  Indigo
+// 
+// File:     SecurityToolkit.cs
+// 
+// Contents: 
+// 
+// Owner:    yihui@longshine.com
+// 
+// History:  2002/06/10     Created.
+// 
+//===================================================================
+using System;
+using System.Data;
+using System.Collections;
+using System.Collections.Specialized;
+using System.DirectoryServices;
+using System.Security;
+using System.Security.Principal;
+namespace Longshine.Indigo.Runtime.Security {
+    public sealed class SecurityToolkit {
+        private SecurityToolkit() {}
+        public static string GetWindowsIdentityLdapPath(WindowsIdentity 
+identity) {
+            if (identity == null) {
+                Debug.Trace("indentity 为空.");
+                throw new ArgumentException("不能为空.", "identity");
+            }
+            if (!identity.IsAuthenticated) {
+                throw new Exception("a","b");
+            }
+
+            using (DirectoryEntry user = GetWindowsIdentityLdapEntry
+(identity)) {
+                return user.Path;
+            }
+        }
+
+        public static DirectoryEntry GetWindowsIdentityLdapEntry
+(WindowsIdentity identity) {
+            if (identity == null) {
+                Debug.Trace("identity 为空.");
+                throw new ArgumentException("不能为空.", "identity");
+            }
+            if (!identity.IsAuthenticated) {
+                throw new Exception("a","b");
+            }
+
+            string userName = identity.Name;
+
+            int index = userName.LastIndexOf(@"\");
+
+            string sn;
+
+            if (index >= 0) {
+                sn = userName.Substring(index + 1);
+            }
+            else {
+                sn = userName;
+            }
+
+            return SecurityEnvironment.GetUserEntryBySamAccountName(sn);
+        }
+        public static StringCollection GetStationProvinces(DirectoryEntry 
+station) {
+            StringCollection provinces = new StringCollection();
+            string perfix = "CN=" + 
+SecurityEnvironment.ProvincePerfix.ToUpper();
+
+            foreach (string s in station.Properties["memberOf"]) {
+                string s2 = s.ToUpper();
+                if (s2.StartsWith(perfix)) {
+                    string provincePath = "LDAP://" + s2;
+                    provinces.Add(provincePath);
+                }
+            }
+
+            return provinces;
+        }
+
+        public static StringCollection GetUserStations(DirectoryEntry 
+user) {
+            StringCollection stations = new StringCollection();
+            string perfix = "CN=" + 
+SecurityEnvironment.StationPerfix.ToUpper();
+
+            foreach (string s in user.Properties["memberOf"]) {
+                string s2 = s.ToUpper();
+
+                if (s2.StartsWith(perfix)) {
+                    string stationPath = "LDAP://" + s2;
+                    stations.Add(stationPath);
+                }
+            }
+            return stations;
+            
+        }
+
+        public static void CombineStringCollection(
+            StringCollection from, 
+            StringCollection to) {
+            foreach (string s in from) {
+                if (!to.Contains(s))
+                    to.Add(s);
+            }
+        }
+
+        public static StringCollection GetUserProvinces(DirectoryEntry 
+user) {
+            StringCollection stations = GetUserStations(user);
+            StringCollection provinces = new StringCollection();
+
+            foreach (string stationPath in stations) {
+                using (DirectoryEntry station = new DirectoryEntry(
+                           stationPath,
+                           SecurityEnvironment.AdminName,
+                           SecurityEnvironment.AdminPassword,
+                           AuthenticationTypes.Secure)) {
+
+                    CombineStringCollection(GetStationProvinces(station), 
+provinces);
+                }
+            }
+
+            return provinces;
+        }
+
+        public static StringCollection GetUserProvinces(WindowsPrincipal 
+user) {
+            if (user == null)
+                throw new ArgumentException("不能为空.", "user");
+
+            if (!user.Identity.IsAuthenticated)
+                throw new SecurityException("用户尚螏蜌过验謤.");
+
+            using (DirectoryEntry userEntry = GetWindowsIdentityLdapEntry
+((WindowsIdentity)user.Identity)) {
+                return GetUserProvinces(userEntry);
+            }
+        }
+    }
+}
+
+2.  mcs SecurityToolkit.cs -r:/usr/local/lib/System.dll -
+r:/usr/local/lib/System.Data.dll -
+r:/usr/local/lib/System.DirectoryServices.dll -out:a.dll /t:library
+
+3. 
+Actual Results:
+
+SecurityToolkit.cs(126) error CS0246: Cannot find type `WindowsPrincipal'
+Compilation failed: 1 error(s), 0 warnings
+
+
+Expected Results:
+Compilation succeeded
+
+How often does this happen? 
+always
+
+
+Additional Information:
+
+We develope our project under Windows2000,it also works with framework1.1,
+we want move to linux+mono.
+thank a lot