Checks whether the workplace is accessed through the workplace server, and sends an error message otherwise.<p>

@param request the request to check
@param cms the CmsObject to use
325071
public void checkWorkplaceRequest(HttpServletRequest request, CmsObject cms) {

        try {
            if ((OpenCms.getSiteManager().getSites().size() > 1)
                && !OpenCms.getSiteManager().isWorkplaceRequest(request)) {
                // this is a multi site-configuration, but not a request to the configured Workplace site

                CmsUser user = cms.getRequestContext().getCurrentUser();
                // to limit the number of times broadcast is called for a user, we use an expiring cache
                // with the user name as  key
                if (null == m_workplaceServerUserChecks.getIfPresent(user.getName())) {
                    m_workplaceServerUserChecks.put(user.getName(), "");
                    OpenCms.getSessionManager().sendBroadcast(
                        null,
                        Messages.get().getBundle(getWorkplaceLocale(cms)).key(
                            Messages.ERR_WORKPLACE_SERVER_CHECK_FAILED_0),
                        user);

                }

            }
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
807110
@Restricted(DoNotUse.class)
    public HttpResponse doConnectionStatus(StaplerRequest request) {
        try {
            String siteId = request.getParameter("siteId");
            if (siteId == null) {
                siteId = ID_DEFAULT;
            } else if (siteId.equals("default")) {
                // If the request explicitly requires the default ID, ship it
                siteId = ID_DEFAULT;
            }
            ConnectionCheckJob checkJob = getConnectionCheckJob(siteId);
            if (checkJob == null) {
                UpdateSite site = getSite(siteId);
                if (site != null) {
                    checkJob = addConnectionCheckJob(site);
                }
            }
            if (checkJob != null) {
                boolean isOffline = false;
                for (ConnectionStatus status : checkJob.connectionStates.values()) {
                    if(ConnectionStatus.FAILED.equals(status)) {
                        isOffline = true;
                        break;
                    }
                }
                if (isOffline) {
                    // retry connection states if determined to be offline
                    checkJob.run();
                    isOffline = false;
                    for (ConnectionStatus status : checkJob.connectionStates.values()) {
                        if(ConnectionStatus.FAILED.equals(status)) {
                            isOffline = true;
                            break;
                        }
                    }
                    if(!isOffline) { // also need to download the metadata
                        updateAllSites();
                    }
                }
                return HttpResponses.okJSON(checkJob.connectionStates);
            } else {
                return HttpResponses.errorJSON(String.format("Cannot check connection status of the update site with ID='%s'"
                        + ". This update center cannot be resolved", siteId));
            }
        } catch (Exception e) {
            return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage()));
        }
    }
1280108
public static void logLoginException(
        CmsRequestContext requestContext,
        String userName,
        CmsException currentLoginException) {

        if (currentLoginException instanceof CmsAuthentificationException) {

            // the authentication of the user failed
            if (org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_2 == currentLoginException.getMessageContainer().getKey()) {

                // the user has been disabled
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_DISABLED_3,
                        userName,
                        requestContext.addSiteRoot(requestContext.getUri()),
                        requestContext.getRemoteAddress()));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_TEMP_DISABLED_4 == currentLoginException.getMessageContainer().getKey()) {

                // the user has been disabled
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_TEMP_DISABLED_5,
                        new Object[] {
                            userName,
                            requestContext.addSiteRoot(requestContext.getUri()),
                            requestContext.getRemoteAddress(),
                            currentLoginException.getMessageContainer().getArgs()[2],
                            currentLoginException.getMessageContainer().getArgs()[3]}));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_NO_USER_2 == currentLoginException.getMessageContainer().getKey()) {

                // the requested user does not exist in the database
                LOG.warn(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_NO_USER_3,
                        userName,
                        requestContext.addSiteRoot(requestContext.getUri()),
                        requestContext.getRemoteAddress()));

            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_WITH_MESSAGE_1 == currentLoginException.getMessageContainer().getKey()) {

                // logins have been disabled by the administration
                long endTime = CmsLoginMessage.DEFAULT_TIME_END;
                if (OpenCms.getLoginManager().getLoginMessage() != null) {
                    endTime = OpenCms.getLoginManager().getLoginMessage().getTimeEnd();
                }
                LOG.info(
                    Messages.get().getBundle().key(
                        Messages.LOG_LOGIN_FAILED_WITH_MESSAGE_4,
                        new Object[] {
                            userName,
                            requestContext.addSiteRoot(requestContext.getUri()),
                            requestContext.getRemoteAddress(),
                            new Date(endTime)}));

            } else {

                // the user exists, so the password must have been wrong
                CmsMessageContainer message = Messages.get().container(
                    Messages.LOG_LOGIN_FAILED_3,
                    userName,
                    requestContext.addSiteRoot(requestContext.getUri()),
                    requestContext.getRemoteAddress());
                if (OpenCms.getDefaultUsers().isUserAdmin(userName)) {
                    // someone tried to log in as "Admin", log this in a higher channel
                    LOG.error(message.key());
                } else {
                    LOG.warn(message.key());
                }
            }
        } else {
            // the error was database related, there may be an issue with the setup
            // write the exception to the log as well
            LOG.error(
                Messages.get().getBundle().key(
                    Messages.LOG_LOGIN_FAILED_DB_REASON_3,
                    userName,
                    requestContext.addSiteRoot(requestContext.getUri()),
                    requestContext.getRemoteAddress()),
                currentLoginException);
        }
    }
855830
protected CmsObject registerSession(HttpServletRequest request, CmsObject cms) throws CmsException {

        if (!cms.getRequestContext().getCurrentUser().isGuestUser()) {
            // make sure we have a new session after login for security reasons
            HttpSession session = request.getSession(false);
            if (session != null) {
                session.invalidate();
            }
            session = request.getSession(true);
        }

        // update the request context
        cms = OpenCmsCore.getInstance().updateContext(request, cms);

        CmsUser user = cms.getRequestContext().getCurrentUser();
        if (!user.isGuestUser() && !OpenCms.getDefaultUsers().isUserExport(user.getName())) {
            // create the session info object, only for 'real' users
            CmsSessionInfo sessionInfo = new CmsSessionInfo(
                cms.getRequestContext(),
                new CmsUUID(),
                request.getSession().getMaxInactiveInterval());
            // register the updated cms object in the session manager
            OpenCmsCore.getInstance().getSessionManager().addSessionInfo(sessionInfo);
        }
        // return the updated cms object
        return cms;
    }
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());
    }
526283
private void checkEditResourceNotSet() throws CmsUgcException {

        if (m_editResource != null) {
            String message = Messages.get().container(Messages.ERR_CANT_EDIT_MULTIPLE_CONTENTS_IN_SESSION_0).key(
                getCmsObject().getRequestContext().getLocale());
            throw new CmsUgcException(CmsUgcConstants.ErrorCode.errInvalidAction, message);

        }
    }
718050
private void initWorkplaceCmsContext(CmsWorkplaceSettings settings, CmsObject cms) {

        CmsRequestContext reqCont = cms.getRequestContext();

        // check project setting
        if (!settings.getProject().equals(reqCont.getCurrentProject().getUuid())) {
            try {
                reqCont.setCurrentProject(cms.readProject(settings.getProject()));
            } catch (CmsDbEntryNotFoundException e) {
                try {
                    // project not found, set current project and settings to online project
                    reqCont.setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                    settings.setProject(CmsProject.ONLINE_PROJECT_ID);
                } catch (CmsException ex) {
                    // log error
                    if (LOG.isInfoEnabled()) {
                        LOG.info(ex.getLocalizedMessage());
                    }
                }
            } catch (CmsException e1) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(e1.getLocalizedMessage());
                }
            }
        }

        // check site setting
        if (!(settings.getSite().equals(reqCont.getSiteRoot()))) {
            // site was switched, set new site root
            reqCont.setSiteRoot(settings.getSite());
            // removed setting explorer resource to "/" to get the stored folder
        }
    }
564709
public static void checkCreateContent(CmsObject cms, CmsUgcConfiguration config) throws CmsUgcException {

        if (config.getMaxContentNumber().isPresent()) {
            int maxContents = config.getMaxContentNumber().get().intValue();
            String sitePath = cms.getSitePath(config.getContentParentFolder());
            try {
                if (cms.getFilesInFolder(sitePath).size() >= maxContents) {

                    String message = Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                        Messages.ERR_TOO_MANY_CONTENTS_1,
                        config.getContentParentFolder());
                    throw new CmsUgcException(CmsUgcConstants.ErrorCode.errMaxContentsExceeded, message);
                }
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
                throw new CmsUgcException(e);
            }
        }
    }
797790
protected void validate(final CmsEntity entity) {

        if (!m_validating) {
            m_validating = true;
            m_contentService.validateEntity(entity, new AsyncCallback<CmsValidationResult>() {

                public void onFailure(Throwable caught) {

                    // can be ignored
                }

                public void onSuccess(CmsValidationResult result) {

                    displayValidation(entity.getId(), result);
                }
            });
        }
    }
1165574
public boolean isAsyncStarted(ServletRequest request) {

        if (isAsyncStartedMethod != null) {
            try {
                return (Boolean) isAsyncStartedMethod.invoke(request);
            } catch (IllegalAccessException e) {
                ServletLogger.LOG.error(e);
                return false;
            } catch (InvocationTargetException e) {
                ServletLogger.LOG.error(e);
                return false;
            }
        } else {
            return false;
        }
    }
1213422
public boolean isEditable(CmsObject cms, CmsResource resource) {

        if (!cms.getRequestContext().getCurrentProject().isOnlineProject()
            && OpenCms.getRoleManager().hasRole(cms, CmsRole.ROOT_ADMIN)) {
            return true;
        }
        // determine if this resource type is editable for the current user
        CmsPermissionSet permissions = getAccess().getPermissions(cms, resource);
        return permissions.requiresWritePermission();
    }
278139
@Override
  public boolean service(RequestBaratine request)
  {
    /*
    try {
      _service.open((WebRequest) request);
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }
    */

    ServiceWebSocket<T, S> service = _factory.apply(request);

    WebSocketManager wsManager = request.webApp().wsManager();
    WebSocketBaratineImpl<T,S> ws
      = new WebSocketBaratineImpl<>(wsManager, service, _type);
    
    try {
      if (ws.handshake(request)) {
        return true;
      }
      else {
        log.fine("WebSocket handshake failed for " + request);
        return false;
      }
    } catch (Throwable e) {
      log.log(Level.WARNING, e.toString(), e);
      e.printStackTrace();
      
      request.fail(e);
      
      return true;
    }
    //request.flush();
  }
165103
private boolean run(I_CmsReport report, Collection<CmsSite> sites, Collection<String> workplaceUrls) {

        try {
            DomainGrouping domainGrouping = computeDomainGrouping(sites, workplaceUrls);
            if (domainGrouping.isEmpty()) {
                report.println(
                    org.opencms.ui.apps.Messages.get().container(
                        org.opencms.ui.apps.Messages.RPT_LETSENCRYPT_NO_DOMAINS_0));
                return false;
            }
            String certConfig = domainGrouping.generateCertJson();
            if (!m_configUpdater.update(certConfig)) {
                report.println(
                    org.opencms.ui.apps.Messages.get().container(
                        org.opencms.ui.apps.Messages.RPT_LETSENCRYPT_UPDATE_FAILED_0),
                    I_CmsReport.FORMAT_WARNING);
                return false;
            }
            return true;
        } catch (Exception e) {
            report.println(e);
            return false;
        }
    }
691165
public static CmsWorkplaceSettings initSiteAndProject(CmsObject cms) {

        CmsWorkplaceSettings workplaceSettings = CmsWorkplace.initWorkplaceSettings(cms, null, false);
        String startSite = CmsWorkplace.getStartSiteRoot(cms, workplaceSettings);
        // switch to the preferred site
        workplaceSettings.setSite(startSite);
        cms.getRequestContext().setSiteRoot(startSite);
        // store the workplace settings
        CmsUserSettings settings = workplaceSettings.getUserSettings();
        // get the direct edit path

        try {
            CmsProject project = cms.readProject(settings.getStartProject());
            if (OpenCms.getOrgUnitManager().getAllAccessibleProjects(cms, project.getOuFqn(), false).contains(
                project)) {
                // user has access to the project, set this as current project
                workplaceSettings.setProject(project.getUuid());
                cms.getRequestContext().setCurrentProject(project);
            }
        } catch (CmsException e) {
            // unable to set the startup project, bad but not critical
            LOG.warn(
                Messages.get().getBundle().key(
                    Messages.LOG_LOGIN_NO_STARTUP_PROJECT_2,
                    cms.getRequestContext().getCurrentUser().getName(),
                    settings.getStartProject()),
                e);
        }
        return workplaceSettings;
    }
119379
private boolean resourceExists(CmsObject cms, String resource) {

        try {
            cms.readResource(resource, CmsResourceFilter.ALL);
            return true;
        } catch (CmsException e) {
            return false;
        }
    }
130295
public static boolean isStatic(final HttpServletRequest request) {
        final boolean requestStaticResourceChecked = null == request.getAttribute(Keys.HttpRequest.REQUEST_STATIC_RESOURCE_CHECKED)
                ? false
                : (Boolean) request.getAttribute(Keys.HttpRequest.REQUEST_STATIC_RESOURCE_CHECKED);

        if (requestStaticResourceChecked) {
            return (Boolean) request.getAttribute(Keys.HttpRequest.IS_REQUEST_STATIC_RESOURCE);
        }

        if (!inited) {
            init();
        }

        request.setAttribute(Keys.HttpRequest.REQUEST_STATIC_RESOURCE_CHECKED, true);
        request.setAttribute(Keys.HttpRequest.IS_REQUEST_STATIC_RESOURCE, false);

        final String requestURI = request.getRequestURI();

        for (final String pattern : STATIC_RESOURCE_PATHS) {
            if (AntPathMatcher.match(Latkes.getContextPath() + pattern, requestURI)) {
                request.setAttribute(Keys.HttpRequest.IS_REQUEST_STATIC_RESOURCE, true);
                return true;
            }
        }

        return false;
    }
699787
private void validateRequest(CmdbRequest request) throws HygieiaException {
        String busServiceName = request.getConfigurationItemBusServName();
        if(!StringUtils.isEmpty( busServiceName ) && cmdbRepository.findByConfigurationItemAndItemType( busServiceName, APP_TYPE ) == null){
            throw new HygieiaException("Configuration Item " + busServiceName + " does not exist", HygieiaException.BAD_DATA);
        }

        Cmdb cmdb = cmdbRepository.findByConfigurationItemIgnoreCaseOrCommonNameIgnoreCase(request.getConfigurationItem(), request.getCommonName());
        if(cmdb != null){
            throw new HygieiaException("Configuration Item " + cmdb.getConfigurationItem() + " already exists", HygieiaException.DUPLICATE_DATA);
        }

        List<Collector> collectors = collectorRepository.findByCollectorTypeAndName(CollectorType.CMDB, request.getToolName());
        if (CollectionUtils.isEmpty(collectors)) {
            throw new HygieiaException(request.getToolName() + " collector is not available.", HygieiaException.BAD_DATA);
        }
    }