Checks whether the current user has permissions for mass editing the alias table.<p>

@param cms the current CMS context
@param siteRoot the site root to check
@return true if the user from the CMS context is allowed to mass edit the alias table
322692
public boolean hasPermissionsForMassEdit(CmsObject cms, String siteRoot) {

        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
        try {
            cms.getRequestContext().setSiteRoot(siteRoot);
            return OpenCms.getRoleManager().hasRoleForResource(cms, CmsRole.ADMINISTRATOR, "/");
        } finally {
            cms.getRequestContext().setSiteRoot(originalSiteRoot);
        }

    }
1119082
private boolean lockResource(CmsObject cms, CmsResource cmsResource) throws CmsException {

        CmsLock lock = cms.getLock(cms.getSitePath(cmsResource));
        // check the lock
        if ((lock != null)
            && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
            && lock.isOwnedInProjectBy(
                cms.getRequestContext().getCurrentUser(),
                cms.getRequestContext().getCurrentProject())) {
            // prove is current lock from current user in current project
            return true;
        } else if ((lock != null) && !lock.isUnlocked() && !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) {
            // the resource is not locked by the current user, so can not lock it
            return false;
        } else if ((lock != null)
            && !lock.isUnlocked()
            && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
            && !lock.isOwnedInProjectBy(
                cms.getRequestContext().getCurrentUser(),
                cms.getRequestContext().getCurrentProject())) {
            // prove is current lock from current user but not in current project
            // file is locked by current user but not in current project

            cms.changeLock(cms.getSitePath(cmsResource));
        } else if ((lock != null) && lock.isUnlocked()) {
            // lock resource from current user in current project
            cms.lockResource(cms.getSitePath(cmsResource));
        }
        lock = cms.getLock(cms.getSitePath(cmsResource));
        if ((lock != null)
            && lock.isOwnedBy(cms.getRequestContext().getCurrentUser())
            && !lock.isOwnedInProjectBy(
                cms.getRequestContext().getCurrentUser(),
                cms.getRequestContext().getCurrentProject())) {
            // resource could not be locked
            return false;
        }
        // resource is locked successfully
        return true;
    }
754518
private void selectSite(String siteRoot) {

        if (m_sortSelectBox == null) {
            return;
        }
        Map<String, String> options = m_sortSelectBox.getItems();
        String option = null;
        for (Map.Entry<String, String> entry : options.entrySet()) {
            if (CmsStringUtil.comparePaths(entry.getKey(), siteRoot)) {
                option = entry.getKey();
                break;
            }
        }
        if (option != null) {
            m_sortSelectBox.setFormValue(option, false);
        }
    }
623090
public boolean hasRole(CmsObject cms, CmsRole role) {

        return m_securityManager.hasRole(cms.getRequestContext(), cms.getRequestContext().getCurrentUser(), role);
    }
3382
private boolean checkLock(CmsResource resource) throws CmsException {

        CmsLock lock = m_cms.getLock(resource);
        return lock.isUnlocked() || lock.getUserId().equals(m_cms.getRequestContext().getCurrentUser().getId());
    }
1254401
public boolean requiresPasswordChange(CmsObject cms, CmsUser user) {

        if (user.isManaged()
            || user.isWebuser()
            || OpenCms.getDefaultUsers().isDefaultUser(user.getName())
            || OpenCms.getRoleManager().hasRole(cms, user.getName(), CmsRole.ROOT_ADMIN)) {
            return false;
        }
        String lastPasswordChangeStr = (String)user.getAdditionalInfo().get(
            CmsUserSettings.ADDITIONAL_INFO_LAST_PASSWORD_CHANGE);
        if (lastPasswordChangeStr == null) {
            return false;
        }
        long lastPasswordChange = Long.parseLong(lastPasswordChangeStr);
        if ((System.currentTimeMillis() - lastPasswordChange) > getPasswordChangeInterval()) {
            return true;
        }
        return false;
    }
604936
protected void onSiteChange(String site) {

        try {
            m_treeData.removeAllItems();
            CmsObject rootCms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            rootCms.getRequestContext().setSiteRoot("");
            CmsResource siteRootResource = rootCms.readResource(site);

            m_treeData.initRoot(rootCms, siteRootResource);
            m_fileTree.expandItem(siteRootResource.getStructureId());
            m_siteRoot = site;
            updateRoot(rootCms, siteRootResource);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
640875
public void submit(CmsUser user, CmsObject cms, Runnable afterWrite, boolean force) {

        try {
            if (isValid() | force) {
                if (force) {
                    removeValidators();
                }
                m_binder.commit();
                PropertyUtilsBean propUtils = new PropertyUtilsBean();
                for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) {
                    boolean editable = (m_editLevel == EditLevel.all)
                        || ((m_editLevel == EditLevel.configured) && info.isEditable());
                    if (editable) {
                        if (info.isAdditionalInfo()) {
                            user.setAdditionalInfo(info.getAddInfoKey(), m_infos.getItemProperty(info).getValue());
                        } else {
                            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(
                                (String)m_infos.getItemProperty(info).getValue())) {
                                propUtils.setProperty(
                                    user,
                                    info.getField().name(),
                                    m_infos.getItemProperty(info).getValue());
                            }
                        }
                    }
                }
                cms.writeUser(user);
                afterWrite.run();
            }
        } catch (CmsException | CommitException | IllegalAccessException | InvocationTargetException
        | NoSuchMethodException e) {
            LOG.error("Unable to commit changes to user..", e);
        }
    }
471918
public CmsRewriteAliasMatcher getRewriteAliasMatcher(CmsObject cms, String siteRoot) throws CmsException {

        List<CmsRewriteAlias> aliases = getRewriteAliases(cms, siteRoot);
        return new CmsRewriteAliasMatcher(aliases);
    }
353166
protected CmsADEConfigData internalLookupConfiguration(CmsObject cms, String rootPath) {

        boolean online = (null == cms) || isOnline(cms);
        CmsADEConfigCacheState state = getCacheState(online);
        return state.lookupConfiguration(rootPath);
    }
1215485
public CmsPermissionSetCustom getPermissions(CmsUser user, List<CmsGroup> groups, List<CmsRole> roles) {

        CmsPermissionSetCustom sum = new CmsPermissionSetCustom();
        boolean hasPermissions = false;
        CmsPermissionSet p = m_permissions.get(user.getId());
        if (p != null) {
            sum.addPermissions(p);
            hasPermissions = true;
        }
        if (groups != null) {
            int size = groups.size();
            for (int i = 0; i < size; i++) {
                I_CmsPrincipal principal = groups.get(i);
                p = m_permissions.get(principal.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (roles != null) {
            int size = roles.size();
            for (int i = 0; i < size; i++) {
                CmsRole role = roles.get(i);
                p = m_permissions.get(role.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (!hasPermissions) {
            // if no applicable entry is found check the 'all others' entry
            p = m_permissions.get(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID);
            if (p != null) {
                sum.addPermissions(p);
            }
        }
        return sum;
    }
647586
public void removeSite(CmsObject cms, CmsSite site) throws CmsException {

        // check permissions
        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
            // simple unit tests will have runlevel 1 and no CmsObject
            OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
        }

        // un-freeze
        m_frozen = false;

        // create a new map containing all existing sites without the one to remove
        Map<CmsSiteMatcher, CmsSite> siteMatcherSites = new HashMap<CmsSiteMatcher, CmsSite>();
        List<CmsSiteMatcher> matchersForSite = site.getAllMatchers();
        for (Map.Entry<CmsSiteMatcher, CmsSite> entry : m_siteMatcherSites.entrySet()) {
            if (!(matchersForSite.contains(entry.getKey()))) {
                // entry not the site itself nor an alias of the site nor the secure URL of the site, so add it
                siteMatcherSites.put(entry.getKey(), entry.getValue());
            }
        }
        setSiteMatcherSites(siteMatcherSites);

        // remove the site from the map holding the site roots as keys and the sites as values
        Map<String, CmsSite> siteRootSites = new HashMap<String, CmsSite>(m_siteRootSites);
        siteRootSites.remove(site.getSiteRoot());
        m_siteRootSites = Collections.unmodifiableMap(siteRootSites);

        // re-initialize, will freeze the state when finished
        initialize(cms);
        OpenCms.writeConfiguration(CmsSitesConfiguration.class);
    }
838132
public List<CmsAlias> readAliasesBySite(CmsDbContext dbc, CmsProject currentProject, String siteRoot)
    throws CmsException {

        return getVfsDriver(dbc).readAliases(dbc, currentProject, new CmsAliasFilter(siteRoot, null, null));
    }
649412
private boolean isAllowedUser(CmsUser user) throws CmsException {

        if (user.getOuFqn().startsWith(m_cms.getRequestContext().getOuFqn())) {
            return true;
        }
        return OpenCms.getRoleManager().getRolesOfUser(m_cms, user.getName(), m_ou, true, true, false).size() > 0;
    }
871688
public boolean isPotentialGroupHead() {

        CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(m_primaryResource.getRootPath());
        if (site == null) {
            return false;
        }
        Locale mainLocale = site.getMainTranslationLocale(null);
        if (mainLocale == null) {
            return false;
        }
        Locale primaryLocale = getMainLocale();
        return mainLocale.equals(primaryLocale);

    }
1024633
public CmsToolRootHandler getCurrentRoot(CmsWorkplace wp) {

        CmsToolUserData userData = getUserData(wp);
        String root = ROOTKEY_DEFAULT;
        if (userData != null) {
            if (m_roots.getObject(userData.getRootKey()) != null) {
                root = userData.getRootKey();
            } else {
                if (LOG.isErrorEnabled()) {
                    LOG.error(
                        Messages.get().getBundle().key(Messages.ERR_NOT_CONFIGURED_ROOT_1, userData.getRootKey()));
                }
            }
        }
        return m_roots.getObject(root);
    }
555816
public boolean isSiteRoot(String rootPath) {

        String siteRoot = getSiteRoot(rootPath);
        rootPath = CmsStringUtil.joinPaths(rootPath, "/");
        return rootPath.equals(siteRoot);

    }