Search code examples
shiro

Permission control using apache shiro


I am new in apache shiro, and I read almost 60% of tutorials in apache shiro page.

It is a wonderful framework, however I wonder if it can meet my requirements.

I am interested in the permission-based authentication.

For example, to make sure if the user have the permission of delete resources, we can use this:

currentUser.isPermitted( "resource:delete" );

However in our application, even a user have the permission of delete resources, he can only delete some specified resources, not all of them.

For example(just an exmaple), the resource have an filed named createdby to record the one who create this resource.

Now user can only delete the resources created by himself if he have the resouce:delete permission.

In fact, the resources which can be deleted by the user(who have authenticated and have delete permission) will be calculated by more constraints.

Now how to make shiro work in this suitation?


Solution

  • From the extent, I have explored Shiro, I don't think it gives that level of flexibility to have a customized check. It basically functions based on roles and permission defined in the config file.

    For this functionality I would suggest that you display only those records the user is allowed to delete, by have this check at query fetch level. (or) add a condition at the UI level not display the delete button if logged in user is same as created by. This is just a suggestion.