Example #1
0
        public async Task <Loginresult> ValidateUserUsinLdapApi(string username, string password)
        {
            Loginresult loginresult = new Loginresult();


            AuthorizationLdap _LdapApiAuthenticationService = new AuthorizationLdap();
            string            json = await _LdapApiAuthenticationService.getUserRoles(username, password);

            if (!string.IsNullOrEmpty(json))
            {
                string Roles      = json.Replace("[", "").Replace("]", ""); // now you have an array of 3 strings
                var    RolesArray = Roles.Split(',');                       // now you have the same as in the first line

                foreach (string role in RolesArray)
                {
                    ADGroups.Add(new Group {
                        Name = role.Replace("\r\n", string.Empty).Replace("\"", string.Empty).Trim()
                    });
                }
                var identity = new ClaimsIdentity(MyAuthentication.ApplicationCookie, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);


                List <string> memberships = new List <string>();
                var           claims      = new List <Claim>();

                //Anonymous
                ADGroups.Add(new Group {
                    Name = "Everyone"
                });
                ADGroups.Add(new Group {
                    Name = "Anonymous"
                });
                foreach (Group item in ADGroups)
                {
                    claims.Add(new Claim(ClaimTypes.Role, item.Name.ToString()));
                    memberships.Add(item.Name.ToString());
                }

                if (claims.Count > 0)
                {
                    identity.AddClaims(claims);
                }

                CMS.User._memberships = memberships;
                CMS.User.username     = username;
                loginresult.claimsid  = identity;

                return(loginresult);
            }
            else
            {
                return(loginresult);
            }
        }
Example #2
0
        public void UnValidateUser()
        {
            Loginresult loginresult = new Loginresult();


            AuthorizationLdap _LdapApiAuthenticationService = new AuthorizationLdap();


            var identity = new ClaimsIdentity();


            List <string> memberships = new List <string>();
            var           claims      = new List <Claim>();

            //Anonymous
            ADGroups = new List <Group>();

            ADGroups.Add(new Group {
                Name = "Everyone"
            });
            ADGroups.Add(new Group {
                Name = "Anonymous"
            });
            foreach (Group item in ADGroups)
            {
                claims.Add(new Claim(ClaimTypes.Role, item.Name.ToString()));
                memberships.Add(item.Name.ToString());
            }

            if (claims.Count > 0)
            {
                identity.AddClaims(claims);
            }

            CMS.User._memberships = null;
            CMS.User.username     = "";
        }