001/*
002 * File   : $Source$
003 * Date   : $Date$
004 * Version: $Revision$
005 *
006 * This library is part of OpenCms -
007 * the Open Source Content Management System
008 *
009 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com)
010 *
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU Lesser General Public
013 * License as published by the Free Software Foundation; either
014 * version 2.1 of the License, or (at your option) any later version.
015 *
016 * This library is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 * Lesser General Public License for more details.
020 *
021 * For further information about Alkacon Software, please see the
022 * company website: http://www.alkacon.com
023 *
024 * For further information about OpenCms, please see the
025 * project website: http://www.opencms.org
026 *
027 * You should have received a copy of the GNU Lesser General Public
028 * License along with this library; if not, write to the Free Software
029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030 */
031
032package org.opencms.workplace.tools.sites;
033
034import org.opencms.file.CmsObject;
035import org.opencms.main.OpenCms;
036import org.opencms.security.CmsRole;
037import org.opencms.workplace.tools.A_CmsToolHandler;
038
039/**
040 * Sites management tool handler that hides the tool if the current user
041 * has not the needed privileges.<p>
042 *
043 * @since 9.0.0
044 */
045public class CmsSitesToolHandlerWebserver extends A_CmsToolHandler {
046
047    /** Parameter name to enable or disable the configuration. */
048    private static final String PARAM_ENABLED = "enableconfig";
049
050    /** The name of this module. */
051    private static final String MODULE_NAME = "org.opencms.workplace.tools.sites";
052
053    /**
054     * @see org.opencms.workplace.tools.I_CmsToolHandler#isEnabled(org.opencms.file.CmsObject)
055     */
056    public boolean isEnabled(CmsObject cms) {
057
058        boolean isEnabled = Boolean.valueOf(
059            OpenCms.getModuleManager().getModule(MODULE_NAME).getParameter(
060                PARAM_ENABLED,
061                Boolean.TRUE.toString())).booleanValue();
062        return isEnabled && OpenCms.getRoleManager().hasRole(cms, CmsRole.ROOT_ADMIN);
063    }
064
065    /**
066     * @see org.opencms.workplace.tools.A_CmsToolHandler#isVisible(org.opencms.file.CmsObject)
067     */
068    public boolean isVisible(CmsObject cms) {
069
070        return isEnabled(cms);
071    }
072}