Ejemplo n.º 1
0
        public DirectoryLogin(DirectoryConfiguration config, string username, string password)
        {
            this.TimeoutSeconds = config.TimeoutSeconds;

            using (var context = AccountAuthorizer.CreateLdapContext(config.Domain, config.ContainerDN, config.SSL))
            {
                if (AccountAuthorizer.IsAuthenticated(context, username, password))
                {
                    this.IsAuthenticated = true;
                    using (UserPrincipal user = AccountAuthorizer.GetUserPrincipal(context, username))
                    {
                        this.GivenName = user.GivenName != null ? user.GivenName : string.Empty;
                        this.Surname   = user.Surname != null? user.Surname : string.Empty;
                        this.ID        = user.Sid.Value;
                        this.Name      = user.UserPrincipalName;

                        if (AccountAuthorizer.IsMemberOf(context, user, config.UserGroup))
                        {
                            this.IsUser = true;
                        }

                        if (AccountAuthorizer.IsMemberOf(context, user, config.AdminGroup))
                        {
                            this.IsAdmin = true;
                        }
                    }
                }
                else
                {
                    this.IsAuthenticated = false;
                }
            }
        }
Ejemplo n.º 2
0
        public LocalLogin(LocalAuthConfiguration config, string username, string password)
        {
            this.TimeoutSeconds = config.TimeoutSeconds;

            using (var context = AccountAuthorizer.CreateLocalContext())
            {
                if (AccountAuthorizer.IsAuthenticated(context, username, password))
                {
                    this.IsAuthenticated = true;
                    using (UserPrincipal user = AccountAuthorizer.GetUserPrincipal(context, username))
                    {
                        this.GivenName = user.GivenName == null ? "" : user.GivenName;
                        this.Surname   = user.Surname == null ? "" : user.Surname;
                        this.ID        = user.Sid.Value;
                        this.Name      = user.Name == null ? "Unknown" : user.Name;

                        foreach (string u in config.Users)
                        {
                            if (u.Equals(username, StringComparison.OrdinalIgnoreCase))
                            {
                                this.IsUser = true;
                            }
                        }

                        foreach (string u in config.AdminUsers)
                        {
                            if (u.Equals(username, StringComparison.OrdinalIgnoreCase))
                            {
                                this.IsAdmin = true;
                            }
                        }
                    }
                }
                else
                {
                    this.IsAuthenticated = false;
                }
            }
        }