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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations