Ejemplo n.º 1
0
 protected void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
 {
     // ensure we have a name and made it through authentication
     if (e.Identity != null && e.Identity.IsAuthenticated)
     {
         try
         {
             var username = e.Identity.Name;
             username = username.Replace("\\", "|");
             if (username.Contains("|"))
             {
                 username = username.Split('|')[1];
             }
             username = username.ToLower();
             var rolesLst = new List <string> {
                 "0"
             };
             GenericPrincipal principal = new GenericPrincipal(e.Identity, rolesLst.ToArray());
             Thread.CurrentPrincipal = HttpContext.Current.User = principal;
         }
         catch (Exception ex)
         {
             //throw ex;
             Console.WriteLine(ex.Message);
         }
     }
 }
Ejemplo n.º 2
0
 void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
 {
     // ensure we have a name and made it through authentication
     if (e.Identity != null && e.Identity.IsAuthenticated)
     {
         //create your principal, pass in the identity so you know what permissions are tied to
         Components.MoriaUser opPrincipal = new Components.MoriaUser(e.Identity);
         //assign your principal to the HttpContext.Current.User, or perhaps Thread.Current
         HttpContext.Current.User = opPrincipal;
     }
 }
Ejemplo n.º 3
0
        void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
        {
            bool hasHeaderValue = false;

            string headerValue = HttpContext.Current.Request.Headers["MyHeader1"];

            if (headerValue == "true")
            {
                hasHeaderValue = true;
            }


            if (hasHeaderValue)
            {
                if (guestIdentity != null)
                {
                    HttpContext.Current.User = new WindowsPrincipal(guestIdentity);
                }
            }
        }
Ejemplo n.º 4
0
 public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args)
 {
     //args.Identity.
 }
 public void FixtureSetUp()
 {
     context = new HttpContext(null);
     waea    = new WindowsAuthenticationEventArgs(null, context);
 }
Ejemplo n.º 6
0
 private void Authenticate(object sender, WindowsAuthenticationEventArgs e)
 {
 }
Ejemplo n.º 7
0
 protected void WindowsAuthentication_OnAuthenticate(Object send, WindowsAuthenticationEventArgs args)
 {
     TTWebForm.userName = args.Identity.Name;
 }
Ejemplo n.º 8
0
        public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args)
        {
            if (args.Identity.IsAuthenticated)
            {
                using (var adsEntry = new DirectoryEntry($"LDAP://TU", "svc.isbi", "TaskUs@2019!"))
                    using (var adsSearcher = new DirectorySearcher(adsEntry))
                    {
                        adsSearcher.Filter = "(sAMAccountName=" + args.Identity.Name.Substring(3) + ")";
                        adsSearcher.PropertiesToLoad.Add("employeeID");
                        adsSearcher.PropertiesToLoad.Add("givenName");
                        adsSearcher.PropertiesToLoad.Add("sn");
                        adsSearcher.PropertiesToLoad.Add("mail");
                        adsSearcher.PropertiesToLoad.Add("sAMAccountName");
                        adsSearcher.PropertiesToLoad.Add("title");
                        adsSearcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
                        adsSearcher.PropertiesToLoad.Add("department");
                        SearchResult adsSearchResult = adsSearcher.FindOne();

                        if (adsSearchResult.Properties.Count > 0)
                        {
                            var employee = new
                            {
                                Id         = adsSearchResult.Properties.Contains("employeeID") ? adsSearchResult.Properties["employeeID"][0].ToString() : null,
                                FirstName  = adsSearchResult.Properties.Contains("givenName") ? adsSearchResult.Properties["givenName"][0].ToString() : null,
                                LastName   = adsSearchResult.Properties.Contains("sn") ? adsSearchResult.Properties["sn"][0].ToString() : null,
                                Email      = adsSearchResult.Properties.Contains("mail") ? adsSearchResult.Properties["mail"][0].ToString() : null,
                                NT         = adsSearchResult.Properties.Contains("sAMAccountName") ? adsSearchResult.Properties["sAMAccountName"][0].ToString() : null,
                                Position   = adsSearchResult.Properties.Contains("title") ? adsSearchResult.Properties["title"][0].ToString() : null,
                                Site       = adsSearchResult.Properties.Contains("physicalDeliveryOfficeName") ? adsSearchResult.Properties["physicalDeliveryOfficeName"][0].ToString() : null,
                                Department = adsSearchResult.Properties.Contains("department") ? adsSearchResult.Properties["department"][0].ToString() : null
                            };
                            if (employee != null && employee.Department.Equals("Corporate Applications", StringComparison.CurrentCultureIgnoreCase))
                            {
                                if (employee.Position.StartsWith("VP ", StringComparison.OrdinalIgnoreCase) || employee.Position.StartsWith("Director ", StringComparison.OrdinalIgnoreCase))
                                {
                                    args.Identity.AddClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, "Admin"));
                                }
                                else
                                {
                                    args.Identity.AddClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, "Developer"));
                                    if (Request.Url.AbsolutePath.StartsWith("/Admin"))
                                    {
                                        Response.ClearContent();
                                        Response.StatusCode = 401;
                                        Response.End();
                                    }
                                }
                                args.Identity.AddClaim(new System.Security.Claims.Claim("employeeID", employee.Id));
                                args.Identity.AddClaim(new System.Security.Claims.Claim("FirstName", employee.FirstName));
                                args.Identity.AddClaim(new System.Security.Claims.Claim("LastName", employee.LastName));
                                args.Identity.AddClaim(new System.Security.Claims.Claim("Email", employee.Email));
                                args.Identity.AddClaim(new System.Security.Claims.Claim("Department", employee.Department));
                                args.Identity.AddClaim(new System.Security.Claims.Claim("Position", employee.Position));
                            }
                            else
                            {
                                Response.ClearContent();
                                Response.StatusCode = 401;
                                Response.End();
                            }
                        }
                    }
            }
            //if (!args.Identity.IsAnonymous)
            //{
            //    args.User = new Samples.AspNet.Security.MyPrincipal(args.Identity);
            //}
        }
Ejemplo n.º 9
0
 protected void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
 {
 }