Exercise - Secure and troubleshoot an extension
In this exercise, you build an extension-owned note feature and test two roles in a Business Central online sandbox. The result demonstrates that assigned execute access controls entry to a bounded service, while the service's inherent permission doesn't grant direct table insertion.
Prepare the sandbox and project
Use an existing AL project connected to a Business Central online sandbox. The project must have object IDs 70600 through 70699 available. All objects in this exercise belong to this extension.
Ask a tenant administrator to provision two nonproduction test identities with the same Business Central Essentials or Premium sandbox license. Neither identity has SUPER or unrelated broad permissions, and the administrator performs all permission assignments. Don't expose, share, or store test credentials. If two identities aren't available, repeat the tests with one test identity after the administrator changes assignments and you sign in again.
This exercise doesn't add an entitlement object because no approved Partner Center service ID is available. It tests assigned permissions and a bounded inherent permission under the sandbox's existing license entitlement.
Before you begin:
- Confirm that the AL project publishes to the intended sandbox and uses object IDs 70600 through 70699.
- Remove
SUPERand unrelated broad inherited permissions from both test identities in the sandbox. - Confirm that both identities can sign in to the same test company.
- Create the following AL files in sensible source folders in the existing project.
Build the secured note objects
Create SecureNote.Table.al:
table 70600 "Secure Note"
{
DataClassification = CustomerContent;
fields
{
field(1; "Entry No."; Integer)
{
AutoIncrement = true;
}
field(2; "Note Text"; Text[100])
{
}
field(3; "Created By"; Code[50])
{
}
field(4; "Created At"; DateTime)
{
}
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
}
}
Create SecureNoteService.Codeunit.al. The service has no user-interface calls. Its public method inserts one app-owned record and records the current user and time:
codeunit 70600 "Secure Note Service"
{
[InherentPermissions(PermissionObjectType::TableData, Database::"Secure Note", 'i', InherentPermissionsScope::Both)]
procedure CreateNote(NoteText: Text[100])
var
SecureNote: Record "Secure Note";
begin
SecureNote.Init();
SecureNote."Note Text" := NoteText;
SecureNote."Created By" := CopyStr(UserId(), 1, MaxStrLen(SecureNote."Created By"));
SecureNote."Created At" := CurrentDateTime();
SecureNote.Insert(true);
end;
}
Create SecureNotes.Page.al. The page is read-only at page level. Add bounded note calls the service and refreshes the page. Try direct insert attempts the same table operation outside the attributed method:
page 70600 "Secure Notes"
{
PageType = List;
SourceTable = "Secure Note";
ApplicationArea = All;
UsageCategory = Lists;
InsertAllowed = false;
ModifyAllowed = false;
DeleteAllowed = false;
layout
{
area(Content)
{
repeater(Notes)
{
field("Entry No."; Rec."Entry No.")
{
ApplicationArea = All;
}
field("Note Text"; Rec."Note Text")
{
ApplicationArea = All;
}
field("Created By"; Rec."Created By")
{
ApplicationArea = All;
}
field("Created At"; Rec."Created At")
{
ApplicationArea = All;
}
}
}
}
actions
{
area(Processing)
{
action(AddBoundedNote)
{
ApplicationArea = All;
Caption = 'Add bounded note';
trigger OnAction()
var
SecureNoteService: Codeunit "Secure Note Service";
begin
SecureNoteService.CreateNote('Created through the bounded service');
CurrPage.Update(false);
Message('The bounded note was added.');
end;
}
action(TryDirectInsert)
{
ApplicationArea = All;
Caption = 'Try direct insert';
trigger OnAction()
var
SecureNote: Record "Secure Note";
begin
SecureNote.Init();
SecureNote."Note Text" := 'Attempted outside the bounded service';
SecureNote."Created By" := CopyStr(UserId(), 1, MaxStrLen(SecureNote."Created By"));
SecureNote."Created At" := CurrentDateTime();
SecureNote.Insert(true);
Message('The direct note was added.');
end;
}
}
}
}
The platform checks authorization at SecureNote.Insert(true). For both test roles, that check raises a permission error before the direct-insert success message can run.
Compose and publish the roles
Create SecNoteData.PermissionSet.al. This nonassignable set grants table object execution, table-data read, and page execution, but no insert permission:
permissionset 70600 "SEC NOTE DATA"
{
Assignable = false;
Permissions =
table "Secure Note" = X,
tabledata "Secure Note" = R,
page "Secure Notes" = X;
}
Create SecNoteUser.PermissionSet.al. Its assignable name is within the 20-character limit:
permissionset 70601 "SEC NOTE USER"
{
Assignable = true;
IncludedPermissionSets = "SEC NOTE DATA";
}
Create SecNoteActions.PermissionSetExt.al. The extension adds only execute permission for the app-owned service:
permissionsetextension 70602 "SEC NOTE ACTIONS" extends "SEC NOTE USER"
{
Permissions =
codeunit "Secure Note Service" = X;
}
Create SecNoteReviewer.PermissionSet.al. This role can open and read the page but doesn't receive service execution:
permissionset 70603 "SEC NOTE REVIEWER"
{
Assignable = true;
IncludedPermissionSets = "SEC NOTE DATA";
}
Publish the extension to the sandbox. Resolve compilation or publication errors in the existing project before you continue. Don't add table-data insert to either assignable role, and don't use SUPER as a fix.
Assign and test effective access
The tenant administrator assigns roles through Users or through security groups. Apply assignments to the same test company when you use company-specific scope:
- Assign
SEC NOTE REVIEWERto test identity A. - Assign
SEC NOTE USERto test identity B. - On Users, open Effective Permissions for each identity and filter to object IDs 70600 through 70603.
- Use Effective Permissions By Set or View all permissions to record which set supplies page, table, table-data, and codeunit access.
- Sign in as each identity in a separate private browser session, open Secure Notes, and run both actions.
Record this expected matrix:
| Test | Identity A: SEC NOTE REVIEWER |
Identity B: SEC NOTE USER |
|---|---|---|
| Open and read Secure Notes | Succeeds. | Succeeds. |
| Select Add bounded note | Fails because service execute is absent. | Succeeds because the extension adds service execute and the attributed method supplies bounded insert. |
| Select Try direct insert | Fails because direct table-data insert is absent. | Fails because direct table-data insert is absent. |
For identity B, verify that the new row records the identity in Created By and the insertion time in Created At. Then inspect Effective Permissions and confirm that identity B still doesn't have direct insert permission on table data 70600.
Create two troubleshooting records with this structure:
| Symptom | Controlling layer | Evidence | Narrow correction |
|---|---|---|---|
| Identity A can't run Add bounded note. | Permission-set composition. | Effective Permissions By Set shows page execution and table-data read, but no codeunit 70600 execute permission. | Assign SEC NOTE USER only if the reviewer needs the bounded action, or retain the separation when review-only access is intended. |
| Identity B can't run Add bounded note after an update. | Extension dependency or version, or missing composed execute permission. | RT0031 object details and AL stack trace identify the denied codeunit and extension version. Expanded Permissions confirms whether the extension contribution is active. |
Publish the matching app version or restore the specific codeunit execute addition, then retest as identity B. |
Don't broaden either role while investigating. Match RT0031 by user telemetry ID, company, client type, error time, object type and ID, extension metadata, and AL stack trace.
Clean up the sandbox
- Ask the administrator to remove
SEC NOTE REVIEWERandSEC NOTE USERassignments from the test identities or security groups. - Delete the test records as an administrator.
- Uninstall and unpublish the exercise extension when the sandbox no longer needs it.
- Remove the nonproduction identities according to the tenant's test-account policy.
- Confirm that no test credentials remain in notes, source files, browser profiles, or troubleshooting records.