From f6349dde10cef37436a217d8cd28e2f8cce0bf2d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 3 Aug 2018 22:14:12 +0200 Subject: [PATCH] [Minor] Logging of exception in StrolchSystemActionWithResult --- .../DefaultStrolchPrivilegeHandler.java | 14 +++++++------- .../runtime/privilege/StrolchSystemAction.java | 2 +- .../privilege/StrolchSystemActionWithResult.java | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java index 4bab812a0..25f69d1b4 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java @@ -1,12 +1,12 @@ /* * Copyright 2013 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -72,11 +72,11 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements * @param privilegeXmlFile * a {@link File} reference to the XML file containing the configuration for Privilege * - * @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and - * {@link PersistenceHandler} are set and initialized as well + * @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and {@link + * PersistenceHandler} are set and initialized as well */ private li.strolch.privilege.handler.PrivilegeHandler initializeFromXml(ComponentConfiguration configuration, - File privilegeXmlFile) { + File privilegeXmlFile) { // make sure file exists if (!privilegeXmlFile.exists()) { @@ -132,7 +132,7 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements } return certificate; } - + @Override public Certificate authenticateSingleSignOn(Object data) { assertContainerStarted(); diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemAction.java b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemAction.java index d73b779d2..b425abdec 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemAction.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemAction.java @@ -14,7 +14,7 @@ public class StrolchSystemAction extends SystemAction { public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class); - private PrivilegedRunnable runnable; + private final PrivilegedRunnable runnable; public StrolchSystemAction(PrivilegedRunnable runnable) { this.runnable = runnable; diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemActionWithResult.java b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemActionWithResult.java index e5c99f99e..574645ee2 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemActionWithResult.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/privilege/StrolchSystemActionWithResult.java @@ -3,16 +3,20 @@ package li.strolch.runtime.privilege; import li.strolch.privilege.handler.SystemAction; import li.strolch.privilege.handler.SystemActionWithResult; import li.strolch.privilege.model.PrivilegeContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * {@link SystemAction} to run {@link PrivilegedRunnableWithResult} as a system user - * - * @author Robert von Burg * * @param + * + * @author Robert von Burg */ public class StrolchSystemActionWithResult extends SystemActionWithResult { + public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class); + private PrivilegedRunnableWithResult runnable; public StrolchSystemActionWithResult(PrivilegedRunnableWithResult runnable) { @@ -21,6 +25,12 @@ public class StrolchSystemActionWithResult extends SystemActionWithResult @Override public T execute(PrivilegeContext privilegeContext) { - return this.runnable.run(privilegeContext); + try { + return this.runnable.run(privilegeContext); + } catch (Exception e) { + logger.error("Failed to execute SystemAction for " + privilegeContext.getUsername() + " due to " + e + .getMessage(), e); + throw e; + } } }