업데이트 날짜: 2015년 6월 19일
적용 대상: Azure
적용 대상
- Microsoft Azure Active Directory 액세스 제어(액세스 제어 서비스 또는 ACS라고도 함)
개요
ACS 관리 포털( 자세한 내용은 서비스 ID 참조) 또는 ACS 관리 서비스를 사용하여 ACS 서비스 ID를 구성할 수 있습니다. ACS 관리를 위한 사용자 지정 사용자 인터페이스를 구축하거나 다중 테넌트 SaaS(Software as a Service) 솔루션에 대한 새 테넌트 온보딩을 자동화하려는 경우 ACS 관리 서비스를 사용하는 것이 더 효율적일 수 있습니다.
ACS 관리 서비스를 사용하여 서비스 ID를 구성하는 단계
중요합니다
다음 단계를 수행하기 전에 시스템이 ACS 필수 구성 요소에 요약된 모든 .NET Framework 및 플랫폼 요구 사항을 충족하는지 확인합니다.
ACS 관리 서비스를 사용하여 서비스 ID를 구성하려면 다음 단계를 수행합니다.
1단계 - ACS 구성 정보 수집
2단계 - 샘플 콘솔 응용 프로그램 만들기
3단계 - 필요한 서비스 및 어셈블리에 대한 참조 추가
4단계 - 관리 서비스 클라이언트 구현
5단계 - 서비스 ID 추가
1단계 - ACS 구성 정보 수집
ACS 관리 포털을 사용하여 필요한 구성 정보를 수집할 수 있습니다. ACS 관리 포털을 시작하는 방법에 대한 자세한 내용은 ACS 관리 포털을 참조하십시오.
ACS 구성 정보를 수집하려면
ACS 관리 포털을 시작합니다. ACS 관리 포털을 시작하는 방법에 대한 자세한 내용은 ACS 관리 포털을 참조하십시오.
ACS 관리 서비스 계정의 값을 가져옵니다. 기본 ManagementClient 계정을 사용할 수 있습니다. 이 값을 보려면 ACS 관리 포털에서 페이지 왼쪽에 있는 트리의 관리 섹션 아래에 있는 관리 서비스를 클릭합니다.
ACS 관리 서비스 계정 암호의 값을 가져옵니다. 이 값을 보려면 다음을 수행합니다.
ACS 관리 포털에서 페이지 왼쪽에 있는 트리의 관리 섹션 아래에 있는 관리 서비스를 클릭합니다.
관리 서비스 페이지의 관리 서비스 계정 아래에서 ManagementClient를 클릭합니다.
Edit Management Service Account(관리 서비스 계정 편집) 페이지의 Credentials(자격 증명)에서 Password(암호)를 클릭합니다.
Edit Management Credential(관리 자격 증명 편집) 페이지에서 Password(비밀번호) 필드의 값을 복사합니다.
Azure 네임스페이스의 값을 가져옵니다. Azure Portal 또는 ACS 관리 포털의 URL에서 이 값을 가져올 수 있습니다. 예를 들어 에서
http://contoso.accesscontrol.windows.net
Azure 네임스페이스의 값은 contoso입니다.ACS 호스트 이름의 값을 가져옵니다. 일반적으로 accesscontrol.windows.net 입니다.
2단계 - 샘플 콘솔 응용 프로그램 만들기
이 단계에서는 ACS 서비스 ID를 추가하기 위한 코드를 실행할 수 있는 샘플 콘솔 응용 프로그램을 만듭니다.
샘플 콘솔 응용 프로그램을 만들려면
Visual Studio 2012를 열고 새 콘솔 응용 프로그램 프로젝트를 만듭니다.
Program 클래스에 다음 코드를 추가한 다음 serviceIdentityPasswordForManagement, serviceNamespace 및 acsHostName 변수를 위 단계에서 수집한 적절한 구성 정보에 할당합니다.
public const string serviceIdentityUsernameForManagement = "ManagementClient"; public const string serviceIdentityPasswordForManagement = "My Password/Key for ManagementClient"; public const string serviceNamespace = "MyNameSpaceNoDots"; public const string acsHostName = "accesscontrol.windows.net"; public const string acsManagementServicesRelativeUrl = "v2/mgmt/service/"; static string cachedSwtToken;
3단계 - 필요한 서비스 및 어셈블리에 대한 참조 추가
이 단계에서는 필요한 종속성을 식별하고 서비스 및 어셈블리에 추가합니다.
서비스 및 어셈블리에 필요한 종속성을 추가하려면
참조를 마우스 오른쪽 단추로 클릭하고 참조 추가를 클릭한 다음 System.Web.Extensions에 대한 참조를 추가합니다.
비고
솔루션 탐색기에서 샘플 콘솔 응용 프로그램 이름을 마우스 오른쪽 단추로 클릭하고, 속성을 선택하고, 샘플 응용 프로그램의 대상 프레임워크를 .NET Framework 4 클라이언트 프로필(새 콘솔 응용 프로그램을 만들 때 기본적으로 할당됨)에서 .NET Framework 4로 변경해야 할 수 있습니다.
Service References(서비스 참조)를 마우스 오른쪽 단추로 클릭하고 Add Service Reference(서비스 참조 추가)를 클릭한 다음 관리 서비스에 대한 서비스 참조를 추가합니다. 관리 서비스 URL은 네임스페이스에 고유하며 다음과 유사합니다.
https:// 네임스페이스.accesscontrol.windows.net/v2/mgmt/service
MyConsoleApplication은 콘솔 응용 프로그램의 이름이고 MyServiceReference는 서비스 참조의 이름입니다.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Net; using System.Data.Services.Client; using System.Collections.Specialized; using System.Web.Script.Serialization; using System.Globalization; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using MyConsoleApplication.MyServiceReference;
4단계 - 관리 서비스 클라이언트 구현
이 단계에서는 관리 서비스 클라이언트를 구현합니다.
관리 서비스 클라이언트를 구현하려면
Program 클래스에 다음 메서드를 추가합니다.
public static ManagementService CreateManagementServiceClient() { string managementServiceEndpoint = String.Format(CultureInfo.InvariantCulture, "https://{0}.{1}/{2}", serviceNamespace, acsHostName, acsManagementServicesRelativeUrl); ManagementService managementService = new ManagementService(new Uri(managementServiceEndpoint)); managementService.SendingRequest += GetTokenWithWritePermission; return managementService; }
Program 클래스에 다음 코드를 추가하여 GetTokenWithWritePermission 메서드와 해당 도우미 메서드를 만듭니다. GetTokenWithWritePermission 및 해당 도우미는 HTTP 요청의 권한 부여 헤더에 SWT OAuth 토큰을 추가합니다.
public static void GetTokenWithWritePermission(object sender, SendingRequestEventArgs args) { GetTokenWithWritePermission((HttpWebRequest)args.Request); } public static void GetTokenWithWritePermission(HttpWebRequest args) { if (cachedSwtToken == null) { cachedSwtToken = GetTokenFromACS(); } args.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + cachedSwtToken); } private static string GetTokenFromACS() { // // Request a token from ACS // WebClient client = new WebClient(); client.BaseAddress = string.Format(CultureInfo.CurrentCulture, "https://{0}.{1}", serviceNamespace, acsHostName); NameValueCollection values = new NameValueCollection(); values.Add("grant_type", "client_credentials"); values.Add("client_id", serviceIdentityUsernameForManagement); values.Add("client_secret", serviceIdentityPasswordForManagement); values.Add("scope", client.BaseAddress + acsManagementServicesRelativeUrl); byte[] responseBytes = client.UploadValues("/v2/OAuth2-13", "POST", values); string response = Encoding.UTF8.GetString(responseBytes); // Parse the JSON response and return the access token JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary<string, object> decodedDictionary = serializer.DeserializeObject(response) as Dictionary<string, object>; return decodedDictionary["access_token"] as string; }
5단계 - 서비스 ID 추가
이 단계에서는 위 단계에서 만든 관리 서비스 클라이언트를 사용하여 서비스 ID를 추가합니다. ACS 서비스 ID는 암호, 대칭 키 또는 X.509 인증서를 자격 증명 유형으로 사용할 수 있습니다.
서비스 ID를 추가하려면
Program 클래스의 Main 메서드에 다음 코드를 추가하여 관리 서비스 클라이언트를 초기화합니다.
ManagementService svc = CreateManagementServiceClient();
다음 중 하나를 수행합니다.
암호와 연결된 서비스 ID를 추가하고 변경 내용을 저장하려면 Program 클래스의 Main 메서드에 다음 코드를 추가합니다.
비고
아래 코드와 같이 이 서비스 ID를 "SampleServiceIdentity"라고 하고 암호를 "SampleServiceIdentityPassword"로 설정할 수 있습니다.
string name = "SampleServiceIdentity"; string password = "SampleServiceIdentityPassword"; ServiceIdentity sid = new ServiceIdentity() { Name = name }; DateTime startDate, endDate; startDate = DateTime.UtcNow; endDate = DateTime.MaxValue; ServiceIdentityKey key = new ServiceIdentityKey() { EndDate = endDate.ToUniversalTime(), StartDate = startDate.ToUniversalTime(), Type = "Password", Usage = "Password", Value = Encoding.UTF8.GetBytes(password), DisplayName = String.Format(CultureInfo.InvariantCulture, "{0} key for {1}", "Password", name) }; svc.AddToServiceIdentities(sid); svc.AddRelatedObject( sid, "ServiceIdentityKeys", key); svc.SaveChanges(SaveChangesOptions.Batch);
대칭 키와 연결된 서비스 ID를 추가하고 변경 내용을 저장하려면 Program 클래스의 Main 메서드에 다음 코드를 추가합니다.
비고
아래 코드와 같이 이 서비스 ID를 "SampleServiceIdentity"라고 부르고 대칭 키 값을 "SampleServiceIdentityPassword"로 설정할 수 있습니다.
string name = "SampleServiceIdentity"; string symKey = "SampleServiceIdentitySymmetricKey"; ServiceIdentity sid = new ServiceIdentity() { Name = name }; DateTime startDate, endDate; startDate = DateTime.UtcNow; endDate = DateTime.MaxValue; ServiceIdentityKey key = new ServiceIdentityKey() { EndDate = endDate.ToUniversalTime(), StartDate = startDate.ToUniversalTime(), Type = "Symmetric", Usage = "Signing", Value = Convert.FromBase64String(symKey), DisplayName = String.Format(CultureInfo.InvariantCulture, "{0} key for {1}", "Sym Key", name) }; svc.AddToServiceIdentities(sid); svc.AddRelatedObject( sid, "ServiceIdentityKeys", key); svc.SaveChanges(SaveChangesOptions.Batch);
X.509 인증서와 연결된 서비스 ID를 추가하고 변경 내용을 저장하려면 Program 클래스의 Main 메서드에 다음 코드를 추가합니다.
비고
아래 코드와 같이 이 서비스 ID를 "SampleServiceIdentity"라고 호출할 수 있습니다
아래 코드에서 "Full path to your . CER 파일"을 X.509 인증서의 정규화된 경로로 바꿉니다. 예를 들어 ACS2ClientCertificate.cer라는 인증서가 C:\에 저장된 경우 올바른 값은 "C:\ ACS2ClientCertificate.cer"입니다.string name = "SampleServiceIdentity"; X509Certificate2 cert = new X509Certificate2(@"Full path to your .CER file"); ServiceIdentity sid = new ServiceIdentity() { Name = name }; DateTime startDate, endDate; startDate = cert.NotBefore.ToUniversalTime(); endDate = cert.NotAfter.ToUniversalTime(); ServiceIdentityKey key = new ServiceIdentityKey() { EndDate = endDate.ToUniversalTime(), StartDate = startDate.ToUniversalTime(), Type = "X509Certificate", Usage = "Signing", Value = cert.GetRawCertData(), DisplayName = String.Format(CultureInfo.InvariantCulture, "{0} key for {1}", "Cert", name) }; svc.AddToServiceIdentities(sid); svc.AddRelatedObject( sid, "ServiceIdentityKeys", key); svc.SaveChanges(SaveChangesOptions.Batch);