<ph type="x-smartling-placeholder"></ph>
您正在查看 Apigee Edge 文档。
转到
Apigee X 文档。 信息
内容
从 Apigee Edge 数据存储区中检索您指定的实体配置文件。该政策将配置文件放置在名称遵循 AccessEntity.{policy_name}
格式的变量中。您可以使用 AccessEntity
访问以下实体的配置文件:
- 应用
- API 产品
- 公司
- 公司开发者
- 使用方密钥
- 开发者
AccessEntity
政策充当基于政策的运行时数据库查询。您可以使用此政策返回的个人资料信息,以实现动态行为,例如条件端点路由、流执行、政策执行。
您可以使用 AccessEntity
政策获取实体个人资料数据作为 XML,并将其置于变量中。您可以通过指定实体类型以及指定所需类型实体的一个或多个标识符来标识实体。然后,在其他政策中,您可以使用另一政策检索实体配置文件数据,例如 ExtractVariables 政策或 AssignMessage 政策。
示例
以下示例展示了与 ExtractVariables
和 AssignMessage
政策结合使用的 AccessEntity
,用于提取开发者的电子邮件并将其添加到 HTTP 标头中。
获取用于其他政策的开发者电子邮件
设置 AccessEntity
政策来指定要从哪个实体配置文件获取
边缘,以及配置文件数据的放置位置。
在以下示例中,该政策使用作为查询参数传递的 API 密钥标识开发者,以获取 developer
实体配置文件。配置文件会放置在名称遵循 AccessEntity.{policy_name}
格式的变量中。因此,此政策设置的变量为 AccessEntity.GetDeveloperProfile
。
<AccessEntity name="GetDeveloperPro>fil<e" !-- This is the type entity whose profile we need to pull from the Edge dat>ast<ore. -- EntityType value=&q>uot<;developer"/ !-- We tell the policy to use the API key (presented as query parameter) to identi>fy <the developer. -- EntityIdentifier ref="request.queryparam.ap>ik<ey" type>="consumerkey"/ /AccessEntity
使用其他政策从 AccessEntity
设置的变量中检索实体配置文件值。
在以下示例中,ExtractVariables
政策会从 AccessEntity
之前设置的 AccessEntity.GetDeveloperProfile
变量中检索值。
请注意,检索的值在 XMLPayload
元素中被指定为 XPath 表达式。提取值放在 developer.email
变量中。
<ExtractVariables name="SetDeveloperPro>fil<e" !-- The source element points to the variable populated by AccessEntity policy. The <format is p>o<licy-type.p>olicy-name. In this case, the variable contains the whole developer p>rof<ile. ->- SourceAccessEntity.GetDevelo<perProf>ile/<Source Vari>ablePrefi<xdeveloper/Vari>abl<ePrefix >XMLPa<yload Variable name="email>" typ<e="string" !-- You parse elements from the dev>eloper <profi>le using XPath. <-- > XP<ath/Devel>ope<r/Email/XPa>t<h /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="EchoV>ari<ables" AssignTo createNew="fal><se" >typ<e="response"/As>sign<To IgnoreUnresolvedVaria>ble<str>ue/Ig<noreUnr>esolved<Variables Set Headers > Header name=&q<uot;X-D>evelo<per-emai>l&q<uot;>{<developer.emai>l}/Header /Headers /Set /AssignMessage
元素参考
AccessEntity
政策的基本结构如下:
<AccessEntity name="policy_>nam<e" EntityType value=&quo>t;e<ntity_type"/ EntityIdentifier ref="entity_identifier>&quo<t; type="identifier_type"/ SecondaryIdentifier ref=">s<econdary_iden>tifier" type="identifier_type"/ /AccessEntity
您可以通过将同一类型的多个实体分组到 Identifiers
元素中来访问这些对象:
<AccessEntity name="name_of_the_po>lic<y" EntityType value="t>ype<_of_entity&>quot;</ Identi>fiers < Identifier EntityIdentifier ref="reference_to_entity_identifier&>quot; ty<pe*="identifier_type"/ SecondaryIdentifier ref="reference_to_seconda><ry_entity_ident>ifier<" type=>"<;identifie>r_type&<quot;/!-- optional -- /Identifier Identifier EntityIdentifier r>ef="<;reference_to_entity_identifier" type*="identifier_type"/ SecondaryI><dentifier ref=&>quot;<reference_to>_se<condary_enti>t<y_identifier&>quot; type="identifier_type"/!-- optional -- /Identifier /Identifiers /AccessEntity
<AccessEntity> 属性
<AccessEntity async="false" continueOnError="false" enabled=">;true" name="policy_name"
下表介绍了所有政策父元素通用的特性:
属性 | 说明 | 默认 | 状态 |
---|---|---|---|
name |
政策的内部名称。 (可选)使用 |
不适用 | 必填 |
continueOnError |
设置为 设置为 |
false | 可选 |
enabled |
设置为 设为 |
是 | 可选 |
async |
此特性已弃用。 |
false | 已弃用 |
<DisplayName> 元素
除了用于 name
属性之外,还可以用于在管理界面代理编辑器中给政策添加不同的自然语言名称标签。
<DisplayName>Policy Display Name</DisplayName>
默认 |
不适用 如果省略此元素,则会使用政策的 |
---|---|
状态 | 可选 |
类型 | 字符串 |
<EntityIdentifier> 元素
指定要获取的特定实体(具有 EntityType 中指定的类型)。
<EntityIdentifier ref="value_variable" type="id>entifier_type"/
默认 |
不适用 |
状态 |
必填 |
类型 |
字符串 |
特性
属性 | 说明 | 默认 | 状态 | 类型 |
---|---|---|---|---|
ref |
提供标识符的来源的变量,例如 |
无 | 必需。 | 字符串 |
类型 | ref 属性中变量填充的类型。如 consumerkey 。请参阅实体类型和标识符,查看值列表。 |
必需。 | 字符串 |
示例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=>"<;false">; enabled="t<rue" na>me=&q<uot;GetCompany" D><isplayNameG>etCom<panyProfile/DisplayName EntityType value="company"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
<EntityType> 元素
指定要从数据存储区中检索的实体类型。
<EntityType value="entity_t>ype"/
默认 |
不适用 |
状态 |
必填 |
类型 |
字符串 |
使用 EntityIdentifier
元素指定所需的给定类型的实体。如需了解实体类型,请参阅实体类型和标识符。
属性
属性 | 说明 | 默认 | 状态 | 类型 |
---|---|---|---|---|
值 | 支持的实体类型之一。请参阅实体类型和标识符,以查看列表。 | 无。 | 必需。 | 字符串 |
<SecondaryIdentifier> 元素
结合 EntityIdentifier
指定一个值,以标识给定 EntityType
的所需实例。
<SecondaryIdentifier ref="value_variable" type="id>entifier_type"/
默认 |
不适用 |
状态 |
可选 |
类型 |
字符串 |
如果只指定 EntityIdentifier
无法保证您获得单个实体,请使用 SecondaryIdentifier
。如需了解详情,请参阅使用辅助标识符缩小结果范围。
不支持使用多个 SecondaryIdentifier
元素。
属性
属性 | 说明 | 默认 | 状态 | 类型 |
---|---|---|---|---|
ref |
提供标识符的来源的变量,例如 |
无 | 必需。 | 字符串 |
类型 | ref 属性中变量填充的类型。如 consumerkey 。请参阅实体类型和标识符,查看值列表。 |
必需。 | 字符串 |
示例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=&qu>ot;fa<lse" e>nabled="<true" n>ame=&<quot;GetAPIProduct" ><DisplayName>GetAP<IProduct/DisplayName EntityType value="apiproduc>t"<;/EntityType EntityIdentifier ref="developer.app.>na<me" type>="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
使用说明
使用辅助标识符缩小结果范围
对于某些实体,使用一个标识符可能不够具体,无法获得您想要的实体。在这些情况下,您可以使用辅助标识符缩小结果范围。
您的首要政策配置可能如下所示:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduct"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
由于一个应用可与多个 API 产品关联,因此仅使用应用 ID 可能不会返回所需的 API 产品(您可以仅获取多个匹配产品中的第一个产品)。
如需获取更精确的结果,您可以改用 SecondaryIdentifier
。例如,流中可能包含 appname
和 developerid
变量,因为这些变量在 OAuth 2.0 交换期间默认填充。您可以在 AccessEntity
政策中使用这些变量的值,获取请求应用的配置文件详细信息。
更具体的政策配置可能如下所示:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduc>t"<;/EntityType EntityIdentifier ref="developer.app.>na<me" type>="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
支持的实体类型和标识符
AccessEntity
支持以下实体类型和标识符。
EntityType 值 | EntityIdentifier 类型 | 次要标识符类型 |
---|---|---|
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 结构的一些情况。有关结构示例,请使用 Management 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 Management 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
另请参阅 开发者应用详情。
配置文件示例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="ye>s&quo<t;? App na>me=&<quot;thomas>-app&<quot; Ac>cessT<yperead/Acc>essType < ApiProd>ucts/ Cre<dentials > Credent<ial > Attributes/ Con<sumerKeywrqO>OOiPArFI0WRoB<1gAJMRbOguekJ5>w/ConsumerKey < Consu>merSecretWvOh<DrJ8m6kzz7N>i/ConsumerSecret < > ApiProducts < > ApiPro<duct<>/span> N<ameFre>eProduct</Name > < Statusapp>roved/Status < > /ApiProdu<ct > /ApiP<roduct>s < S>copes/ < S>tatus<approved/Sta>tus < /C>redenti<al /Cr>edent<ials<>/span> AppFamilydefault/AppFamily A<ppIdab>308c1<3-bc99-4c5>0-8434-0e<0ed1b8607>5/AppId A<ttri>butes < At>tribute < > NameDisplayName</Name > < ValueTo>m'<;s Weather >App/V<alue > /Attribute /At<tributes > Call<backUrlht>tp://tom.app/<login/Call>backU<rl Cr>eatedAt136250287<2727/Creat>edAt < Created>Byadmin@apigee.c<om/CreatedBy> <DeveloperIdPFK>8IwOeAOW01JKA</DeveloperId > Las<tModifiedAt136>2502872727/LastM<odifiedAt L>astMo<difiedB>yadmi<n@apig>ee.com/L<astModi>f<iedB>y Scopes/ Statusapproved/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
另请参阅获取 API 产品。
XPath 示例,从名为 weather_free
的 API 产品中检索第二个 API 资源 (URI):
/ApiProduct['@name=weather_free']/ApiResources/ApiResource[1]/text()
以 XML 格式返回的个人资料示例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? >ApiPr<oduct name=&>quot;weat<her_free&qu>ot; ApiResources < ApiRe>sourc<e/forecastrss>, /re<ports/ApiRes>ourc<e /ApiRes>ource<s Appr>ovalTypea<uto/Appro>valType A<ttri>butes < At>tribute < > Namedescription/Name < > Valu<eIntroduct>ory API P<roduct/Va>lue /<Attr>ibute Attribute < > Namede<velop>e<r.quot>a.interva<l/Name > <Value1/Va>lue /<Attr>ibute Attribu<te > Nam<edeve>l<oper.q>uota.limi<t/Name > <Value1/Va>lue /<Attr>ibute Attribute < > Namede<velop>er.quo<ta.tim>eunit/Nam<e > Value<minute/Va>lue /<Attr>ibute < At>tribute < > Nameservic<ePlan/>Name < Va>lueIn<troductory/>Value< >/Attribute < /Attribu>tes < Create>dAt1355847839224/<CreatedAt > C<reatedByand>rew@apigee.com/C<reatedBy > Desc<riptionFree> API Product/Des<cription > Disp<layNameFree A>PI Pr<oduct/DisplayN>ame Envir<onments/ La>stMod<ifiedAt1355847>839224/LastModifi<edAt LastMo>difie<dByandre>w@api<gee.com>/<LastModifie>dBy 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
另请参阅 Company Details(公司详情)。
配置文件示例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes&>quot;<? Com>pany <name=">theramin" A<pps/ Dis>playN<ameTheramin >Corporati<on/DisplayNam>e < Organ>izatio<napigee>-pm/O<rganizatio>n Sta<tusactive>/Status A<ttri>butes < Att>ribute < > Namebil<ling_c>ode/Name < > Val<ue13648765/>Value< >/Attribute < /Attribu>tes < Create>dAt1349208631291/<CreatedAt > C<reatedByandrew>@apigee.com/C<reatedBy La>stMod<ifiedAt1349208>631291/LastModifi<edAt LastMo>d<ifiedBya>ndrew@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&quo>t<; standalo>ne=&q<uot;yes&q>uot;? Dev<elope>rs Developer < >Emailntes<la@t>heramin.c<om/Em>ail < Rol>e<developer/R>ole /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 Management API 参考文档中获取开发者应用的密钥详细信息。
XPath 示例:
/Credential/ApiProducts/ApiProduct[Name='weather_free']/Status/text()
配置文件示例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalo>ne=&q<uot;yes&quo>t;? C<redential > Attributes/ ConsumerKeyXL<otL3PRxNkUGX>hGAFD<POr6fqtvAhuZe/>ConsumerKey <ConsumerSecreti>NUyEa<OOh96KR3YL/>ConsumerS<ecret >ApiProducts < > ApiProduc<t > Name<weathe>r_free/N<ame > <Statusappro>ved/S<tatus > /Ap<iProduc>t < /ApiP>roducts < Sco>p<es/ Sta>tusapproved/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&quo>t<; standal>one=&<quot>;yes"<;? >Developer < A>pps < >Appweather<appx>/App < > Ap<pweat>herapp/App /App<s >Email<ntesla@ther>amin.com/Email < Developer>Id4Y4<xd0KRZ1wm>HJqu/D<eveloperId> <FirstNam>eNiko<la/FirstN>ame < LastN>ameTesla</LastName> <UserNametheramin>/UserName< Organization>Namea<pigee->pm/Org<anizati>onNam<e Stat>usactive/<Status > Attributes < > Attribut<e > Name<proje>ct_typ<e/Name> < Valuep>ublic</Value > /<Attribute> /Attribu<tes Cr>eated<At1349797>040634/CreatedAt< Creat>edByr<saha@apigee.co>m/CreatedBy < LastModified>At134<9797040634/Las>tModifiedAt <LastModifiedByr>s<aha@apigee>.com/LastModifiedBy /Developer
流变量
检索 AccessEntity 政策中指定的实体个人资料时,XML 格式的个人资料对象将作为变量添加到消息上下文中。其访问方式与任何其他变量相同,并引用变量名称。用户提供的 AccessEntity 政策名称将设置为变量名称的变量前缀。
例如,如果执行名为 GetDeveloper
的 AccessEntity 政策,则 XML 格式的个人资料存储在名为 AccessEntity.GetDeveloper
的变量中。然后,可以使用在 ExtractVariables 政策中定义的 XPath 来解析 XML 格式的个人资料,ExtractVariables 政策指定 AccessEntity.GetDeveloper
作为其来源。
错误参考信息
如需了解相关信息,请参阅有关政策错误的注意事项和处理故障。
运行时错误
无。
部署错误
错误名称 | 故障字符串 | HTTP 状态 | 发生的条件 |
---|---|---|---|
InvalidEntityType |
Invalid type [entity_type] in ACCESSENTITYStepDefinition
[policy_name] |
不适用 | 使用的实体类型必须是受支持的类型之一。 |
相关主题
ExtractVariables
:ExtractVariables 政策AssignMessage
:AssignMessage 政策