Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
ce0a6f7
Basic progress
ayush3797 Nov 28, 2023
7c47ef5
adding createMultiple mutations
ayush3797 Nov 28, 2023
6677337
nits
ayush3797 Nov 28, 2023
5f3d45a
Collecting metadata about linking entities/adding flag to represent w…
ayush3797 Nov 30, 2023
03113c7
Generating object defs for directional linking entities
ayush3797 Dec 1, 2023
5256c01
clearing up logic
ayush3797 Dec 1, 2023
8793876
Adding prefix to linking fields
ayush3797 Dec 1, 2023
bc27394
Generating array input for *:N relationship
ayush3797 Dec 3, 2023
b047c9d
making nested entity optional
ayush3797 Dec 6, 2023
c5e6b06
updating mutation name
ayush3797 Dec 15, 2023
715125c
Handling conflicting column/relationship names with linking table
ayush3797 Dec 20, 2023
e6efb65
Adding method to get plural name
ayush3797 Dec 20, 2023
bf7a6a7
AuthZ initial progress
ayush3797 Dec 20, 2023
6af96e3
Updating logic/renaming variables
ayush3797 Jan 2, 2024
e70db4c
merging with base
ayush3797 Jan 2, 2024
7a90f0b
shortening loop
ayush3797 Jan 3, 2024
dccc43a
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Jan 3, 2024
a0c7cb5
updating logic
ayush3797 Jan 4, 2024
4b91cc2
Solving bug for M:N relationship schema gen
ayush3797 Jan 13, 2024
191e257
nits
ayush3797 Jan 13, 2024
f50e491
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Jan 13, 2024
61acb0e
Adding summaries
ayush3797 Jan 13, 2024
5f002ec
update branch
ayush3797 Jan 13, 2024
c530949
update branch
ayush3797 Jan 13, 2024
f4adfff
Merge branch 'dev/agarwalayush/AuthZForNestedInsertions' of https://g…
ayush3797 Jan 13, 2024
797db23
Moving role extraction logic to authz resolver
ayush3797 Jan 14, 2024
02fdfdc
Adding comments/examples
ayush3797 Jan 14, 2024
f225e10
updating comments
ayush3797 Jan 14, 2024
5dca094
using tryadd
ayush3797 Jan 14, 2024
887dd79
format fix
ayush3797 Jan 14, 2024
82b0c7f
Fixing failures due to tests
ayush3797 Jan 15, 2024
33fca99
fixing format
ayush3797 Jan 15, 2024
2073c48
Moving linking entity logic to sqlmetadataprovider
ayush3797 Jan 15, 2024
2c96a8b
fixing typo
ayush3797 Jan 15, 2024
fe05132
Moving linking entity logic to sqlmdpvdr
ayush3797 Jan 16, 2024
11bb3d4
fixing format
ayush3797 Jan 16, 2024
d6f6949
fixing failures
ayush3797 Jan 16, 2024
1c0ce60
Preventing serialisation/deserialization of islinkingentity property
ayush3797 Jan 17, 2024
cba8072
Fixing dwsql
ayush3797 Jan 17, 2024
162f2de
god please fix this formatting error
ayush3797 Jan 17, 2024
e9d8b8e
fixing tests
ayush3797 Jan 17, 2024
c58f3ea
Refining logic to create linking objects
ayush3797 Jan 17, 2024
613f386
refining code
ayush3797 Jan 17, 2024
6757208
refactor schema converter for clear code
ayush3797 Jan 17, 2024
9e4b732
adding/removing comments
ayush3797 Jan 17, 2024
c53f4ce
nits
ayush3797 Jan 24, 2024
ff3e952
Merge with main
ayush3797 Jan 29, 2024
450da35
update branch
ayush3797 Jan 29, 2024
7a503d6
Addressing review
ayush3797 Feb 1, 2024
27a45c1
addressing review
ayush3797 Feb 1, 2024
baa0bb8
adding param name
ayush3797 Feb 2, 2024
f5237fe
Logic to find names of src/target entities from linking entity name
ayush3797 Feb 2, 2024
e963d40
update comment
ayush3797 Feb 2, 2024
80a7e79
addressing comments
ayush3797 Feb 4, 2024
af60e25
updating branch
ayush3797 Feb 6, 2024
2007b3e
updating branch
ayush3797 Feb 6, 2024
09055ab
fixing bug
ayush3797 Feb 6, 2024
9262b36
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 6, 2024
3b824d6
adding summary/reusing existing methods
ayush3797 Feb 12, 2024
29c2a1a
Initial progress
ayush3797 Feb 14, 2024
422630d
initial prgress
ayush3797 Feb 14, 2024
47def99
saving progress for fk directive
ayush3797 Feb 14, 2024
783464c
Logic to add FK directive for custom relationships
ayush3797 Feb 15, 2024
9cb61d6
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
d68d311
separating naming logic for mutations
ayush3797 Feb 15, 2024
68b780c
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
be7831f
making rel fields nullable
ayush3797 Feb 15, 2024
daeae37
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
a5f3654
adding tests
ayush3797 Feb 15, 2024
b63aed6
nit
ayush3797 Feb 15, 2024
8583106
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
5089f90
Adding test summaries
ayush3797 Feb 15, 2024
97e6878
refactoring test
ayush3797 Feb 15, 2024
d345a5f
updating comment
ayush3797 Feb 15, 2024
2e03f43
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
9625095
rearranging code
ayush3797 Feb 15, 2024
f4743de
updating branch
ayush3797 Feb 15, 2024
4c7cb74
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
fbd9001
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 15, 2024
ce0c49f
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Feb 15, 2024
baa0956
starting tests
ayush3797 Feb 15, 2024
ce8cc98
Adding test
ayush3797 Feb 15, 2024
6453ed5
addressing review
ayush3797 Feb 19, 2024
c44dda9
addressing review
ayush3797 Feb 19, 2024
7820551
Merge branch 'dev/agarwalayush/schemaGenerationTests' into dev/agarwa…
ayush3797 Feb 20, 2024
6b2f055
reverting conn string change
ayush3797 Feb 20, 2024
a9bb393
addressing review
ayush3797 Feb 22, 2024
be28782
addressing review
ayush3797 Feb 22, 2024
60ae0af
adding comment
ayush3797 Feb 22, 2024
55912f4
adding comment
ayush3797 Feb 22, 2024
ad0d0f7
resolving conflicts
ayush3797 Feb 22, 2024
effc380
addressing comments
ayush3797 Feb 27, 2024
adfcab9
updating mton function logic
ayush3797 Feb 27, 2024
9e377c3
refining logic
ayush3797 Feb 27, 2024
8db211c
addressing review
ayush3797 Feb 28, 2024
5ca4171
addressing review
ayush3797 Feb 28, 2024
a6ae8aa
Adding test asserting absence of ref field directive on non-ref columns
ayush3797 Feb 28, 2024
02c79bc
renaming set
ayush3797 Feb 29, 2024
7624675
formatting fix
ayush3797 Feb 29, 2024
559025f
formatting fix
ayush3797 Feb 29, 2024
78c8f7b
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Feb 29, 2024
96c4a36
formatting fix
ayush3797 Feb 29, 2024
0c4fc3d
Refactoring cosmos create input generation into a different methof
ayush3797 Feb 29, 2024
fa9bcab
fixing test setup
ayush3797 Feb 29, 2024
e0a2b92
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Feb 29, 2024
207d114
Addressing review
ayush3797 Feb 29, 2024
957058a
nit
ayush3797 Feb 29, 2024
f008c24
addressing review/adding comments
ayush3797 Mar 5, 2024
fac35d3
adding example
ayush3797 Mar 5, 2024
5763a11
Addressing review
ayush3797 Mar 5, 2024
d94c265
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Mar 5, 2024
7d95cab
fixing bug
ayush3797 Mar 5, 2024
b34c9f1
Addressing review
ayush3797 Mar 13, 2024
cb7d185
removing stale logic code
ayush3797 Mar 13, 2024
6eea6b0
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Mar 13, 2024
de9d6ea
Adding tests
ayush3797 Mar 19, 2024
e622a7e
Adding tests
ayush3797 Mar 19, 2024
f9c30f6
Updating config
ayush3797 Mar 19, 2024
ad40fb2
format
seantleonard Mar 20, 2024
09b8d98
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Mar 21, 2024
75534f1
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Mar 21, 2024
0ca28f1
updating branch
ayush3797 Mar 21, 2024
104248b
fixing failures
ayush3797 Mar 21, 2024
eb3238b
cleaning up test
ayush3797 Mar 21, 2024
658b22f
Fixing dwsql failure
ayush3797 Mar 21, 2024
b8872a7
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Mar 21, 2024
0ad5561
formatting fix
ayush3797 Mar 21, 2024
e34cf14
Merge branch 'dev/NestedMutations' into dev/agarwalayush/schemaGenera…
ayush3797 Mar 21, 2024
be3c31b
Merge branch 'dev/agarwalayush/schemaGeneration' into dev/agarwalayus…
ayush3797 Mar 21, 2024
147043b
Moving failing negative unit tests to integration testss
ayush3797 Mar 21, 2024
9a8e805
Added more tests
ayush3797 Mar 21, 2024
0e9eb1e
updating config gen
ayush3797 Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config-generators/mssql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add stocks_price --config "dab-config.MsSql.json" --source stocks_price --permis
update stocks_price --config "dab-config.MsSql.json" --permissions "anonymous:read"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_ColumnForbidden:read" --fields.exclude "price"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_EntityReadForbidden:create"
update stocks_price --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:create,read,update,delete"
add Tree --config "dab-config.MsSql.json" --source trees --permissions "anonymous:create,read,update,delete"
add Shrub --config "dab-config.MsSql.json" --source trees --permissions "anonymous:create,read,update,delete" --rest plants
add Fungus --config "dab-config.MsSql.json" --source fungi --permissions "anonymous:create,read,update,delete" --graphql "fungus:fungi"
Expand Down Expand Up @@ -65,6 +66,8 @@ update Publisher --config "dab-config.MsSql.json" --permissions "database_policy
update Publisher --config "dab-config.MsSql.json" --permissions "database_policy_tester:update" --policy-database "@item.id ne 1234"
update Publisher --config "dab-config.MsSql.json" --permissions "database_policy_tester:create" --policy-database "@item.name ne 'New publisher'"
update Stock --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:read,update,delete"
update Stock --config "dab-config.MsSql.json" --permissions "test_role_with_excluded_fields_on_create:create" --fields.exclude "piecesAvailable"
update Stock --config "dab-config.MsSql.json" --rest commodities --graphql true --relationship stocks_price --target.entity stocks_price --cardinality one
update Book --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete"
update Book --config "dab-config.MsSql.json" --relationship publishers --target.entity Publisher --cardinality one
Expand Down Expand Up @@ -112,6 +115,7 @@ update WebsiteUser --config "dab-config.MsSql.json" --permissions "authenticated
update Revenue --config "dab-config.MsSql.json" --permissions "database_policy_tester:create" --policy-database "@item.revenue gt 1000"
update Comic --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.MsSql.json" --relationship comics --target.entity Comic --cardinality many
update stocks_price --config "dab-config.MsSql.json" --relationship Stock --target.entity Stock --cardinality one
update Broker --config "dab-config.MsSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
update Tree --config "dab-config.MsSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Shrub --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
Expand Down
26 changes: 26 additions & 0 deletions src/Core/Authorization/AuthorizationResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Azure.DataApiBuilder.Core.Services;
using Azure.DataApiBuilder.Core.Services.MetadataProviders;
using Azure.DataApiBuilder.Service.Exceptions;
using HotChocolate.Resolvers;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;

Expand Down Expand Up @@ -213,6 +214,31 @@ public string GetDBPolicyForRequest(string entityName, string roleName, EntityAc
return dbPolicy is not null ? dbPolicy : string.Empty;
}

/// <summary>
/// Helper method to get the role with which the GraphQL API request was executed.
/// </summary>
/// <param name="context">HotChocolate context for the GraphQL request.</param>
/// <returns>Role of the current GraphQL API request.</returns>
/// <exception cref="DataApiBuilderException">Throws exception when no client role could be inferred from the context.</exception>
public static string GetRoleOfGraphQLRequest(IMiddlewareContext context)
{
string role = string.Empty;
if (context.ContextData.TryGetValue(key: CLIENT_ROLE_HEADER, out object? value) && value is StringValues stringVals)
{
role = stringVals.ToString();
}

if (string.IsNullOrEmpty(role))
{
throw new DataApiBuilderException(
message: "No ClientRoleHeader available to perform authorization.",
statusCode: HttpStatusCode.Forbidden,
subStatusCode: DataApiBuilderException.SubStatusCodes.AuthorizationCheckFailed);
}

return role;
}

#region Helpers
/// <summary>
/// Method to read in data from the config class into a Dictionary for quick lookup
Expand Down
37 changes: 6 additions & 31 deletions src/Core/Resolvers/CosmosMutationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using HotChocolate.Resolvers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json.Linq;

namespace Azure.DataApiBuilder.Core.Resolvers
Expand Down Expand Up @@ -64,7 +63,7 @@ private async Task<JObject> ExecuteAsync(IMiddlewareContext context, IDictionary
// If authorization fails, an exception will be thrown and request execution halts.
string graphQLType = context.Selection.Field.Type.NamedType().Name.Value;
string entityName = metadataProvider.GetEntityName(graphQLType);
AuthorizeMutationFields(context, queryArgs, entityName, resolver.OperationType);
AuthorizeMutation(context, queryArgs, entityName, resolver.OperationType);

ItemResponse<JObject>? response = resolver.OperationType switch
{
Expand All @@ -74,7 +73,7 @@ private async Task<JObject> ExecuteAsync(IMiddlewareContext context, IDictionary
_ => throw new NotSupportedException($"unsupported operation type: {resolver.OperationType}")
};

string roleName = GetRoleOfGraphQLRequest(context);
string roleName = AuthorizationResolver.GetRoleOfGraphQLRequest(context);

// The presence of READ permission is checked in the current role (with which the request is executed) as well as Anonymous role. This is because, for GraphQL requests,
// READ permission is inherited by other roles from Anonymous role when present.
Expand All @@ -93,14 +92,13 @@ private async Task<JObject> ExecuteAsync(IMiddlewareContext context, IDictionary
}

/// <inheritdoc/>
public void AuthorizeMutationFields(
public void AuthorizeMutation(
IMiddlewareContext context,
IDictionary<string, object?> parameters,
string entityName,
EntityActionOperation mutationOperation)
{
string role = GetRoleOfGraphQLRequest(context);

string clientRole = AuthorizationResolver.GetRoleOfGraphQLRequest(context);
List<string> inputArgumentKeys;
if (mutationOperation != EntityActionOperation.Delete)
{
Expand All @@ -114,9 +112,9 @@ public void AuthorizeMutationFields(
bool isAuthorized = mutationOperation switch
{
EntityActionOperation.UpdateGraphQL =>
_authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: EntityActionOperation.Update, inputArgumentKeys),
_authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: clientRole, operation: EntityActionOperation.Update, inputArgumentKeys),
EntityActionOperation.Create =>
_authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: mutationOperation, inputArgumentKeys),
_authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: clientRole, operation: mutationOperation, inputArgumentKeys),
EntityActionOperation.Delete => true,// Field level authorization is not supported for delete mutations. A requestor must be authorized
// to perform the delete operation on the entity to reach this point.
_ => throw new DataApiBuilderException(
Expand Down Expand Up @@ -261,29 +259,6 @@ private static async Task<ItemResponse<JObject>> HandleUpdateAsync(IDictionary<s
return item;
}

/// <summary>
/// Helper method to get the role with which the GraphQL API request was executed.
/// </summary>
/// <param name="context">HotChocolate context for the GraphQL request</param>
private static string GetRoleOfGraphQLRequest(IMiddlewareContext context)
{
string role = string.Empty;
if (context.ContextData.TryGetValue(key: AuthorizationResolver.CLIENT_ROLE_HEADER, out object? value) && value is StringValues stringVals)
{
role = stringVals.ToString();
}

if (string.IsNullOrEmpty(role))
{
throw new DataApiBuilderException(
message: "No ClientRoleHeader available to perform authorization.",
statusCode: HttpStatusCode.Unauthorized,
subStatusCode: DataApiBuilderException.SubStatusCodes.AuthorizationCheckFailed);
}

return role;
}

/// <summary>
/// The method is for parsing the mutation input object with nested inner objects when input is passing inline.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Core/Resolvers/IMutationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Core.Models;
using Azure.DataApiBuilder.Service.Exceptions;
using HotChocolate.Resolvers;
using Microsoft.AspNetCore.Mvc;

Expand Down Expand Up @@ -41,12 +42,13 @@ public interface IMutationEngine
/// <summary>
/// Authorization check on mutation fields provided in a GraphQL Mutation request.
/// </summary>
/// <param name="context">Middleware context of the mutation</param>
/// <param name="context">GraphQL request context.</param>
/// <param name="clientRole">Client role header value extracted from the middleware context of the mutation</param>
/// <param name="parameters">parameters in the mutation query.</param>
/// <param name="entityName">entity name</param>
/// <param name="mutationOperation">mutation operation</param>
/// <exception cref="DataApiBuilderException"></exception>
public void AuthorizeMutationFields(
public void AuthorizeMutation(
IMiddlewareContext context,
IDictionary<string, object?> parameters,
string entityName,
Expand Down
Loading