2014-11-04 5 views
0

각 임차인이 자신의 사용자를 보유하고있는 다중 사용자 .NET 응용 프로그램이 있다고 가정 해 보겠습니다. 요청이 웹 서버에 도착하면 먼저 임차인을 결정해야합니다. 나중에 HTTP 헤더를 통해 전달 된 정보를 기반으로 사용자를 인증하려고 시도합니다. 이 시점에서 실제로 두 개의 ID가 있습니다. 하나는 입주자 용이고 다른 하나는 사용자 용입니다.임차인 및 사용자 ID에 대한 여러 ClaimsIdentity 인스턴스

class Program 
{ 
    static void Main(string[] args) 
    { 
     // NOTE: The below is a sample of how we may construct a ClaimsPrincipal instance over two ClaimsIdentity instances: 
     //  one for the tenant identity and the the other for the user idenetity. When a request come to the web server, we can determine the 
     //  tenant's identity at the very early stages of the request lifecycle. Then, we can try to authenticate the user based on the 
     //  information passed through the request headers (this could be bearer token, basic auth, etc.). 

     const string authServerName = "urn:myauthserver"; 
     const string tenantAuthType = "Application"; 
     const string userAuthType = "External"; 

     const string tenantId = "f35fe69d-7aef-4f1a-b645-0de4176cd441"; 
     const string tenantName = "bigcompany"; 
     IEnumerable<Claim> tenantClaims = new Claim[] 
     { 
      new Claim(ClaimTypes.NameIdentifier, tenantId, ClaimValueTypes.String, authServerName), 
      new Claim(ClaimTypes.Name, tenantName, ClaimValueTypes.String, authServerName) 
     }; 

     const string userId = "d4903f71-ca06-4671-a3df-14f7e02a0008"; 
     const string userName = "tugberk"; 
     const string twitterToken = "30807826f0d74ed29d69368ea5faee2638b0e931566b4e4092c1aca9b4db04fe"; 
     const string facebookToken = "35037356a183470691504cd163ce2f835419978ed81c4b7781ae3bbefdea176a"; 
     IEnumerable<Claim> userClaims = new Claim[] 
     { 
      new Claim(ClaimTypes.NameIdentifier, userId, ClaimValueTypes.String, authServerName), 
      new Claim(ClaimTypes.Name, userName, ClaimValueTypes.String, authServerName), 
      new Claim("token", twitterToken, ClaimValueTypes.String, authServerName, "Twitter"), 
      new Claim("token", facebookToken, ClaimValueTypes.String, authServerName, "Facebook") 
     }; 

     ClaimsIdentity tenantIdentity = new ClaimsIdentity(tenantClaims, tenantAuthType, ClaimTypes.Name, ClaimTypes.Role); 
     ClaimsIdentity userIdentity = new ClaimsIdentity(userClaims, userAuthType, ClaimTypes.Name, ClaimTypes.Role); 

     ClaimsPrincipal principal = new ClaimsPrincipal(new[] { tenantIdentity, userIdentity }); 
    } 
} 

는 내가 여기서 뭐하는 거지하는 두 ClaimsIdentity 인스턴스를 기반으로 ClaimsPrincipal 인스턴스를 생성하는 것입니다 : 아래의 코드는 내가하고 싶은 일의 의도를 설명합니다. 멀티 테넌트 응용 프로그램의 경우 .NET 서버 응용 프로그램에서 테넌트 및 사용자 ID를 처리하는 올바른 방법입니까?

답변

0

나는 세입자를 식별 할 수있는 추가 소유권이있는 단일 신원 정보를 사용합니다. 이것은 우리가 항상 그렇게하는 방법입니다.

이 방법을 사용하면 사용자가 다른 임차인으로 전환하고 재 인증 (새 소유권 주장 설정) 또는 액세스 차단을 시도 할 수 있는지 확인할 수 있습니다.

+0

Thx. '이런 식으로 사용자가 다른 임차인으로 전환하려고 시도하는지 여부를 확인할 수 있습니다. ' 각 테넌트는 별도의 데이터 스토리지 시스템 내에 고유 한 사용자 ID 관리 기능을 갖추고 있습니다. – tugberk