[opencms-dev] OpenCms Administration Tools/Roles HOW-TO

Michael Moossen m.moossen at alkacon.com
Thu Oct 20 13:05:18 CEST 2005


Hi, All!

To programmatically set the visibility and/or enabled flags for administration
tools.

Create a new tool handler extending
org.opencms.workplace.tools.A_CmsToolHandler,
for this you will need to implement 2 methods: isEnabled(CmsObject) and
isVisible(CmsObject)

In these methods you can use the CmsObject.hasRole(CmsRole) method. as for
example:
-------------
public class SampleToolHandler extends A_CmsToolHandler {
    public boolean isEnabled(CmsObject cms) {
        return cms.hasRole(CmsRole.ADMINISTRATOR);
    }
    public boolean isVisible(CmsObject cms) {
        return cms.hasRole(CmsRole.VFS_MANAGER);
    }
}
-------------
This tool will be visible for users having the VFS_MANAGER role, but only
enabled for users with the ADMINISTRATOR role.

Then, set the 'admintoolhandler-class' property of the tool in question to your
new class name, and be sure to place your class somewhere your servlet
container can find it.

To keep in mind: all the properties related to the admin tools are only read
during the workplace initialization process. it is not enough to change the
value to see a change in behaviour.
you have to reinitialize the workplace.

but what is if no system role (defined in the org.opencms.security.CmsRole
class) fits your needs 100%?
Just create a new role, for instance:
-------------
public static final CmsRole SAMPLE = new CmsRole("SAMPLE", "Sample Group", new
CmsRole[] {CmsRole.ADMINISTRATOR});
-------------
Every direct or indirect member of the "Sample Group" group will have this role,
and also everybody having the ADMINISTRATOR role.

PD: some day it will be an administration tool to administrate the roles.

-- 
Regards
Michael Moossen

Alkacon Software GmbH - The OpenCms Experts
http://www.alkacon.com


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the opencms-dev mailing list