Java – case insensitive checking of roles in HttpServletRequest

javax. servlet. http. The HttpServletRequest class has a method named isuserinrole I use it to check whether the user has, for example, the admin role However, this method is case sensitive Therefore, if the role in the request is admin or admin, isuserinrole ("admin") will be false I use the isuserinrole method in multiple places in multiple applications to check multiple different roles

Is there a way to implement the isuserinrole function - you don't need to check every different possible combination of situations from isuserinrole?

Solution

You can use httpservletrequestwrapper to implement a filter that uses httpservletrequestwrapper to wrap requests – implement your httpservletrequestwrapper to override the isuserinrole () method so that it is case insensitive (for example, by converting to uppercase), configure all roles with case, and test role parameters to case)

A quick search will find a large number of httpservletrequestwrapper examples

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>