[ https://issues.apache.org/jira/browse/CLK-406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12695693#action_12695693
]
Adrian A. commented on CLK-406:
-------------------------------
I think adding plug-able role checking to the actual Menu content is quite simple: even by
keeping it 100% backwards compatible. If you modify the Menu class as described below, you
can use your own role checking (e.g. from your Cayenne service class).
#1. Add to the body of Menu.java the following interface:
<pre>
public static interface RoleChecker {
boolean isUserInRole(String roleName);
}
</pre>
#2. Add a default implementation for this interface, as it is working now (with the servlet
container) after #1
<pre>
protected RoleChecker roleChecker = new RoleChecker() {
public boolean isUserInRole(String roleName) {
return getContext().getRequest().isUserInRole(roleName);
}
};
</pre>
#3 In the method Menu#isUserInRoles(), change the line
<pre>
if (context.getRequest().isUserInRole(rolename)) {
</pre>
to something like:
<pre>
if (roleChecker.isUserInRole(rolename)) {
</pre>
to allow the Menu component to use this plug-able role cheking.
#4 Add a setter for this role checking interface to the Menu control:
<pre>
public void setRoleChecker(RoleChecker roleChecker){
this.roleChecker = roleChecker;
}
</pre>
That's all.
Now if you want to use a different role checking than the servlet container, just use the
setter from #4, e.g.
in the case of click-examples with Cayenne, this would be in BorderPage:
<pre>
rootMenu.setRoleChecker(new Menu.RoleChecker() {
public boolean isUserInRole(String roleName) {
return getUserService().isUserInRole();
}
});
</pre>
where getUserService().isUserInRole() would be you Cayenne based role checking.
This is backwards compatible (the default works as before) and simple to use.
> Menu improvements - plug-able role checking.
> --------------------------------------------
>
> Key: CLK-406
> URL: https://issues.apache.org/jira/browse/CLK-406
> Project: Click
> Issue Type: Improvement
> Components: extras
> Reporter: Demetrios Kyriakis
>
> Please improve the Menu Control, by allowing the user to have a plug-able role cheking
for the menu items.
> Right now the Menu Control is using HttpRequest#isUserInRole(String role), but most webapplications
> don't use this strategy for user/roles management, so this method returns false for all
those cases :(.
> This is very limiting, making the existing Menu Control useless for most user applications,
thus forcing the users
> to make their own menu controls (or the hack the original one).
> Please allow to set a different method for this operation by the user (if no other is
used, of course, the default one - mentioned above - would be used as before - so 100% backwards
compatible).
> Thank you,
> Demetrios.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
|