[Lazarus] allow/Deny user to show form
Fabio Luis Girardi
fluisgirardi at gmail.com
Wed Feb 15 21:39:03 CET 2017
I don't know if the solution that I implemented last night is the best one.
I did the following:
//FIsEnabledBySecurity: the user can access the control? this variable is
changed via another call, when user login or logout, checking the
authorizations of the logged user.
//FAllowUnauthorizedShowForm: value of a property that sets if not allowed
users can show the form or not.
procedure TpSCADASecureForm.SetVisible(Value: boolean); override;
begin
FIsPSCADAFormVisible:=Value;
inherited SetVisible(FIsPSCADAFormVisible and (FIsEnabledBySecurity or
FAllowUnauthorizedShowForm));
end;
this do the job very well, showing and hiding the form across user
login/logout changes, even if I call
TsomePSCADAFormInstance = class(TpSCADASecureForm);
somePSCADAFormInstance:TsomePSCADAFormInstance;
somePSCADAFormInstance.Visible := true;
somePSCADAFormInstance.Show;
but when I call
somePSCADAFormInstance.ShowModal;
I got a Exception that says that somePSCADAFormInstance is not enabled
(that is true, because I have a access try of a not allowed user), but this
exception is not the real cause of the problem, that is access of a not
allowed user or a not logged user.
My solution at this point is override the ShowModal:
//FSecurityCode is a property with a string that describes the permission
that you will give or not for each user
//GetPascalSCADAControlSecurityManager: class instance that manages the
control interaction with users and their permissions, 44
//Each control that supports the interface ISecureControlInterface, should
register/unregister with this manager, to be notified about user
changes/permission changes.
function TpSCADASecureForm.ShowModal: Integer; override;
begin
if GetPascalSCADAControlSecurityManager.CanAccess(FSecurityCode)=false
then
raise ESecuritySystemAccessDenied.Create(FSecurityCode);
Result:=inherited ShowModal;
end;
What is your opinion?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170215/f59b20ab/attachment.html>
More information about the Lazarus
mailing list