Search in sources :

Example 6 with RMCoreAllPermission

use of org.ow2.proactive.permissions.RMCoreAllPermission in project scheduling by ow2-proactive.

the class CommonRest method getLogLevel.

@Override
public String getLogLevel(String sessionId, String name) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    try {
        checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        Logger loggerInstance;
        if (name == null) {
            loggerInstance = Logger.getRootLogger();
        } else {
            loggerInstance = Logger.getLogger(name);
        }
        if (loggerInstance == null) {
            throw new RestException("No logger found with name " + name);
        }
        return loggerInstance.getEffectiveLevel().toString();
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger)

Example 7 with RMCoreAllPermission

use of org.ow2.proactive.permissions.RMCoreAllPermission in project scheduling by ow2-proactive.

the class CommonRest method setLogLevelMultiple.

@Override
public boolean setLogLevelMultiple(String sessionId, Map<String, String> loggersConfiguration) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    boolean levelChanged = false;
    try {
        try {
            checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        } catch (PermissionException e) {
            checkPermission(scheduler.getSubject(), new NSAdminPermission(), "Resource Manager administrative rights is required");
        }
        if (loggersConfiguration != null) {
            for (Map.Entry<String, String> entry : loggersConfiguration.entrySet()) {
                Logger loggerInstance;
                String name = entry.getKey();
                String level = entry.getValue();
                if (name == null) {
                    loggerInstance = Logger.getRootLogger();
                } else {
                    loggerInstance = Logger.getLogger(name);
                }
                if (loggerInstance == null) {
                    throw new RestException("No logger found with name " + name);
                }
                Level levelInstance = Level.toLevel(level, Level.INFO);
                Level effectiveLevel = loggerInstance.getEffectiveLevel();
                if (levelInstance.toInt() != effectiveLevel.toInt()) {
                    logger.info("Changing logger " + name + " to " + levelInstance.toString());
                    levelChanged = true;
                } else {
                    logger.debug("Logger " + name + " is already on level " + levelInstance.toString());
                }
                loggerInstance.setLevel(levelInstance);
            }
        }
        return levelChanged;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Level(org.apache.log4j.Level)

Example 8 with RMCoreAllPermission

use of org.ow2.proactive.permissions.RMCoreAllPermission in project scheduling by ow2-proactive.

the class CommonRest method getCurrentLoggers.

@Override
public Map<String, String> getCurrentLoggers(String sessionId) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    try {
        try {
            checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        } catch (PermissionException e) {
            checkPermission(scheduler.getSubject(), new NSAdminPermission(), "Resource Manager administrative rights is required");
        }
        Map<String, String> loggers = new LinkedHashMap<>();
        Enumeration loggerEnumeration = LogManager.getCurrentLoggers();
        while (loggerEnumeration.hasMoreElements()) {
            Object loggerObject = loggerEnumeration.nextElement();
            if (loggerObject != null && loggerObject instanceof Logger) {
                Logger loggerInstance = (Logger) loggerObject;
                if (loggerInstance.getName() != null && loggerInstance.getLevel() != null) {
                    loggers.put(loggerInstance.getName(), loggerInstance.getLevel().toString());
                }
            }
        }
        return loggers;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)

Example 9 with RMCoreAllPermission

use of org.ow2.proactive.permissions.RMCoreAllPermission in project scheduling by ow2-proactive.

the class CommonRest method setLogLevel.

@Override
public boolean setLogLevel(String sessionId, String name, String level) throws RestException {
    Scheduler scheduler = checkAccess(sessionId);
    boolean levelChanged;
    try {
        checkPermission(scheduler.getSubject(), new RMCoreAllPermission(), "Resource Manager administrative rights is required");
        Logger loggerInstance;
        if (name == null) {
            loggerInstance = Logger.getRootLogger();
        } else {
            loggerInstance = Logger.getLogger(name);
        }
        if (loggerInstance == null) {
            throw new RestException("No logger found with name " + name);
        }
        Level levelInstance = Level.toLevel(level, Level.INFO);
        Level effectiveLevel = loggerInstance.getEffectiveLevel();
        if (levelInstance.toInt() != effectiveLevel.toInt()) {
            logger.info("Changing logger " + name + " to " + levelInstance.toString());
            levelChanged = true;
        } else {
            logger.warn("Logger " + name + " is already on level " + levelInstance.toString());
            levelChanged = false;
        }
        loggerInstance.setLevel(levelInstance);
        return levelChanged;
    } catch (PermissionException e) {
        throw new PermissionRestException("Resource Manager administrative rights is required");
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(YOU_ARE_NOT_CONNECTED_TO_THE_SCHEDULER_YOU_SHOULD_LOG_ON_FIRST);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Level(org.apache.log4j.Level) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Logger(org.apache.log4j.Logger)

Example 10 with RMCoreAllPermission

use of org.ow2.proactive.permissions.RMCoreAllPermission in project scheduling by ow2-proactive.

the class RMCore method checkNodeAdminPermission.

/**
 * Checks if the client is the node source admin.
 *
 * @param nodeSource is a nodeSource to be checked
 * @param client is a client to be checked
 * @return true if the client is an admin, SecurityException otherwise
 */
private boolean checkNodeAdminPermission(NodeSource nodeSource, Client client) {
    String errorMessage = client.getName() + " is not authorized to manage node source " + nodeSource.getName();
    // checking if the caller is an administrator
    client.checkPermission(nodeSource.getAdminPermission(), errorMessage, new RMCoreAllPermission(), new NSAdminPermission());
    return true;
}
Also used : RMCoreAllPermission(org.ow2.proactive.permissions.RMCoreAllPermission) NSAdminPermission(org.ow2.proactive.permissions.NSAdminPermission)

Aggregations

RMCoreAllPermission (org.ow2.proactive.permissions.RMCoreAllPermission)8 NSAdminPermission (org.ow2.proactive.permissions.NSAdminPermission)7 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)5 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)5 Logger (org.apache.log4j.Logger)4 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)4 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)4 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)4 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)4 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)4 RestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException)3 SchedulerRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException)3 Level (org.apache.log4j.Level)2 Node (org.objectweb.proactive.core.node.Node)2 MethodCallPermission (org.ow2.proactive.permissions.MethodCallPermission)2 RMNodeSourceEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeSourceEvent)2 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)2 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Permission (java.security.Permission)1