From 27ae06775881e7e8deaaa135ab2cd103dd3efe99 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 20 May 2016 08:41:47 +0200 Subject: [PATCH] Some clean code refactorings Signed-off-by: SirWayne --- .../hawkbit/api/DefaultProtocolProperties.java | 2 +- .../hawkbit/security/SystemSecurityContext.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java index 9d053104c..07eac8db1 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java @@ -76,4 +76,4 @@ public class DefaultProtocolProperties implements ProtocolProperties { public void setPort(final String port) { this.port = port; } -} \ No newline at end of file +} diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java index f849eb541..abe921473 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java @@ -29,12 +29,12 @@ import org.springframework.stereotype.Service; import com.google.common.base.Throwables; /** - * + * A Service which provide to run system code. */ @Service public class SystemSecurityContext { - private static final Logger logger = LoggerFactory.getLogger(SystemSecurityContext.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SystemSecurityContext.class); private final TenantAware tenantAware; @@ -67,19 +67,20 @@ public class SystemSecurityContext { public T runAsSystem(final Callable callable) { final SecurityContext oldContext = SecurityContextHolder.getContext(); try { - logger.debug("entering system code execution"); + LOGGER.debug("entering system code execution"); return tenantAware.runAsTenant(tenantAware.getCurrentTenant(), () -> { try { setSystemContext(); return callable.call(); - } catch (final Exception e) { + // The callable API throws a Exception ant to specific + } catch (@SuppressWarnings("squid:S2221") final Exception e) { throw Throwables.propagate(e); } }); } finally { SecurityContextHolder.setContext(oldContext); - logger.debug("leaving system code execution"); + LOGGER.debug("leaving system code execution"); } } @@ -97,6 +98,9 @@ public class SystemSecurityContext { SecurityContextHolder.setContext(securityContextImpl); } + /** + * Authentication with the system role. + */ public static class SystemCodeAuthentication implements Authentication { private static final long serialVersionUID = 1L;