# Policy Schema — Full Element Reference Source: `enforce-o-matic-impl/java/src/enforce/o/matic/metadata/` --- ## Path Enums > **Surface principle.** The MDAPI surface is the narrower `*Type` enum in `enforce-o-matic-impl/java/src/enforce/o/matic/metadata/`. The wider runtime enums (`RulePrincipalPath`, `RuleResourcePath`, `RuleContextPath` in `enforce-o-matic-api/.../enums/`) drive Cedar evaluation and DAO behavior; values absent from the `*Type` enums are **not authorable via MDAPI**. ### `` / `` — `RulePrincipalPathType` (6 values) | Value | Meaning | |-------|---------| | `IS_AUTHENTICATED_USER_PATH` | Boolean "is principal an authenticated user" | | `ASSIGNED_PERMISSIONS_PATH` | Principal's assigned permissions (pair with `valueReferenceType=CUSTOM_PERMISSION`) | | `USER_ID` | Principal user ID | | `ORGANIZATION_ID` | Principal org ID | | `USER_ROLE_ID` | Principal role ID | | `RBAC_TAGS` | Principal RBAC tags | Outside contract (not in `RulePrincipalPathType`): `IS_INTERNAL`, `CONTACT_ID`, `SCALAR_ATTRIBUTE`, `PLURAL_ATTRIBUTE`, `PLACEHOLDER`. Use a runtime RuleProvider for these. ### `` / `` — `RuleResourcePathType` (16 values) | Value | Meaning | |-------|---------| | `NAMESPACE` | Resource namespace | | `ENTITY` | Entity (object) reference | | `FIELD` | Field reference | | `ENTITYTYPE` | Entity type — pair with `IS` operator and `{"t":"Text","v":"FIELD"}` literal | | `ENTITYKIND` | Entity kind bits | | `FIELDKIND` | Field kind bits | | `DATASPACE` | Resource dataspace | | `TAG` | Custom or standard tag | | `OBJECT_TAG` | Object-level tag | | `CLASSIFICATION` | Custom or standard classification | | `IMPLICITTAG` | Implicit tag | | `RECORDFIELD` | Field of the record being evaluated (RLS) — pair with `Schema:field` | | `OBJECT_CLASSIFICATION` | Object-level classification | | `EXPRESSION` | Compound expression — pair with `` PROJECTION | | `OBJECT_DATASPACE` | Object-level dataspace | | `RECORDFIELDTYPE` | Type of a record field | ### `` / `` — `RuleContextPathType` (1 value) | Value | Cedar attribute | Use case | |-------|-----------------|----------| | `SESSION_DATASPACE` | `context.sessionDataspace` | Session-scoped dataspace check | Outside contract: `SESSION_CONSUMER_ID`, `CONTEXT_AGENT_ID`, `CONTEXT_AGENT_VERSION_ID` (IDENTIFIED_RECORD / agentic — runtime RuleProvider only). > Some steelthread fixtures use `SCALAR_ATTRIBUTE` / `PLURAL_ATTRIBUTE` in `` (`conditionScalarAttributeValidSteelThread`). They deploy in the ftest harness because the entity object is type-tolerant, but these values are outside `RulePrincipalPathType` — not sanctioned for new work. --- ## `` — `RuleDefinitionOperatorType` | Operator | Use with | |----------|----------| | `EQUALS` / `NOT_EQUALS` | Scalar equality | | `GREATER_THAN`, `LESS_THAN`, `GREATER_THAN_OR_EQUAL`, `LESS_THAN_OR_EQUALS` | Numeric / date | | `IN` | Scalar IN set | | `LIKE` | String pattern | | `CONTAINS_ANY` | Set has at least one of | | `CONTAINS_ALL` | Set has all of | | `CONTAINS_NONE` | Set has none of | | `IS` | Type / kind check (pair with `ENTITYTYPE` + `{"t":"Text","v":"FIELD"}` literal) | | `EXISTS` | RLS join exists (pair with `resourcePath=EXPRESSION` + PROJECTION) | | `HIERARCHICALLY_ABOVE` / `HIERARCHICALLY_BELOW` | Hierarchy traversal — pair with `valueReferenceType=HIERARCHY` | --- ## `` — Full Schema (`PolicyRuleDefinitionCondition.java`) | Element | Notes | |---------|-------| | `` | `WHEN` or `UNLESS` — match the wrapper | | `` | Always required | | `` | What about the resource to inspect | | `` | What about the principal to inspect | | `` | Context attribute (SESSION_DATASPACE only) | | `` | `Schema:field` — for RECORDFIELD comparisons | | `` | Used in PROJECTION join expressions | | `` | Entity/field-kind bits | | `` | Path the value comes from | | `` | Path the value comes from | | `` | Path the value comes from | | `` | Literal or named-reference values (see below) | | `` | `PolicyJsonExpression` type=PROJECTION (RLS join) | | `` | `PolicyJsonExpression` type=SOQLTARGETLISTEXPR (SOQL principal) | | `` | Sub-expression for nested conditions | | `` | Nested children — used with `whereClauseConjunction` | --- ## `` — `PolicyRuleValueSet.java` Three fields (all optional at schema level, but a non-empty value set needs at least one): ### Literal values — `` For typed literals, embed JSON (escape `"` to `"`): ```xml {"t":"Text","v":"FIELD"} {"t":"Boolean","v":true} {"t":"Number","v":42} ``` For plain string equality: ```xml Toxico ``` ### Named references — `` + `` | `valueReferenceType` | Refers to | Typical path pairing | |----------------------|-----------|----------------------| | `CUSTOM_TAG` | Custom tag by devName | `resourcePath=TAG` | | `STANDARD_TAG` | Standard tag — **fully qualified** (e.g. `DataGovernanceTags.ExternalData.Visibility.Public`) | `resourcePath=TAG` | | `CUSTOM_CLASSIFICATION` | Custom classification | `resourcePath=CLASSIFICATION` | | `STANDARD_CLASSIFICATION` | Standard classification — **fully qualified** (e.g. `DataGovernanceClassifications.DataCategorization.FieldUsage.Active`) | `resourcePath=CLASSIFICATION` | | `HIERARCHY` | Hierarchy definition | `operator=HIERARCHICALLY_BELOW/ABOVE`, `resourcePath=RECORDFIELD` | | `CUSTOM_PERMISSION` | Custom permission | `principalPath=ASSIGNED_PERMISSIONS_PATH` | | `DATASPACE` | Dataspace | `resourcePath=DATASPACE` or `contextPath=SESSION_DATASPACE` | > **Tag/classification dev names are NOT free-form.** The deploy-time validator checks `` against the org's taxonomy. To find the exact string: `sf project retrieve start --target-org --metadata "PolicyRuleDefinition:"` and copy `` verbatim. Multiple `` siblings inside one condition are OR-combined. --- ## JSON Expressions — `PolicyJsonExpression.java` (min API 66.0) `` must match the location: | Location | Required `type` | |----------|-----------------| | Top-level `` (TRANSFORM rule arg list) | `ARGLIST` | | `` `` (RLS join) | `PROJECTION` | | `` `` (SOQL principal) | `SOQLTARGETLISTEXPR` | ### ARGLIST — Transform argument list ```xml ARGLIST 1 NUMBER 4 ``` `TransformExpressionArgumentType` = `STRING` or `NUMBER`. Use when `` takes parameters (e.g. `LAST_N_CHARS_RESOURCE_TRANSFORM` needs N). ### PROJECTION — RLS join Used inside `` with `resourcePath=EXPRESSION` and `operator=EXISTS`: ```xml PROJECTION 1 testDMO__dlm test 1 EQUALS testDMO__dlm:name__c resource testDMO__dlm age__c ``` ### SOQLTARGETLISTEXPR — Principal SOQL target Scalar: ```xml SOQLTARGETLISTEXPR 1 ``` Plural (use a set operator: `CONTAINS_ANY` / `CONTAINS_NONE` / `CONTAINS_ALL`): ```xml SOQLTARGETLISTEXPR 1 true pluralAttributes__r ``` > `SCALAR_ATTRIBUTE` / `PLURAL_ATTRIBUTE` principal expressions are outside MDAPI contract. Fixture-only. --- ## `` Enum (TRANSFORM rules only) | Value | Effect | |-------|--------| | `NULL_RESOURCE_TRANSFORM` | Replace with NULL | | `EMPTY_STRING_RESOURCE_TRANSFORM` | Replace with `""` | | `LAST_N_CHARS_RESOURCE_TRANSFORM` | Keep last N chars (N via ARGLIST) | | `FIRST_N_CHARS_RESOURCE_TRANSFORM` | Keep first N chars (N via ARGLIST) | | `ALL_BUT_LAST_N_CHARS_RESOURCE_TRANSFORM` | Mask last N | | `ALL_BUT_FIRST_N_CHARS_RESOURCE_TRANSFORM` | Mask first N | | `CLOSEST_ORDER_OF_MAGNITUDE_RESOURCE_TRANSFORM` | Round to nearest power of 10 | | `TRUNCATE_DATE_RESOURCE_TRANSFORM` | Truncate date precision | | `ROUND_RESOURCE_TRANSFORM` | Round number | | `REPLACE_ALL_CHARS_RESOURCE_TRANSFORM` | Replace each char | Pure transforms (NULL, EMPTY_STRING) need no ``. Parameterized transforms (FIRST_N, LAST_N, ROUND, REPLACE_ALL_CHARS, TRUNCATE_DATE) take args via ARGLIST. --- ## File Cross-References | Concern | File | |---------|------| | Rule wrapper | `enforce-o-matic-impl/java/src/enforce/o/matic/metadata/PolicyRuleDefinition.java` | | Set wrapper | `…/PolicyRuleDefinitionSet.java` | | Conditions | `…/PolicyRuleDefinitionClauseConjunction.java`, `…/PolicyRuleDefinitionCondition.java` | | Value set | `…/PolicyRuleValueSet.java` + `…/PolicyRuleValueSetReferenceType.java` | | JSON expression | `…/PolicyJsonExpression.java` + `…/PolicyJsonExpressionType.java` | | ARGLIST | `…/TransformExpression.java` + `…/TransformExpressionArgument.java` | | PROJECTION | `…/ProjectionExpression.java` + `…/ProjectionJoin.java` + `…/PolicyJoinPredicate.java` | | SOQLTARGETLISTEXPR | `…/PrincipalExpression.java` | | Resource domain | `…/PolicyRuleResourceDomain.java` | | Enums | `Category.java`, `Effect.java`, `RuleConsumer.java`, `PrincipalAuthenticationLevel.java`, `RulePrincipalScopeType.java`, `RuleResourceScopeType.java`, `RulePrincipalPathType.java`, `RuleResourcePathType.java`, `RuleContextPathType.java`, `RuleDefinitionClauseType.java`, `RuleDefinitionOperatorType.java`, `ResourceTransform.java` | | IDENTIFIED_RECORD condition validator | `PolicyRuleDefinitionCondObject.java:332-339` | | Agentic RuleProvider canonical builder | `AgenticPolicyRuleProviderService.java:130-260` |