Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Active Directory Groups Expand / Collapse
Author
Message
Posted Monday, October 15, 2012 5:57 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 4:05 AM
Points: 20, Visits: 55
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
Post #1372671
Posted Monday, October 15, 2012 9:57 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:15 AM
Points: 14,326, Visits: 37,418
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!
Post #1372795
Posted Monday, October 15, 2012 11:54 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 4:05 AM
Points: 20, Visits: 55
Many thanks for your response, I'll give it a go and let you know how I get on
Post #1373042
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse