From 56ec1b4b05775e0dec27cc5c3a2ed6176d39a9d9 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Mon, 20 Apr 2009 01:01:34 +0000 Subject: [PATCH] Tidying beforeInvocation method. --- .../AbstractSecurityInterceptor.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/springframework/security/access/intercept/AbstractSecurityInterceptor.java b/core/src/main/java/org/springframework/security/access/intercept/AbstractSecurityInterceptor.java index 32b7def514..4223af5fc0 100644 --- a/core/src/main/java/org/springframework/security/access/intercept/AbstractSecurityInterceptor.java +++ b/core/src/main/java/org/springframework/security/access/intercept/AbstractSecurityInterceptor.java @@ -160,6 +160,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, A protected InterceptorStatusToken beforeInvocation(Object object) { Assert.notNull(object, "Object was null"); + final boolean debug = logger.isDebugEnabled(); if (!getSecureObjectClass().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException("Security invocation attempted for object " @@ -178,7 +179,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, A + "rejectPublicInvocations property is set to 'true'"); } - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("Public object - authentication not attempted"); } @@ -187,7 +188,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, A return null; // no further work post-invocation } - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("Secure object: " + object + "; Attributes: " + attributes); } @@ -203,38 +204,36 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, A this.accessDecisionManager.decide(authenticated, object, attributes); } catch (AccessDeniedException accessDeniedException) { - AuthorizationFailureEvent event = new AuthorizationFailureEvent(object, attributes, authenticated, - accessDeniedException); - publishEvent(event); + publishEvent(new AuthorizationFailureEvent(object, attributes, authenticated, + accessDeniedException)); throw accessDeniedException; } - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("Authorization successful"); } - AuthorizedEvent event = new AuthorizedEvent(object, attributes, authenticated); - publishEvent(event); + publishEvent(new AuthorizedEvent(object, attributes, authenticated)); // Attempt to run as a different user Authentication runAs = this.runAsManager.buildRunAs(authenticated, object, attributes); if (runAs == null) { - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("RunAsManager did not change Authentication object"); } // no further work post-invocation return new InterceptorStatusToken(authenticated, false, attributes, object); } else { - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("Switching to RunAs Authentication: " + runAs); } SecurityContextHolder.getContext().setAuthentication(runAs); - // revert to token.Authenticated post-invocation + // need to revert to token.Authenticated post-invocation return new InterceptorStatusToken(authenticated, true, attributes, object); } } @@ -279,7 +278,6 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean, A return returnedObject; } - /** * Checks the current authentication token and passes it to the AuthenticationManager if * {@link org.springframework.security.core.Authentication#isAuthenticated()} returns false or the property