The javax.servlet.http.HttpServletRequest
class has a method called isUserInRole
. I use this to check if a user has, for example, the admin
role. However, that method is case sensitive. So, if the role in the request was Admin
or ADMIN
, then isUserInRole("admin")
would be false. I use the isUserInRole
method in a number of places accross multiple applications to check for a number of different roles.
Is there a way to achieve the isUserInRole
functionality case-insensitively that does not require checking each different possible case combination with isUserInRole
?
The docs for getHeader(String) state: The header name is case insensitive.
Parameter names are case sensitive so, for example, request. get- Parameter("Param1") and request. getParameter("param1") are not interchangeable. The values supplied to getParameter and getParameterValues are case sensitive.
The HttpServletRequest provides methods for accessing parameters of a request. The type of the request determines where the parameters come from. In most implementations, a GET request takes the parameters from the query string, while a POST request takes the parameters from the posted arguments.
The HttpServletRequest object can be used to retrieve incoming HTTP request headers and form data. The HttpServletResponse object can be used to set the HTTP response headers (e.g., content-type) and the response message body.
You could implement a filter that wraps requests using a HttpServletRequestWrapper
- implement your HttpServletRequestWrapper to override the isUserInRole()
method to make it case-insensitive (eg, configure all roles in upper-case, test role params by converting to upper-case).
A quick search will find plenty of HTTPServletRequestWrapper examples...
http://docs.oracle.com/javaee/6/tutorial/doc/gjiie.html
Just map multiple role names to the admin role:
<servlet>
<security-role-ref>
<role-name>admin</role-name>
<role-link>admin</role-link>
</security-role-ref>
<security-role-ref>
<role-name>Admin</role-name>
<role-link>admin</role-link>
</security-role-ref>
</servlet>
<security-role>
<role-name>admin</role-name>
</security-role>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With