public void TestLogonLocalUser() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); IWindowsIdentity account = windowsAuthProviderImpl.LogonUser(_testUser.usri1_name, _testUser.usri1_password); Console.WriteLine("Sid: {0}", account.SidString); Console.WriteLine("Fqn: {0}", account.Fqn); Console.WriteLine("Guest: {0}", account.IsGuest); Assert.AreEqual(account.Fqn.ToLower(), _testUserFqn.ToLower()); Assert.IsTrue(Advapi32.IsValidSid(account.Sid)); Assert.IsFalse(account.IsGuest); Console.WriteLine("Groups: {0}", account.Groups.Length); }
public void TestImpersonation() { WindowsAuthProviderImpl windowsAuthProviderImpl = new WindowsAuthProviderImpl(); IWindowsIdentity account = windowsAuthProviderImpl.LogonUser(_testUser.usri1_name, _testUser.usri1_password); IWindowsImpersonationContext impersonationCtx = account.Impersonate(); try { Console.WriteLine(account.SidString); Console.WriteLine(account.Fqn); Assert.AreEqual(account.Fqn, WindowsIdentity.GetCurrent().Name); } finally { impersonationCtx.RevertToSelf(); Assert.AreNotEqual(account.Fqn, WindowsIdentity.GetCurrent().Name); } }
public void Returns_current_windows_username() { MockRepository mocks = new MockRepository(); IWindowsIdentity windowsIdentity = mocks.CreateMock <IWindowsIdentity>(); using (mocks.Record()) { Expect.Call(windowsIdentity.GetCurrentUsername()).Return(@"MY_LAPTOP\khurwitz"); } using (mocks.Playback()) { ISecurityContext context = new SecurityContext(windowsIdentity); string username = context.GetCurrentUsername(); Assert.That(username, Is.EqualTo("khurwitz")); } mocks.VerifyAll(); }
public SecurityContext(IWindowsIdentity windowsIdentity) { _windowsIdentity = windowsIdentity; }
public SecurityContext(IWindowsIdentity windowsIdentity) { _windowsIdentity = windowsIdentity; }