Search in sources :

Example 1 with CmsRoleViolationException

use of org.opencms.security.CmsRoleViolationException in project opencms-core by alkacon.

the class CmsSchedulerList method executeListSingleActions.

/**
 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
 */
@Override
public void executeListSingleActions() throws IOException, ServletException {
    if (getParamListAction().equals(LIST_ACTION_EDIT) || getParamListAction().equals(LIST_DEFACTION_EDIT)) {
        // edit a job from the list
        String jobId = getSelectedItem().getId();
        // forward to the edit job screen with additional parameters
        Map<String, String[]> params = new HashMap<String, String[]>();
        params.put(CmsEditScheduledJobInfoDialog.PARAM_JOBID, new String[] { jobId });
        // set action parameter to initial dialog call
        params.put(CmsDialog.PARAM_ACTION, new String[] { CmsDialog.DIALOG_INITIAL });
        getToolManager().jspForwardTool(this, "/scheduler/edit", params);
    } else if (getParamListAction().equals(LIST_ACTION_COPY)) {
        // copy a job from the list
        String jobId = getSelectedItem().getId();
        // forward to the edit job screen with additional parameters
        Map<String, String[]> params = new HashMap<String, String[]>();
        params.put(CmsEditScheduledJobInfoDialog.PARAM_JOBID, new String[] { jobId });
        // set action parameter to copy job action
        params.put(CmsDialog.PARAM_ACTION, new String[] { CmsEditScheduledJobInfoDialog.DIALOG_COPYJOB });
        getToolManager().jspForwardTool(this, "/scheduler/new", params);
    } else if (getParamListAction().equals(LIST_ACTION_ACTIVATE)) {
        // activate a job from the list
        String jobId = getSelectedItem().getId();
        CmsScheduledJobInfo job = (CmsScheduledJobInfo) OpenCms.getScheduleManager().getJob(jobId).clone();
        job.setActive(true);
        try {
            OpenCms.getScheduleManager().scheduleJob(getCms(), job);
            // update the XML configuration
            writeConfiguration(true);
        } catch (CmsException e) {
            // should never happen
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_SCHEDULE_JOB_1, jobId), e);
        }
    } else if (getParamListAction().equals(LIST_ACTION_DEACTIVATE)) {
        // deactivate a job from the list
        String jobId = getSelectedItem().getId();
        CmsScheduledJobInfo job = (CmsScheduledJobInfo) OpenCms.getScheduleManager().getJob(jobId).clone();
        job.setActive(false);
        try {
            OpenCms.getScheduleManager().scheduleJob(getCms(), job);
            // update the XML configuration
            writeConfiguration(true);
        } catch (CmsException e) {
            // should never happen
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_UNSCHEDULE_JOB_1, jobId), e);
        }
    } else if (getParamListAction().equals(LIST_ACTION_DELETE)) {
        // delete a job from the list
        String jobId = getSelectedItem().getId();
        try {
            OpenCms.getScheduleManager().unscheduleJob(getCms(), jobId);
            // update the XML configuration
            writeConfiguration(false);
        } catch (CmsRoleViolationException e) {
            // should never happen
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_DELETE_JOB_1, jobId), e);
        }
    } else if (getParamListAction().equals(LIST_ACTION_EXECUTE)) {
        String jobId = getSelectedItem().getId();
        CmsScheduleManager scheduler = OpenCms.getScheduleManager();
        scheduler.executeDirectly(jobId);
    } else {
        throwListUnsupportedActionException();
    }
    listSave();
}
Also used : CmsScheduleManager(org.opencms.scheduler.CmsScheduleManager) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) HashMap(java.util.HashMap) CmsException(org.opencms.main.CmsException) CmsRuntimeException(org.opencms.main.CmsRuntimeException) CmsScheduledJobInfo(org.opencms.scheduler.CmsScheduledJobInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with CmsRoleViolationException

use of org.opencms.security.CmsRoleViolationException in project opencms-core by alkacon.

the class CmsExportpointsList method deleteExportpoint.

/**
 * Deletes a module exportpoint from a module.<p>
 *
 * @param module the module to delete the dependency from
 * @param exportpoint the name of the exportpoint to delete
 */
private void deleteExportpoint(CmsModule module, String exportpoint) {
    List oldExportpoints = module.getExportPoints();
    List newExportpoints = new ArrayList();
    Iterator i = oldExportpoints.iterator();
    while (i.hasNext()) {
        CmsExportPoint exp = (CmsExportPoint) i.next();
        if (!exp.getUri().equals(exportpoint)) {
            newExportpoints.add(exp);
        }
    }
    module.setExportPoints(newExportpoints);
    // update the module information
    try {
        OpenCms.getModuleManager().updateModule(getCms(), module);
    } catch (CmsConfigurationException ce) {
        // should never happen
        throw new CmsRuntimeException(Messages.get().container(Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2, exportpoint, module.getName()), ce);
    } catch (CmsRoleViolationException re) {
        throw new CmsRuntimeException(Messages.get().container(Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2, exportpoint, module.getName()), re);
    }
}
Also used : CmsConfigurationException(org.opencms.configuration.CmsConfigurationException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CmsRuntimeException(org.opencms.main.CmsRuntimeException) CmsExportPoint(org.opencms.db.CmsExportPoint) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with CmsRoleViolationException

use of org.opencms.security.CmsRoleViolationException in project opencms-core by alkacon.

the class CmsScheduleManager method initialize.

/**
 * Initializes the OpenCms scheduler.<p>
 *
 * @param adminCms an OpenCms context object that must have been initialized with "Admin" permissions
 *
 * @throws CmsRoleViolationException if the user has insufficient role permissions
 */
public synchronized void initialize(CmsObject adminCms) throws CmsRoleViolationException {
    if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
        // simple unit tests will have runlevel 1 and no CmsObject
        OpenCms.getRoleManager().checkRole(adminCms, CmsRole.WORKPLACE_MANAGER);
    }
    // the list of job entries
    m_jobs = new ArrayList<CmsScheduledJobInfo>();
    // save the admin cms
    m_adminCms = adminCms;
    // Quartz scheduler settings
    Properties properties = new Properties();
    properties.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "OpenCmsScheduler");
    properties.put(StdSchedulerFactory.PROP_SCHED_THREAD_NAME, "OpenCms: Scheduler");
    properties.put(StdSchedulerFactory.PROP_SCHED_RMI_EXPORT, CmsStringUtil.FALSE);
    properties.put(StdSchedulerFactory.PROP_SCHED_RMI_PROXY, CmsStringUtil.FALSE);
    properties.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, CmsSchedulerThreadPool.class.getName());
    properties.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, "org.quartz.simpl.RAMJobStore");
    // this will be required in quartz versions from 1.6, but constants are not supported in earlier versions
    properties.put("org.quartz.scheduler.jmx.export", CmsStringUtil.FALSE);
    properties.put("org.quartz.scheduler.jmx.proxy", CmsStringUtil.FALSE);
    try {
        // initialize the Quartz scheduler
        SchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
        m_scheduler = schedulerFactory.getScheduler();
    } catch (Exception e) {
        LOG.error(Messages.get().getBundle().key(Messages.LOG_NO_SCHEDULER_0), e);
        // can not continue
        m_scheduler = null;
        return;
    }
    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_INITIALIZED_0));
    }
    if (m_configuredJobs != null) {
        // add all jobs from the system configuration
        for (int i = 0; i < m_configuredJobs.size(); i++) {
            try {
                CmsScheduledJobInfo job = m_configuredJobs.get(i);
                scheduleJob(adminCms, job);
            } catch (CmsSchedulerException e) {
            // ignore this job, but keep scheduling the other jobs
            // note: the log is has already been written
            }
        }
    }
    try {
        // start the scheduler
        m_scheduler.start();
    } catch (Exception e) {
        LOG.error(Messages.get().getBundle().key(Messages.LOG_CANNOT_START_SCHEDULER_0), e);
        // can not continue
        m_scheduler = null;
        return;
    }
    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_STARTED_0));
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SCHEDULER_CONFIG_FINISHED_0));
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Properties(java.util.Properties) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) SchedulerException(org.quartz.SchedulerException) CmsIllegalArgumentException(org.opencms.main.CmsIllegalArgumentException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 4 with CmsRoleViolationException

use of org.opencms.security.CmsRoleViolationException in project opencms-core by alkacon.

the class CmsSecurityManager method countLockedResources.

/**
 * Counts the locked resources in this project.<p>
 *
 * @param context the current request context
 * @param id the id of the project
 *
 * @return the amount of locked resources in this project
 *
 * @throws CmsException if something goes wrong
 * @throws CmsRoleViolationException if the current user does not have management access to the project
 */
public int countLockedResources(CmsRequestContext context, CmsUUID id) throws CmsException, CmsRoleViolationException {
    CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
    CmsProject project = null;
    int result = 0;
    try {
        project = m_driverManager.readProject(dbc, id);
        checkManagerOfProjectRole(dbc, project);
        result = m_driverManager.countLockedResources(project);
    } catch (Exception e) {
        dbc.report(null, Messages.get().container(Messages.ERR_COUNT_LOCKED_RESOURCES_PROJECT_2, (project == null) ? "<failed to read>" : project.getName(), id), e);
    } finally {
        dbc.clear();
    }
    return result;
}
Also used : CmsProject(org.opencms.file.CmsProject) CmsVfsException(org.opencms.file.CmsVfsException) CmsInitException(org.opencms.main.CmsInitException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) CmsSecurityException(org.opencms.security.CmsSecurityException) CmsDataAccessException(org.opencms.file.CmsDataAccessException) CmsException(org.opencms.main.CmsException) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) CmsVfsResourceAlreadyExistsException(org.opencms.file.CmsVfsResourceAlreadyExistsException) CmsTooManyPublishResourcesException(org.opencms.ade.publish.CmsTooManyPublishResourcesException) CmsMultiException(org.opencms.main.CmsMultiException) CmsLockException(org.opencms.lock.CmsLockException) SQLException(java.sql.SQLException) CmsIllegalArgumentException(org.opencms.main.CmsIllegalArgumentException) CmsPermissionViolationException(org.opencms.security.CmsPermissionViolationException)

Example 5 with CmsRoleViolationException

use of org.opencms.security.CmsRoleViolationException in project opencms-core by alkacon.

the class CmsSecurityManager method createGroup.

/**
 * Creates a new user group.<p>
 *
 * @param context the current request context
 * @param name the name of the new group
 * @param description the description for the new group
 * @param flags the flags for the new group
 * @param parent the name of the parent group (or <code>null</code>)
 *
 * @return a <code>{@link CmsGroup}</code> object representing the newly created group
 *
 * @throws CmsException if operation was not successful.
 * @throws CmsRoleViolationException if the  role {@link CmsRole#ACCOUNT_MANAGER} is not owned by the current user
 */
public CmsGroup createGroup(CmsRequestContext context, String name, String description, int flags, String parent) throws CmsException, CmsRoleViolationException {
    CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
    CmsGroup result = null;
    try {
        checkRole(dbc, CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParentOrganizationalUnit(name)));
        result = m_driverManager.createGroup(dbc, new CmsUUID(), name, description, flags, parent);
    } catch (Exception e) {
        dbc.report(null, Messages.get().container(Messages.ERR_CREATE_GROUP_1, name), e);
    } finally {
        dbc.clear();
    }
    return result;
}
Also used : CmsGroup(org.opencms.file.CmsGroup) CmsUUID(org.opencms.util.CmsUUID) CmsVfsException(org.opencms.file.CmsVfsException) CmsInitException(org.opencms.main.CmsInitException) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) CmsSecurityException(org.opencms.security.CmsSecurityException) CmsDataAccessException(org.opencms.file.CmsDataAccessException) CmsException(org.opencms.main.CmsException) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) CmsVfsResourceAlreadyExistsException(org.opencms.file.CmsVfsResourceAlreadyExistsException) CmsTooManyPublishResourcesException(org.opencms.ade.publish.CmsTooManyPublishResourcesException) CmsMultiException(org.opencms.main.CmsMultiException) CmsLockException(org.opencms.lock.CmsLockException) SQLException(java.sql.SQLException) CmsIllegalArgumentException(org.opencms.main.CmsIllegalArgumentException) CmsPermissionViolationException(org.opencms.security.CmsPermissionViolationException)

Aggregations

CmsRoleViolationException (org.opencms.security.CmsRoleViolationException)35 CmsSecurityException (org.opencms.security.CmsSecurityException)21 CmsException (org.opencms.main.CmsException)20 CmsIllegalArgumentException (org.opencms.main.CmsIllegalArgumentException)19 CmsVfsResourceNotFoundException (org.opencms.file.CmsVfsResourceNotFoundException)18 CmsLockException (org.opencms.lock.CmsLockException)17 SQLException (java.sql.SQLException)16 CmsTooManyPublishResourcesException (org.opencms.ade.publish.CmsTooManyPublishResourcesException)16 CmsDataAccessException (org.opencms.file.CmsDataAccessException)16 CmsVfsException (org.opencms.file.CmsVfsException)16 CmsVfsResourceAlreadyExistsException (org.opencms.file.CmsVfsResourceAlreadyExistsException)16 CmsInitException (org.opencms.main.CmsInitException)16 CmsMultiException (org.opencms.main.CmsMultiException)16 CmsPermissionViolationException (org.opencms.security.CmsPermissionViolationException)16 CmsConfigurationException (org.opencms.configuration.CmsConfigurationException)8 CmsObject (org.opencms.file.CmsObject)6 CmsProject (org.opencms.file.CmsProject)5 CmsRuntimeException (org.opencms.main.CmsRuntimeException)5 IOException (java.io.IOException)4 Date (java.util.Date)4