click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian A. (JIRA)" <>
Subject [jira] Commented: (CLK-406) Menu improvements - plug-able role checking.
Date Sat, 04 Apr 2009 09:25:13 GMT


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 the following interface:
public static interface RoleChecker {
        boolean isUserInRole(String roleName);

#2. Add a default implementation for this interface, as it is working now (with the servlet
container) after #1
protected RoleChecker roleChecker = new RoleChecker() {
        public boolean isUserInRole(String roleName) {
            return getContext().getRequest().isUserInRole(roleName);

#3 In the method Menu#isUserInRoles(), change the line 
if (context.getRequest().isUserInRole(rolename)) {
to something like:
if (roleChecker.isUserInRole(rolename)) {
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:
public void setRoleChecker(RoleChecker roleChecker){
        this.roleChecker = roleChecker;

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:
rootMenu.setRoleChecker(new Menu.RoleChecker() {
            public boolean isUserInRole(String roleName) {
                return getUserService().isUserInRole();
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:
>             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
> Thank you,
> Demetrios.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message