AccessEntity 정책

현재 Apigee Edge 문서가 표시되고 있습니다.
Apigee X 문서로 이동
정보

내용

Apigee Edge 데이터 저장소에서 지정한 항목 프로필을 검색합니다. 정책은 이름이 AccessEntity.{policy_name} 형식을 따르는 변수에 프로필을 배치합니다. AccessEntity를 사용하여 다음 항목의 프로필에 액세스할 수 있습니다.

  • API 제품
  • 회사
  • 회사 개발자
  • 고객 키
  • 개발자

AccessEntity 정책은 정책 기반 런타임 데이터베이스 조회 역할을 합니다. 이 정책에서 반환하는 프로필 정보를 사용하여 조건부 엔드포인트 라우팅, 흐름 실행, 정책 시행과 같은 동적 동작을 사용 설정할 수 있습니다.

AccessEntity 정책을 사용하여 항목 프로필 데이터를 XML로 가져와 변수에 입력합니다. 항목 유형과 원하는 유형의 항목을 지정하는 하나 이상의 식별자를 지정하여 가져올 항목을 식별합니다. 나중에 다른 정책에서 ExtractVariables 정책 또는 AssignMessage 정책과 같은 다른 정책으로 항목 프로필 데이터를 검색할 수 있습니다.

샘플

다음 샘플은 ExtractVariablesAssignMessage 정책과 함께 개발자의 이메일을 추출하여 HTTP 헤더에 추가하기 위해 사용하는 AccessEntity를 보여줍니다.

다른 정책에 사용하기 위한 개발자 이메일 가져오기

AccessEntity 정책을 설정하여 Edge에서 가져올 항목 프로필과 프로필 데이터를 저장할 위치를 지정합니다.

다음 예시에서는 정책이 개발자를 식별하기 위해 쿼리 매개변수로 전달된 API 키를 사용하여 developer 항목 프로필을 가져옵니다. 프로필은 이름이 AccessEntity.{policy_name} 형식인 변수에 배치됩니다. 따라서 이 정책에서 설정된 변수는 AccessEntity.GetDeveloperProfile이 됩니다.

<AccessEntity name="GetDeveloperProfile">
  <!-- This is the type entity whose profile we need to pull from the Edge datastore. -->
  <EntityType  value="developer"/>
  <!-- We tell the policy to use the API key (presented as query parameter) to identify the developer. -->
  <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/> 
</AccessEntity>

다른 정책을 사용하여 AccessEntity에서 설정한 변수에서 항목 프로필 값을 검색합니다.

다음 예시에서 ExtractVariables 정책은 AccessEntity가 이전에 설정한 AccessEntity.GetDeveloperProfile 변수에서 값을 검색합니다.

검색된 값은 XMLPayload 요소에서 XPath 표현식으로 지정됩니다. 추출된 값은 developer.email 변수에 배치됩니다.

<ExtractVariables name="SetDeveloperProfile">
  <!-- The source element points to the variable populated by AccessEntity policy. 
  The format is <policy-type>.<policy-name>.
  In this case, the variable contains the whole developer profile. -->
  <Source>AccessEntity.GetDeveloperProfile</Source> 
  <VariablePrefix>developer</VariablePrefix>
  <XMLPayload>
    <Variable name="email" type="string"> 
        <!-- You parse elements from the developer profile using XPath. -->
      <XPath>/Developer/Email</XPath>
    </Variable>
  </XMLPayload>
</ExtractVariables>

다음 AssignMessage 정책ExtractVariables 정책에서 설정한 개발자 이메일을 검색합니다.

<!-- We'll use this policy to return the variables set in the developer profile, 
just so that we can easily see them in the response. -->
<AssignMessage name="EchoVariables">
  <AssignTo createNew="false" type="response"></AssignTo>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <Set>
    <Headers>
      <Header name="X-Developer-email">{developer.email}</Header>
    </Headers>
  </Set>
</AssignMessage>

요소 참조

AccessEntity 정책의 기본 구조는 다음과 같습니다.

<AccessEntity name="policy_name">
  <EntityType  value="entity_type"/>
  <EntityIdentifier ref="entity_identifier" type="identifier_type"/> 
  <SecondaryIdentifier ref="secondary_identifier" type="identifier_type"/>
</AccessEntity>

Identifiers 요소에서 동일한 유형의 여러 항목을 그룹화하여 액세스할 수 있습니다.

<AccessEntity name="name_of_the_policy">
  <EntityType  value="type_of_entity"/>
  <Identifiers>
    <Identifier>
      <EntityIdentifier ref="reference_to_entity_identifier" type*="identifier_type"/> 
      <SecondaryIdentifier ref="reference_to_secondary_entity_identifier" type="identifier_type"/><!-- optional -->
    </Identifier >
    <Identifier>
      <EntityIdentifier ref="reference_to_entity_identifier" type*="identifier_type"/> 
      <SecondaryIdentifier ref="reference_to_secondary_entity_identifier" type="identifier_type"/><!-- optional -->
    </Identifier >
  </Identifiers>
</AccessEntity>

<AccessEntity> 속성

<AccessEntity async="false" continueOnError="false" enabled="true" name="policy_name">

다음 표는 모든 정책 상위 요소의 공통 속성에 대해 설명합니다.

속성 설명 기본 계정 현재 상태
name

정책의 내부 이름입니다. name 속성의 값에는 문자, 숫자, 공백, 하이픈, 밑줄, 마침표가 포함될 수 있습니다. 이 값은 255자(영문 기준)를 초과할 수 없습니다.

원하는 경우 <DisplayName> 요소를 사용하여 관리 UI 프록시 편집기의 정책에 다른 자연어 이름을 사용하여 정책에 라벨을 지정합니다.

N/A 필수
continueOnError

정책이 실패할 경우 오류가 반환되도록 하려면 false로 설정합니다. 이는 대부분의 정책에서 예상되는 동작입니다.

정책이 실패해도 흐름 실행이 계속되도록 하려면 true로 설정합니다.

false 선택사항
enabled

정책을 시행하려면 true로 설정합니다.

정책을 중지하려면 false로 설정합니다. 정책이 흐름에 연결되어 있어도 정책이 시행되지 않습니다.

true 선택사항
async

이 속성은 지원이 중단되었습니다.

false 지원 중단됨

<DisplayName> 요소

name 속성 외에도 이 요소를 사용하여 관리 UI 프록시 편집기의 정책에 다른 자연어 이름으로 라벨을 지정합니다.

<DisplayName>Policy Display Name</DisplayName>
기본 계정

N/A

이 요소를 생략하면 정책 name 속성 값이 사용됩니다.

현재 상태 선택사항
유형 문자열

<EntityIdentifier> 요소

EntityType에 제공된 유형의 가져올 특정 항목을 지정합니다.

<EntityIdentifier ref="value_variable" type="identifier_type"/> 

기본

N/A

Presence

필수

유형

문자열

특성

속성 설명 기본 계정 현재 상태 유형
ref

식별자의 소스를 제공하는 변수입니다(예: request.queryparam.apikey).

N/A 필수 항목입니다. 문자열
유형 ref 속성의 변수에 의해 입력된 유형입니다(예: consumerkey). 값 목록은 항목 유형 및 식별자를 참조하세요. 필수 항목입니다. 문자열

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetCompany">
    <DisplayName>GetCompanyProfile</DisplayName>
    <EntityType value="company"></EntityType>
    <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/>
</AccessEntity>

<EntityType> 요소

데이터 저장소에서 검색할 항목의 유형을 지정합니다.

<EntityType  value="entity_type"/>

기본

N/A

Presence

필수

유형

문자열

EntityIdentifier 요소를 사용하여 원하는 특정 유형의 항목을 지정합니다. 항목 유형에 대한 참조는 항목 유형 및 식별자를 참조하세요.

특성

속성 설명 기본 계정 현재 상태 유형
지원되는 항목 유형 중 하나입니다. 목록은 항목 유형 및 식별자를 참조하세요. 없음 필수 항목입니다. 문자열

<SecondaryIdentifier> 요소

지정된 EntityType의 원하는 인스턴스를 식별하는 값을 EntityIdentifier와 함께 지정합니다.

<SecondaryIdentifier ref="value_variable" type="identifier_type"/>

기본

N/A

Presence

선택사항

유형

문자열

EntityIdentifier만 지정할 때 SecondaryIdentifier를 사용하는 것은 단일 항목을 가져온다는 보장하지 않습니다. 자세한 내용은 보조 식별자로 결과 좁히기를 참조하세요.

여러 SecondaryIdentifier 요소 사용은 지원되지 않습니다.

속성

속성 설명 기본 계정 현재 상태 유형
ref

식별자의 소스를 제공하는 변수입니다(예: request.queryparam.apikey).

N/A 필수 항목입니다. 문자열
유형 ref 속성의 변수에 의해 입력된 유형입니다(예: consumerkey). 값 목록은 항목 유형 및 식별자를 참조하세요. 필수 항목입니다. 문자열

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetAPIProduct">
    <DisplayName>GetAPIProduct</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="developer.app.name" type="appname"/> 
    <SecondaryIdentifier ref="developer.id" type="developerid"/> 
</AccessEntity>

사용 참고사항

보조 식별자로 결과 좁히기

일부 항목의 경우 하나의 식별자를 제공하는 것은 원하는 항목을 가져올 만큼 충분히 구체적이지 않을 수 있습니다. 이러한 경우 보조 식별자를 사용하여 결과를 좁힐 수 있습니다.

처음의 범위가 넓은 정책 구성은 다음과 같을 수 있습니다.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetApp">
    <DisplayName>GetAppProfile</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/>
</AccessEntity>

앱은 여러 API 제품에 연결될 수 있으므로 앱 ID만 사용하면 원하는 API 제품이 반환되지 않을 수 있습니다. 일치하는 여러 제품 중 첫 제품만 가져올 가능성이 높습니다.

더 정확한 결과를 얻으려면 대신 SecondaryIdentifier를 사용할 수 있습니다. 예를 들어 OAuth 2.0 교환 중에 기본적으로 appnamedeveloperid 변수가 채워지므로 흐름에 이러한 변수가 있을 수 있습니다. AccessEntity 정책의 이러한 변수 값을 사용하여 요청하는 앱의 프로필 세부정보를 가져올 수 있습니다.

좀 더 구체적인 정책 구성은 다음과 같습니다.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetApp">
    <DisplayName>GetAppProfile</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="developer.app.name" type="appname"/> 
    <SecondaryIdentifier ref="developer.id" type="developerid"/> 
</AccessEntity>

지원되는 항목 유형 및 식별자

AccessEntity는 다음 항목 유형 및 식별자를 지원합니다.

EntityType 값 EntityIdentifier 유형 SecondaryIdentifier 유형
apiproduct appid apiresource
apiproductname
appname apiresource
developeremail
developerid
companyname
consumerkey apiresource
app appid
appname developeremail
developerid
companyname
consumerkey
authorizationcode authorizationcode
company appid
company
consumerkey
companydeveloper companyname
consumerkey consumerkey
consumerkey_scope consumerkey
developer appid
consumerkey
developeremail
developerid
requesttoken requesttoken consumerkey
verifier verifier

예시 항목 프로필 XML

XPath로 원하는 항목 프로필 값을 검색하려면 프로필 XML의 구조에 대해 알아야 합니다. 구조의 예로 관리 API 호출을 사용하여 원하는 항목의 XML을 가져옵니다. 자세한 내용은 관리 API 참조를 확인하세요.

다음 섹션에는 API 호출 코드와 호출의 XML 예시가 포함되어 있습니다.

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/apps/{app_id} \
-u email:password

Edge 관리 API 참조에서 앱 ID로 조직에서 앱 가져오기도 참조하세요.

또는

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name} \
-u email:password

Edge 관리 API 참조에서 개발자 앱 세부정보 가져오기도 참고하세요.

샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<App name="thomas-app">
    <AccessType>read</AccessType>
    <ApiProducts/>
    <Credentials>
        <Credential>
            <Attributes/>
            <ConsumerKey>wrqOOOiPArFI0WRoB1gAJMRbOguekJ5w</ConsumerKey>
            <ConsumerSecret>WvOhDrJ8m6kzz7Ni</ConsumerSecret>
            <ApiProducts>
                <ApiProduct>
                    <Name>FreeProduct</Name>
                    <Status>approved</Status>
                </ApiProduct>
            </ApiProducts>
            <Scopes/>
            <Status>approved</Status>
        </Credential>
    </Credentials>
    <AppFamily>default</AppFamily>
    <AppId>ab308c13-bc99-4c50-8434-0e0ed1b86075</AppId>
    <Attributes>
        <Attribute>
            <Name>DisplayName</Name>
            <Value>Tom's Weather App</Value>
        </Attribute>
    </Attributes>
    <CallbackUrl>http://tom.app/login</CallbackUrl>
    <CreatedAt>1362502872727</CreatedAt>
    <CreatedBy>admin@apigee.com</CreatedBy>
    <DeveloperId>PFK8IwOeAOW01JKA</DeveloperId>
    <LastModifiedAt>1362502872727</LastModifiedAt>
    <LastModifiedBy>admin@apigee.com</LastModifiedBy>
    <Scopes/>
    <Status>approved</Status>
</App>

API 제품

$ curl  -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/apiproducts/{apiproduct_name} \
-u email:password

Edge Management API 참조에서 API 제품 가져오기도 참고하세요.

샘플 XPath는 weather_free라는 API 제품에서 두 번째 API 리소스(URI)를 검색합니다.

/ApiProduct['@name=weather_free']/ApiResources/ApiResource[1]/text()

XML로 반환된 샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ApiProduct name="weather_free">
    <ApiResources>
        <ApiResource>/forecastrss, /reports</ApiResource>
    </ApiResources>
    <ApprovalType>auto</ApprovalType>
    <Attributes>
        <Attribute>
            <Name>description</Name>
            <Value>Introductory API Product</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.interval</Name>
            <Value>1</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.limit</Name>
            <Value>1</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.timeunit</Name>
            <Value>minute</Value>
        </Attribute>
        <Attribute>
            <Name>servicePlan</Name>
            <Value>Introductory</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1355847839224</CreatedAt>
    <CreatedBy>andrew@apigee.com</CreatedBy>
    <Description>Free API Product</Description>
    <DisplayName>Free API Product</DisplayName>
    <Environments/>
    <LastModifiedAt>1355847839224</LastModifiedAt>
    <LastModifiedBy>andrew@apigee.com</LastModifiedBy>
    <Proxies/>
    <Scopes/>
</ApiProduct>

회사

$ curl   -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name} \
-u email:password

Edge Management API 참조에서 회사 세부정보 가져오기도 참고하세요.

샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Company name="theramin">
    <Apps/>
    <DisplayName>Theramin Corporation</DisplayName>
    <Organization>apigee-pm</Organization>
    <Status>active</Status>
    <Attributes>
        <Attribute>
            <Name>billing_code</Name>
            <Value>13648765</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1349208631291</CreatedAt>
    <CreatedBy>andrew@apigee.com</CreatedBy>
    <LastModifiedAt>1349208631291</LastModifiedAt>
    <LastModifiedBy>andrew@apigee.com</LastModifiedBy>
</Company>

회사 개발자

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name}/developers/{developer_name} \
-u email:password

샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Developers>
    <Developer>
        <Email>ntesla@theramin.com</Email>
        <Role>developer</Role>
    </Developer>
</Developers>

고객 키

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name}/keys/{consumer_key} \
-u email:password

Edge 관리 API 참조에서 개발자 앱의 키 세부정보 가져오기도 참고하세요.

샘플 XPath:

/Credential/ApiProducts/ApiProduct[Name='weather_free']/Status/text()

샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Credential>
    <Attributes/>
    <ConsumerKey>XLotL3PRxNkUGXhGAFDPOr6fqtvAhuZe</ConsumerKey>
    <ConsumerSecret>iNUyEaOOh96KR3YL</ConsumerSecret>
    <ApiProducts>
        <ApiProduct>
            <Name>weather_free</Name>
            <Status>approved</Status>
        </ApiProduct>
    </ApiProducts>
    <Scopes/>
    <Status>approved</Status>
</Credential>

개발자

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email} \
-u email:password

Edge Management API 참조에서 개발자 가져오기도 참고하세요.

샘플 XPath:

/Developer/Attributes/Attribute[Name='my_custom_attribute']/Value/text()
/Developer/Email/text()

샘플 프로필:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Developer>
    <Apps>
        <App>weatherappx</App>
        <App>weatherapp</App>
    </Apps>
    <Email>ntesla@theramin.com</Email>
    <DeveloperId>4Y4xd0KRZ1wmHJqu</DeveloperId>
    <FirstName>Nikola</FirstName>
    <LastName>Tesla</LastName>
    <UserName>theramin</UserName>
    <OrganizationName>apigee-pm</OrganizationName>
    <Status>active</Status>
    <Attributes>
        <Attribute>
            <Name>project_type</Name>
            <Value>public</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1349797040634</CreatedAt>
    <CreatedBy>rsaha@apigee.com</CreatedBy>
    <LastModifiedAt>1349797040634</LastModifiedAt>
    <LastModifiedBy>rsaha@apigee.com</LastModifiedBy>
</Developer>

흐름 변수

AccessEntity 정책에 지정된 항목 프로필을 가져오면 XML 형식의 프로필 객체가 메시지 컨텍스트에 변수로 추가됩니다. 변수 이름을 참조하여 다른 변수처럼 액세스할 수 있습니다. 사용자가 제공한 AccessEntity 정책 이름은 변수 이름의 변수 프리픽스로 설정됩니다.

예를 들어 이름이 GetDeveloper인 AccessEntity 정책이 실행되면 XML 형식 프로필이 AccessEntity.GetDeveloper라는 변수에 저장됩니다. 그러면 AccessEntity.GetDeveloper를 소스로 지정하는 ExtractVariables 정책에 정의된 XPath를 사용하여 XML 형식 프로필을 파싱할 수 있습니다.

오류 참조

관련 정보는 정책 오류에 대해 알아야 할 사항오류 처리를 참조하세요.

런타임 오류

없음

배포 오류

오류 이름 오류 문자열 HTTP 상태 발생 상황
InvalidEntityType Invalid type [entity_type] in ACCESSENTITYStepDefinition [policy_name] N/A 사용된 항목 유형은 지원되는 유형 중 하나여야 합니다.

관련 주제