Search in sources :

Example 31 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class LoggerLogic method readAudit.

@PreAuthorize("hasRole('" + StandardEntitlement.AUDIT_READ + "')")
@Transactional(readOnly = true)
public LoggerTO readAudit(final String name) {
    for (final AuditLoggerName logger : listAudits()) {
        if (logger.toLoggerName().equals(name)) {
            final LoggerTO loggerTO = new LoggerTO();
            loggerTO.setKey(logger.toLoggerName());
            loggerTO.setLevel(LoggerLevel.DEBUG);
            return loggerTO;
        }
    }
    throw new NotFoundException("Logger " + name);
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AuditLoggerName(org.apache.syncope.common.lib.types.AuditLoggerName) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class LoggerLogic method delete.

private LoggerTO delete(final String name, final LoggerType expectedType) {
    Logger syncopeLogger = loggerDAO.find(name);
    if (syncopeLogger == null) {
        throw new NotFoundException("Logger " + name);
    }
    if (expectedType != syncopeLogger.getType()) {
        throwInvalidLogger(expectedType);
    }
    LoggerTO loggerToDelete = new LoggerTO();
    BeanUtils.copyProperties(syncopeLogger, loggerToDelete);
    // remove SyncopeLogger from local storage, so that LoggerLoader won't load this next time
    loggerDAO.delete(syncopeLogger);
    // set log level to OFF in order to disable configured logger until next reboot
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    String auditLoggerName = AuditLoggerName.getAuditEventLoggerName(AuthContextUtils.getDomain(), syncopeLogger.getKey());
    org.apache.logging.log4j.core.Logger logger = SyncopeConstants.ROOT_LOGGER.equals(name) ? ctx.getLogger(LogManager.ROOT_LOGGER_NAME) : LoggerType.AUDIT.equals(syncopeLogger.getType()) ? ctx.getLogger(auditLoggerName) : ctx.getLogger(name);
    logger.setLevel(Level.OFF);
    ctx.updateLoggers();
    return loggerToDelete;
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Logger(org.apache.syncope.core.persistence.api.entity.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 33 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class NotificationLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.NOTIFICATION_UPDATE + "')")
public NotificationTO update(final NotificationTO notificationTO) {
    Notification notification = notificationDAO.find(notificationTO.getKey());
    if (notification == null) {
        LOG.error("Could not find notification '" + notificationTO.getKey() + "'");
        throw new NotFoundException(String.valueOf(notificationTO.getKey()));
    }
    binder.update(notification, notificationTO);
    notification = notificationDAO.save(notification);
    return binder.getNotificationTO(notification);
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 34 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class NotificationLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.NOTIFICATION_DELETE + "')")
public NotificationTO delete(final String key) {
    Notification notification = notificationDAO.find(key);
    if (notification == null) {
        LOG.error("Could not find notification '" + key + "'");
        throw new NotFoundException(String.valueOf(key));
    }
    NotificationTO deleted = binder.getNotificationTO(notification);
    notificationDAO.delete(key);
    return deleted;
}
Also used : NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 35 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class PolicyLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.POLICY_DELETE + "')")
public <T extends PolicyTO> T delete(final PolicyType type, final String key) {
    Policy policy = policyDAO.find(key);
    if (policy == null) {
        throw new NotFoundException("Policy " + key + " not found");
    }
    PolicyUtils policyUtils = policyUtilsFactory.getInstance(policy);
    if (type != null && policyUtils.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + policyUtils.getType());
        throw sce;
    }
    T deleted = binder.getPolicyTO(policy);
    policyDAO.delete(policy);
    return deleted;
}
Also used : Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PolicyUtils(org.apache.syncope.core.persistence.api.entity.policy.PolicyUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)110 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)87 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)41 Transactional (org.springframework.transaction.annotation.Transactional)21 Date (java.util.Date)12 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)10 SchedulerException (org.quartz.SchedulerException)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8 Report (org.apache.syncope.core.persistence.api.entity.Report)8 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)8 User (org.apache.syncope.core.persistence.api.entity.user.User)8 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 StringUtils (org.apache.commons.lang3.StringUtils)6 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)6