문제

방금 WCF 보안을 잡기 시작했습니다. 서비스에서 사용자의 역할을 어떻게 나열합니까?

예를 들어

// Could use declarative security here, i.e. using PrincipalPermission attribute
public string MyService()
{
    // Would like some code that does something like:
    foreach( Role role in CurrentUser.Roles )
    {
    }
}

감사

도움이 되었습니까?

해결책

Windows 그룹을 처리 할 때는이 코드를 사용할 수 있습니다.

foreach (IdentityReference idRef in WindowsIdentity.GetCurrent().Groups)
{
    Console.WriteLine(idRef.Translate(typeof(NTAccount)).Value);
}

다른 팁

.NET (IE IPRINCIPAL)의 역할 기반 보안 인프라는 사용자의 모든 역할을 가져올 수 없습니다. 사용자가 특정 역할에 있는지 확인할 수 있습니다 (iprincipal.isinrole ( "role-name")을 통해).

그러나 특정 인증/인증 설정과 관련이 없으면 솔루션이 있습니다. 예를 들어, 다른 포스터는 Windows 인증을 사용할 때 사용자의 역할을 얻는 방법을 지적했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top