3131 * determines if the policies allow for the given principal to perform the given action against the
3232 * given resource.
3333 *
34- * <p>An optional schema can be provided, but will not be used for validation unless you call
35- * validate(). The schema is provided to allow parsing Entities from JSON without escape sequences
36- * (in general, you don't need to worry about this if you construct your entities via the EntityUID
37- * class).
34+ * <p>If the (optional) schema is provided, this will inform parsing the
35+ * `context` from JSON: for instance, it will allow `__entity` and `__extn`
36+ * escapes to be implicit, and it will error if attributes have the wrong types
37+ * (e.g., string instead of integer).
38+ * If the schema is provided and `enable_request_validation` is true, then the
39+ * schema will also be used for request validation.
3840 */
3941public class AuthorizationRequest {
4042 /** EUID of the principal in the request. */
4143 @ JsonProperty ("principal" )
42- public final Optional <EntityUID > principalEUID ;
44+ public final Optional <EntityUID > principalEUID ;
4345 /** EUID of the action in the request. */
4446 @ JsonProperty ("action" )
4547 public final EntityUID actionEUID ;
@@ -50,9 +52,17 @@ public class AuthorizationRequest {
5052 /** Key/Value map representing the context of the request. */
5153 public final Optional <Map <String , Value >> context ;
5254
53- /** JSON object representing the Schema. */
55+ /** JSON object representing the Schema. Used for schema-based parsing of
56+ * `context`, and also (if `enable_request_validation` is `true`) for
57+ * request validation. */
5458 public final Optional <Schema > schema ;
5559
60+ /** If this is `true` and a schema is provided, perform request validation.
61+ * If this is `false`, the schema will only be used for schema-based parsing
62+ * of `context`, and not for request validation.
63+ * If a schema is not provided, this option has no effect. */
64+ public final boolean enable_request_validation ;
65+
5666 /**
5767 * Create an authorization request from the EUIDs and Context.
5868 *
@@ -61,13 +71,17 @@ public class AuthorizationRequest {
6171 * @param resourceEUID Resource's EUID.
6272 * @param context Key/Value context.
6373 * @param schema Schema (optional).
74+ * @param enable_request_validation Whether to use the schema for just
75+ * schema-based parsing of `context` (false) or also for request validation
76+ * (true). No effect if `schema` is not provided.
6477 */
6578 public AuthorizationRequest (
6679 Optional <EntityUID > principalEUID ,
6780 EntityUID actionEUID ,
6881 Optional <EntityUID > resourceEUID ,
6982 Optional <Map <String , Value >> context ,
70- Optional <Schema > schema ) {
83+ Optional <Schema > schema ,
84+ boolean enable_request_validation ) {
7185 this .principalEUID = principalEUID ;
7286 this .actionEUID = actionEUID ;
7387 this .resourceEUID = resourceEUID ;
@@ -77,10 +91,11 @@ public AuthorizationRequest(
7791 this .context = Optional .of (new HashMap <>(context .get ()));
7892 }
7993 this .schema = schema ;
94+ this .enable_request_validation = enable_request_validation ;
8095 }
8196
8297 /**
83- * Create a request in the empty context .
98+ * Create a request without a schema .
8499 *
85100 * @param principalEUID Principal's EUID.
86101 * @param actionEUID Action's EUID.
@@ -93,11 +108,12 @@ public AuthorizationRequest(EntityUID principalEUID, EntityUID actionEUID, Entit
93108 actionEUID ,
94109 Optional .of (resourceEUID ),
95110 Optional .of (context ),
96- Optional .empty ());
111+ Optional .empty (),
112+ false );
97113 }
98114
99115 /**
100- * Create a request without a schema.
116+ * Create a request without a schema, using Entity objects for principal/action/resource .
101117 *
102118 * @param principalEUID Principal's EUID.
103119 * @param actionEUID Action's EUID.
@@ -106,20 +122,32 @@ public AuthorizationRequest(EntityUID principalEUID, EntityUID actionEUID, Entit
106122 */
107123 public AuthorizationRequest (Entity principalEUID , Entity actionEUID , Entity resourceEUID , Map <String , Value > context ) {
108124 this (
109- Optional . of ( principalEUID .getEUID () ),
125+ principalEUID .getEUID (),
110126 actionEUID .getEUID (),
111- Optional .of (resourceEUID .getEUID ()),
112- Optional .of (context ),
113- Optional .empty ());
127+ resourceEUID .getEUID (),
128+ context );
114129 }
115130
116- public AuthorizationRequest (Optional <Entity > principal , Entity action , Optional <Entity > resource , Optional <Map <String , Value >> context , Optional <Schema > schema ) {
131+ /**
132+ * Create a request from Entity objects and Context.
133+ *
134+ * @param principal
135+ * @param action
136+ * @param resource
137+ * @param context
138+ * @param schema
139+ * @param enable_request_validation Whether to use the schema for just
140+ * schema-based parsing of `context` (false) or also for request validation
141+ * (true). No effect if `schema` is not provided.
142+ */
143+ public AuthorizationRequest (Optional <Entity > principal , Entity action , Optional <Entity > resource , Optional <Map <String , Value >> context , Optional <Schema > schema , boolean enable_request_validation ) {
117144 this (
118145 principal .map (e -> e .getEUID ()),
119146 action .getEUID (),
120147 resource .map (e -> e .getEUID ()),
121148 context ,
122- schema
149+ schema ,
150+ enable_request_validation
123151 );
124152 }
125153
0 commit comments