Skip to content

Instantly share code, notes, and snippets.

@marcioalthmann
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcioalthmann/9073219 to your computer and use it in GitHub Desktop.
Save marcioalthmann/9073219 to your computer and use it in GitHub Desktop.
Listando grupos de autenticação do usuário no domínio
var contexto = new PrincipalContext(ContextType.Domain);
// Retorna o nome do usuário, ex: DOMINIO\\Usuario
var usuario = WindowsIdentity.GetCurrent().Name;
// Retorna a lista de todos os grupos
var gruposDeAutorizacao = UserPrincipal.FindByIdentity(contexto, usuario).GetAuthorizationGroups();
// Uma forma simples de validar se o usuário faz parte de determinado grupo
var fazParteDoGrupoYYZ = gruposDeAutorizacao.Any(grupo => grupo.Name == "YYZ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment