Skip to content

Commit 14afafd

Browse files
committed
Added row-level security
1 parent c4061a3 commit 14afafd

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/Application/Functions/DetermineCustomerAccess.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RETURN (SELECT 1 AS AccessResult
1010
INNER JOIN [Application].StateProvinces AS sp
1111
ON c.StateProvinceID = sp.StateProvinceID
1212
WHERE c.CityID = @CityID) + N' Sales') <> 0
13-
OR (ORIGINAL_LOGIN() = N'Website'
13+
OR ((ORIGINAL_LOGIN() = N'Website' OR ORIGINAL_LOGIN() = N'WebApi')
1414
AND EXISTS (SELECT 1
1515
FROM [Application].Cities AS c
1616
INNER JOIN [Application].StateProvinces AS sp

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/Security/Permissions.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ GRANT VIEW ANY COLUMN ENCRYPTION KEY DEFINITION TO PUBLIC;
55
GO
66
GRANT VIEW ANY COLUMN MASTER KEY DEFINITION TO PUBLIC;
77
*/
8+
9+
GO
10+
CREATE LOGIN WebApi WITH PASSWORD = 'Sp1d3rman!';
11+
GO
12+
CREATE USER WebApi FROM LOGIN WebApi;
13+
GO
14+
GRANT EXECUTE ON SCHEMA::WebApi TO WebApi;
15+
GO
16+
GRANT SELECT ON SCHEMA::WebApi TO WebApi;
17+
GO
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE PROCEDURE [WebApi].[Login](@LogonName nvarchar(256), @Password nvarchar(256))
2+
WITH EXECUTE AS OWNER
3+
AS BEGIN
4+
select PersonID, PreferredName, IsSalesperson, IsEmployee,
5+
Territory = JSON_VALUE(CustomFields,'$.PrimarySalesTerritory')
6+
from Application.People
7+
where IsPermittedToLogon = 1
8+
and LogonName = @LogonName
9+
--and HashedPassword = HASHBYTES(N'SHA2_256', @Password)",
10+
END

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Views/CustomerTransactions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SELECT ct.CustomerTransactionID, ct.TransactionDate, ct.AmountExcludingTax, ct.T
44
c.CustomerName, tt.TransactionTypeName, i.InvoiceDate, i.CustomerPurchaseOrderNumber, pm.PaymentMethodName,
55
ct.CustomerID, ct.TransactionTypeID, ct.InvoiceID, ct.PaymentMethodID
66
FROM Sales.CustomerTransactions AS ct
7-
LEFT OUTER JOIN Sales.Invoices AS i ON ct.InvoiceID = i.InvoiceID
7+
JOIN Sales.Customers AS c ON ct.CustomerID = c.CustomerID
8+
JOIN Sales.Invoices AS i ON ct.InvoiceID = i.InvoiceID
89
LEFT OUTER JOIN Application.TransactionTypes AS tt ON ct.TransactionTypeID = tt.TransactionTypeID
9-
LEFT OUTER JOIN Sales.Customers AS c ON ct.CustomerID = c.CustomerID
1010
LEFT OUTER JOIN Application.PaymentMethods AS pm ON ct.PaymentMethodID = pm.PaymentMethodID

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WideWorldImporters.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@
773773
<AnsiNulls>On</AnsiNulls>
774774
<QuotedIdentifier>On</QuotedIdentifier>
775775
</Build>
776+
<Build Include="WebApi\Stored Procedures\Login.sql" />
776777
</ItemGroup>
777778
<ItemGroup>
778779
<PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />

0 commit comments

Comments
 (0)