SBarnes wrote:is there a way to the plug the new business object into Jiwa's security?
Currently security is managed by default at the UI level. If you have a form using your business logic, then the security/permissions system in Jiwa can control who is allowed to load that form automatically. If a user uses an application which uses the Jiwa business logic (eg: 3rd party developed application) then there is no
automatic permission controls.
You can, however create an abstract permission and have your business logic check the current user has that permission on instantiation or setup of the business logic - or any other method when invoked. That way you can enforce permissions purely on the business logic level.
An example is the abstract permission in the sales order business logic to control who can process a sales order:
- Code: Select all
Dim processPermission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "Process")
If processPermission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
Throw New JiwaApplication.Exceptions.PermissionDeniedException("You do not have the required permission to process a sales order")
End If
The above code is in the Process method of the sales order business logic class. It is looking at an abstract permission for the form which has a class name of "JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", and the permission name is "Process".
To set the permission you need to edit the permissions for the sales order form - open the sales order form, on the utilities tab choose set permissions and then on the permission dialog on the abstract permissions tab you will see those permissions.
So, you could use the above to have your own business logic permissions for your own object - if you have a form for your business logic, then you obviously should put it there. If you don't have a form, then it really doesn't matter where you place the abstract permission - you can add it to any existing form - you just need a form which has an entry in the table SY_Forms so you have a way in the user interface to set the permissions.
To add your own abstract permission you need to perform a SQL insert into the SY_FormsAbstractPermissions table. For example - if you wanted to add one to sales orders - then you would do this:
- Code: Select all
INSERT INTO SY_FormsAbstractPermissions(RecID, SY_Forms_ClassName, Name, Description, ItemNo)
SELECT NewID(), 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm', 'My Permission', 'My test permission',
(SELECT COALESCE(MAX(ItemNo), 0) + 1 FROM SY_FormsAbstractPermissions WHERE SY_Forms_ClassName = 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm')
Now if you load the permissions dialog you will see that permission in the abstract permissions list (you will need to logout and log back into Jiwa after running the above query) and you can set the permission each user group has for that.
Then in your business logic, you can do a check like the following to control what methods the user can invoke:
- Code: Select all
Dim myPermission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "My Permission")
If myPermission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
Throw New JiwaApplication.Exceptions.PermissionDeniedException("You do not have permission")
End If
You can also do this in the constructor (New sub in VB.Net) to cause an exception on instantiation to completely prevent use of the object. Then, when you attempt to create your object using the business logic factory (or when they invoke a method in which you throw a PermissionDeniedException), you can selectively deal with insufficient permissions by catching the PermissionDeniedException.
- Code: Select all
Try
myBL = JiwaApplication.BusinessLogicFactory.Instance.CreateBusinessLogic(Of MyNS.MyClass)(Nothing)
Catch permissionDenied As JiwaApplication.Exceptions.PermissionDeniedException
' gracefully handle a no-permission exception
End Try
I hope that all makes sense!
Mike