private HalooUserPrincipal FindUserPrincipal(string username)
        {
            var principalContext = GetPrincipalContext();
            // 2. luodaan malliobjekti, jota haetaan AD:sta
            HalooUserPrincipal model = new HalooUserPrincipal(principalContext);

            model.SamAccountName = username;

            // 3. tehdään haku
            PrincipalSearcher searcher = new PrincipalSearcher(model);
            var user = (HalooUserPrincipal)searcher.FindOne();

            searcher.Dispose();
            return(user);
        }
        public HalooUser FindUser(string username)
        {
            HalooUserPrincipal user = FindUserPrincipal(username);

            if (null == user)
            {
                return(null);
            }

            return(new HalooUser()
            {
                AccountName = user.SamAccountName,
                DisplayName = user.DisplayName,
                GivenName = user.DisplayName,
                IsEnabled = user.Enabled.GetValueOrDefault(),
                LastName = user.Surname,
                Title = user.Title
            });
        }