I have a http listener app that is getting requests from a client app. Im trying to use AD user names and groups to control access to the app. When I originally built this proof of concept it worked like I had intended but now its busted and I can't figure out why.
What is supposed to happen is the server will run and when a client connects it prints out if they have access to a group that I'm testing. I remember seeing this work in the past but since then I modified the code for another test and now its kaput.
Any ideas?
Server Code:
Client Code:Code:static void Main(string[] args) { HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://myhost/"); listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate; listener.Start(); bool validUser; while (true) { HttpListenerContext ctx = listener.GetContext(); HttpListenerBasicIdentity identity = ctx.User.Identity as HttpListenerBasicIdentity; if (identity != null) { Console.WriteLine(identity.Name); Console.WriteLine(identity.Password); } string[] groups = new string[] {"Group1", "Group2", "Group3", "Group4" }; Console.WriteLine("Checking user {0}", ctx.User.Identity.Name); foreach (string group in groups) { Console.Write("Group {0}:{1}", group, ctx.User.IsInRole(group)?"True":"False"); } } }
Code:static void Main(string[] args) { string userId, password; for (int i = 1; i < 5; ++i) { userId = string.Format("domin\User{0}", i); password = "pasword"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://myhost/"); req.UseDefaultCredentials = false; req.Credentials = new NetworkCredential(userId, password); req.GetResponse(); } }




Reply With Quote