Active Directory Groups

  • Excuse my ignorance, but I'm fairly new to SQL and Visual Studio. I'm creating a VB app that allows users to access archive data relating to a number of different companies. I only want allow them to view certain company's data. I was told about active directory and have now had some AD groups created and added various users to these groups.

    On the initial screen within the app is a 'Company Select' screen. What I want to do is enable/disable buttons depending on what AD group the user is in, what data item can I use which relates to the AD group. e.g.

    If user is a member of AD group 1 then company1button.enable = True

  • ron there's a built in extended procedure that can tell you what Ad groups an AD login belongs to.

    the problem is, you do NOT want to grant everyone access to extended stored procs.

    the syntax is simple:

    EXEC master..xp_logininfo @acctname = 'mydomain\lowell',@option = 'all' -- Show all paths a user gets his auth from

    go

    EXEC master..xp_logininfo @acctname = 'mydomain\authenticatedusers',@option = 'members' -- show group members

    since in reality, people change/get added/drop from groups very rarely, i would suggest scanning a list of users and put all their groups into a single static table;

    then use that table for your test, and update it once a week or so.

    here's a very basic example;

    CREATE TABLE [dbo].[#TMP] (

    [ACCOUNT NAME] NVARCHAR(256) NULL ,

    [TYPE] VARCHAR(8) NULL ,

    [PRIVILEGE] VARCHAR(8) NULL ,

    [MAPPED LOGIN NAME] NVARCHAR(256) NULL ,

    [PERMISSION PATH] NVARCHAR(256) NULL )

    INSERT INTO #tmp

    EXEC master..xp_logininfo @acctname = 'mydomain\lowell',@option = 'all'

    IF EXISTS(SELECT 1 FROM [dbo].[#TMP] WHERE [account name] = ORIGINAL_LOGIN() AND [permission path] = 'BUILTIN\Administrators')

    PRINT 'whoopee!'

    --all inline as a single command:

    IF EXISTS(SELECT 1 FROM (SELECT *

    FROM OPENROWSET('SQLOLEDB','Server=DEV223\SQL2005;Trusted_Connection=Yes;Database=Master',

    'Set FmtOnly OFF; EXEC master..xp_logininfo @acctname = 'mydomain\lowell'',@option = ''all'' '

    )

    ) MyAlias

    WHERE [account name] = ORIGINAL_LOGIN()

    AND [permission path] = 'BUILTIN\Administrators')

    PRINT 'whoopee!'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Many thanks for your response, I'll give it a go and let you know how I get on

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply