protected AdUser DisplayCurUser() { CurUser = GetCurUser(); if (CurUser == new AdUser()) { RedirectToAction("AccessDenied", "Error"); } ViewBag.CurUser = CurUser; return(CurUser); }
public AdUser GetCurUser() { AdUser user = new AdUser(); try { using (WindowsImpersonationContextFacade impersonationContext = new WindowsImpersonationContextFacade( nc)) { var wi = (WindowsIdentity)base.User.Identity; if (wi.User != null) { var domain = new PrincipalContext(ContextType.Domain); string sid = wi.User.Value; user.Sid = sid; var login = wi.Name.Remove(0, wi.Name.IndexOf("\\", StringComparison.CurrentCulture) + 1); user.Login = login; //var userPrincipal = UserPrincipal.FindByIdentity(domain, login); //if (userPrincipal != null) //{ // var mail = userPrincipal.EmailAddress; // var name = userPrincipal.DisplayName; // user.Email = mail; // user.FullName = name; // user.AdGroups = new List<AdGroup>(); // var wp = new WindowsPrincipal(wi); // foreach (var role in AdUserGroup.GetList()) // { // var grpSid = new SecurityIdentifier(role.Sid); // if (wp.IsInRole(grpSid)) // { // user.AdGroups.Add(role.Group); // } // } //} } } } catch (Exception ex) { throw; } return(user); }
public AdUser GetCurUser() { AdUser user = new AdUser(); try { using (WindowsImpersonationContextFacade impersonationContext = new WindowsImpersonationContextFacade( nc)) { var wi = (WindowsIdentity)base.User.Identity; if (wi.User != null) { var domain = new PrincipalContext(ContextType.Domain); string sid = wi.User.Value; user.Sid = sid; var login = wi.Name.Remove(0, wi.Name.IndexOf("\\", StringComparison.CurrentCulture) + 1); user.Login = login; var userPrincipal = UserPrincipal.FindByIdentity(domain, login); if (userPrincipal != null) { var mail = userPrincipal.EmailAddress; var name = userPrincipal.DisplayName; user.Email = mail; user.FullName = name; user.AdGroups = new List<AdGroup>(); var wp = new WindowsPrincipal(wi); foreach (var role in AdUserGroup.GetList()) { var grpSid = new SecurityIdentifier(role.Sid); if (wp.IsInRole(grpSid)) { user.AdGroups.Add(role.Group); } } } } } } catch (Exception ex) { throw; } return user; }
protected AdUser DisplayCurUser() { CurUser = GetCurUser(); if (CurUser == new AdUser()) { RedirectToAction("AccessDenied", "Error"); } ViewBag.CurUser = CurUser; //ViewBag.TechAccess = CurUser.HasAccess(AdGroup.ServiceTech); //ViewBag.AdminAccess = CurUser.HasAccess(AdGroup.ServiceAdmin); //ViewBag.ManagerAccess = CurUser.HasAccess(AdGroup.ServiceManager); //ViewBag.EngeneerAccess = CurUser.HasAccess(AdGroup.ServiceEngeneer); //ViewBag.UserIsTech = CurUser.Is(AdGroup.ServiceTech); //ViewBag.UserIsAdmin = CurUser.Is(AdGroup.ServiceAdmin); //ViewBag.UserIsManager = CurUser.Is(AdGroup.ServiceManager); //ViewBag.UserIsEngeneer = CurUser.Is(AdGroup.ServiceEngeneer); return(CurUser); }
public static AdUser GetUserBySid(string sid) { var result = new AdUser(); using (WindowsImpersonationContextFacade impersonationContext = new WindowsImpersonationContextFacade( nc)) { var context = new PrincipalContext(ContextType.Domain); var userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.Sid, sid); if (userPrincipal != null) { result.Sid = sid; result.FullName = userPrincipal.DisplayName; //result.DisplayName = MainHelper.ShortName(result.FullName); result.Email = userPrincipal.EmailAddress; } } return result; }
public AdUser GetCurUser() { AdUser user = new AdUser(); try { //////List<GroupPrincipal> result = new List<GroupPrincipal>(); //////// establish domain context //////PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain); //////// find your user //////UserPrincipal usr = UserPrincipal.FindByIdentity(yourDomain, userName); //////// if found - grab its groups //////if (user != null) //////{ ////// PrincipalSearchResult<Principal> groups = usr.GetAuthorizationGroups(); ////// // iterate over all groups ////// foreach (Principal p in groups) ////// { ////// // make sure to add only group principals ////// if (p is GroupPrincipal) ////// { ////// result.Add((GroupPrincipal)p); ////// } ////// } //////} //////return user; string fakeSid = null; string fakeLosgin = null; //fakeSid = "S-1-5-21-1970802976-3466419101-4042325969-3837"; //fakeLosgin = "olga.skidan"; using (WindowsImpersonationContextFacade impersonationContext = new WindowsImpersonationContextFacade( nc)) { var wi = (WindowsIdentity)base.User.Identity; if (wi.User != null) { var domain = new PrincipalContext(ContextType.Domain); string sid = fakeSid ?? wi.User.Value; user.Sid = sid; var login = fakeLosgin ?? wi.Name.Remove(0, wi.Name.IndexOf("\\", StringComparison.CurrentCulture) + 1); user.Login = login; var userPrincipal = UserPrincipal.FindByIdentity(domain, login); if (userPrincipal != null) { var mail = userPrincipal.EmailAddress; var name = userPrincipal.DisplayName; user.Email = mail; user.FullName = name; //user.AdGroups = new List<AdGroup>(); //var wp = new WindowsPrincipal(wi); //foreach (var role in AdUserGroup.GetList()) //{ // var grpSid = new SecurityIdentifier(role.Sid); // if (wp.IsInRole(grpSid)) // { // user.AdGroups.Add(role.Group); // } //} } } } } catch (Exception ex) { throw; } return(user); }
public AdUser GetCurUser() { AdUser user = new AdUser(); try { //////List<GroupPrincipal> result = new List<GroupPrincipal>(); //////// establish domain context //////PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain); //////// find your user //////UserPrincipal usr = UserPrincipal.FindByIdentity(yourDomain, userName); //////// if found - grab its groups //////if (user != null) //////{ ////// PrincipalSearchResult<Principal> groups = usr.GetAuthorizationGroups(); ////// // iterate over all groups ////// foreach (Principal p in groups) ////// { ////// // make sure to add only group principals ////// if (p is GroupPrincipal) ////// { ////// result.Add((GroupPrincipal)p); ////// } ////// } //////} //////return user; string fakeSid = null; string fakeLosgin = null; //fakeSid = "S-1-5-21-1970802976-3466419101-4042325969-3837"; //fakeLosgin = "olga.skidan"; using (WindowsImpersonationContextFacade impersonationContext = new WindowsImpersonationContextFacade( nc)) { var wi = (WindowsIdentity)base.User.Identity; if (wi.User != null) { var domain = new PrincipalContext(ContextType.Domain); string sid = fakeSid??wi.User.Value; user.Sid = sid; var login = fakeLosgin??wi.Name.Remove(0, wi.Name.IndexOf("\\", StringComparison.CurrentCulture) + 1); user.Login = login; var userPrincipal = UserPrincipal.FindByIdentity(domain, login); if (userPrincipal != null) { var mail = userPrincipal.EmailAddress; var name = userPrincipal.DisplayName; user.Email = mail; user.FullName = name; //user.AdGroups = new List<AdGroup>(); //var wp = new WindowsPrincipal(wi); //foreach (var role in AdUserGroup.GetList()) //{ // var grpSid = new SecurityIdentifier(role.Sid); // if (wp.IsInRole(grpSid)) // { // user.AdGroups.Add(role.Group); // } //} } } } } catch (Exception ex) { throw; } return user; }
protected AdUser DisplayCurUser() { CurUser = GetCurUser(); if (CurUser == new AdUser()) RedirectToAction("AccessDenied", "Error"); ViewBag.CurUser = CurUser; //ViewBag.TechAccess = CurUser.HasAccess(AdGroup.ServiceTech); //ViewBag.AdminAccess = CurUser.HasAccess(AdGroup.ServiceAdmin); //ViewBag.ManagerAccess = CurUser.HasAccess(AdGroup.ServiceManager); //ViewBag.EngeneerAccess = CurUser.HasAccess(AdGroup.ServiceEngeneer); //ViewBag.UserIsTech = CurUser.Is(AdGroup.ServiceTech); //ViewBag.UserIsAdmin = CurUser.Is(AdGroup.ServiceAdmin); //ViewBag.UserIsManager = CurUser.Is(AdGroup.ServiceManager); //ViewBag.UserIsEngeneer = CurUser.Is(AdGroup.ServiceEngeneer); return CurUser; }
protected AdUser DisplayCurUser() { CurUser = GetCurUser(); if (CurUser == new AdUser()) RedirectToAction("AccessDenied", "Error"); ViewBag.CurUser = CurUser; return CurUser; }