All Downloads are FREE. Search and download functionalities are using the official Maven repository.

li.strolch.runtime.privilege.StrolchSystemActionWithResult Maven / Gradle / Ivy

The newest version!
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
 *
 * @param 
 *
 * @author Robert von Burg 
 */
public class StrolchSystemActionWithResult extends SystemActionWithResult {

	public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);

	private final PrivilegedRunnableWithResult runnable;

	public StrolchSystemActionWithResult(PrivilegedRunnableWithResult runnable) {
		this.runnable = runnable;
	}

	@Override
	public T execute(PrivilegeContext privilegeContext) throws Exception {
		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;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy