Dimmed buttons are not a permission check - admin forms in Uniface
Stage 33 of the customer app from the series Building a customer app in Uniface 10 added six modules. Two of them show data that only administrators should see: an audit view (changes per user, failed logins, exports) an
Stage 33 of the customer app from the series Building a customer app in Uniface 10 added six modules. Two of them show data that only administrators should see: an audit view (changes per user, failed logins, exports) and a job monitor. The other four are open to every role.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).
Two layers
The form decides what the user can click. The service decides what the user gets. Only the second one is a protection: a service can be called from other forms, from a batch or from a test, and none of them pass through the form.
The form: dim, don't hide
When the form starts, it asks for the current user and role and dims the buttons if the role is below ADMIN:
entry SET_RIGHTS
variables
string vUser, vRole
boolean vOk
endvariables
activate "USER_SVC".CURRENT_USER(vUser, vRole)
INFO.AU2_DMY = "Logged in as %%(vUser) (%%(vRole))"
call ROLE_AT_LEAST("ADMIN", vOk)
if (vOk = 0)
$fieldsyntax(BTN_USERS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_HOURS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_LOGINS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_FIELDS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_APPROVALS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_EXPORTS.AU2_DMY) = "DIM"
$fieldsyntax(BTN_REPORT.AU2_DMY) = "DIM"
endif
return 0
end
ROLE_AT_LEAST is a small helper in the shared include for forms. Roles are ordered READ < EDIT < ADMIN:
entry ROLE_AT_LEAST
params
string pNeeded : IN
boolean pOk : OUT
endparams
variables
string vUser, vRole
numeric vHave, vWant
endvariables
activate "USER_SVC".CURRENT_USER(vUser, vRole)
vHave = 0
if (vRole = "READ")
vHave = 1
elseif (vRole = "EDIT")
vHave = 2
elseif (vRole = "ADMIN")
vHave = 3
endif
vWant = 3
if (pNeeded = "READ")
vWant = 1
elseif (pNeeded = "EDIT")
vWant = 2
endif
pOk = 0
if (vHave >= vWant)
pOk = 1
endif
return 0
end
A dimmed button stays visible and cannot be clicked. In the click test a reader opened the audit form, saw all buttons in grey, clicked one and nothing happened. The info line says who is logged in, so the reason is clear. Hiding the buttons would leave an empty form that looks broken.
The menu that opens the forms keeps both entries active and marks them with "(admin)". A reader may look at the form; the data stays behind the service.
The service: check first
Every operation of an admin service starts with the same three lines:
public operation NEVER_RUN
params
string pData : OUT
numeric pCount : OUT
string pError : OUT
endparams
pData = ""
pCount = 0
pError = ""
activate "RIGHTS_SVC".REQUIRE("ADMIN", pError)
if ($status < 0)
return -1
endif
...
end
REQUIRE is in a shared rights service:
public operation REQUIRE
params
string pRight : IN
string pError : OUT
endparams
variables
string vUser, vRole
boolean vAllowed
endvariables
pError = ""
activate "USER_SVC".HAS_RIGHT(pRight, vAllowed)
if (vAllowed)
return 0
endif
activate "USER_SVC".CURRENT_USER(vUser, vRole)
pError = "This function needs the role %%(pRight). You are logged in as %%(vUser) with the role %%(vRole)."
return -1
end
The message names the needed role and the current one. Forms show pError in their info line, so a reader who gets past the dimmed button (for example through another form) gets a sentence instead of an empty list.
The test: log in as a reader
The test service of the stage creates a temporary READ user, logs in and calls two admin operations. Both must fail:
activate "AUDIT2_SVC".FIELD_HOTSPOTS("", "", vData, vCount, vError)
vS = $status
call CHECK("RIGHTS a reader may not call AUDIT2.FIELD_HOTSPOTS", (vS < 0), "status %%(vS)", pTests, pFailures)
activate "JOBMON_SVC".NEVER_RUN(vData, vCount, vError)
vS = $status
call CHECK("RIGHTS a reader may not call JOBMON.NEVER_RUN", (vS < 0), "status %%(vS)", pTests, pFailures)
The same test also calls one operation of each open module as the reader and expects success. Without this half, a service that refuses everybody would pass.
Notes
-
$fieldsyntaxwith "DIM" is set at runtime; the form definition stays the same for all roles. - A new user created in the user form must change the password at the first login. The click test with the reader started with that dialog.
- The test user and its login entries are removed at the end of the test; the database file has the same checksum before and after the run.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.