Converted ApplicationContextAware classes to ApplicationEventPublisherAware (SEC-69).
This commit is contained in:
parent
6511677f93
commit
0aef31d302
|
@ -35,11 +35,10 @@ import net.sf.acegisecurity.runas.NullRunAsManager;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -51,7 +50,7 @@ import java.util.Set;
|
|||
/**
|
||||
* Abstract class that implements security interception for secure objects.
|
||||
*
|
||||
* <P>
|
||||
* <p>
|
||||
* The <code>AbstractSecurityInterceptor</code> will ensure the proper startup
|
||||
* configuration of the security interceptor. It will also implement the
|
||||
* proper handling of secure object invocations, being:
|
||||
|
@ -138,7 +137,7 @@ import java.util.Set;
|
|||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
||||
ApplicationContextAware {
|
||||
ApplicationEventPublisherAware {
|
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
protected static final Log logger = LogFactory.getLog(AbstractSecurityInterceptor.class);
|
||||
|
@ -147,7 +146,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
|
||||
private AccessDecisionManager accessDecisionManager;
|
||||
private AfterInvocationManager afterInvocationManager;
|
||||
private ApplicationContext context;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private AuthenticationManager authenticationManager;
|
||||
private RunAsManager runAsManager = new NullRunAsManager();
|
||||
private boolean alwaysReauthenticate = false;
|
||||
|
@ -185,9 +184,8 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
return alwaysReauthenticate;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.context = applicationContext;
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -416,7 +414,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
} catch (AccessDeniedException accessDeniedException) {
|
||||
AuthorizationFailureEvent event = new AuthorizationFailureEvent(object,
|
||||
attr, authenticated, accessDeniedException);
|
||||
this.context.publishEvent(event);
|
||||
this.eventPublisher.publishEvent(event);
|
||||
|
||||
throw accessDeniedException;
|
||||
}
|
||||
|
@ -427,7 +425,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
|
||||
AuthorizedEvent event = new AuthorizedEvent(object, attr,
|
||||
authenticated);
|
||||
this.context.publishEvent(event);
|
||||
this.eventPublisher.publishEvent(event);
|
||||
|
||||
// Attempt to run as a different user
|
||||
Authentication runAs = this.runAsManager.buildRunAs(authenticated,
|
||||
|
@ -457,7 +455,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
logger.debug("Public object - authentication not attempted");
|
||||
}
|
||||
|
||||
this.context.publishEvent(new PublicInvocationEvent(object));
|
||||
this.eventPublisher.publishEvent(new PublicInvocationEvent(object));
|
||||
|
||||
return null; // no further work post-invocation
|
||||
}
|
||||
|
@ -467,7 +465,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
* Helper method which generates an exception containing the passed reason,
|
||||
* and publishes an event to the application context.
|
||||
*
|
||||
* <P>
|
||||
* <p>
|
||||
* Always throws an exception.
|
||||
* </p>
|
||||
*
|
||||
|
@ -481,7 +479,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
|||
|
||||
AuthenticationCredentialsNotFoundEvent event = new AuthenticationCredentialsNotFoundEvent(secureObject,
|
||||
configAttribs, exception);
|
||||
this.context.publishEvent(event);
|
||||
this.eventPublisher.publishEvent(event);
|
||||
|
||||
throw exception;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,12 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -131,8 +134,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractProcessingFilter implements Filter,
|
||||
InitializingBean, ApplicationContextAware {
|
||||
//~ Static fields/initializers =============================================
|
||||
InitializingBean, ApplicationEventPublisherAware {
|
||||
//~ Static fields/initializersApplicationContextAware =============================================
|
||||
|
||||
public static final String ACEGI_SECURITY_TARGET_URL_KEY = "ACEGI_SECURITY_TARGET_URL";
|
||||
public static final String ACEGI_SECURITY_LAST_EXCEPTION_KEY = "ACEGI_SECURITY_LAST_EXCEPTION";
|
||||
|
@ -140,7 +143,7 @@ public abstract class AbstractProcessingFilter implements Filter,
|
|||
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private ApplicationContext context;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private AuthenticationManager authenticationManager;
|
||||
private Properties exceptionMappings = new Properties();
|
||||
private RememberMeServices rememberMeServices = new NullRememberMeServices();
|
||||
|
@ -185,8 +188,8 @@ public abstract class AbstractProcessingFilter implements Filter,
|
|||
return alwaysUseDefaultTargetUrl;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext context) {
|
||||
this.context = context;
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
public void setContinueChainBeforeSuccessfulAuthentication(
|
||||
|
@ -421,8 +424,8 @@ public abstract class AbstractProcessingFilter implements Filter,
|
|||
rememberMeServices.loginSuccess(request, response, authResult);
|
||||
|
||||
// Fire event
|
||||
if (this.context != null) {
|
||||
context.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
if (this.eventPublisher != null) {
|
||||
eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
authResult, this.getClass()));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -75,20 +75,20 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* @version $Id$
|
||||
*/
|
||||
public class RememberMeProcessingFilter implements Filter, InitializingBean,
|
||||
ApplicationContextAware {
|
||||
ApplicationEventPublisherAware {
|
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(RememberMeProcessingFilter.class);
|
||||
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private ApplicationContext context;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private RememberMeServices rememberMeServices = new NullRememberMeServices();
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setApplicationContext(ApplicationContext context) {
|
||||
this.context = context;
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
public void setRememberMeServices(RememberMeServices rememberMeServices) {
|
||||
|
@ -136,8 +136,8 @@ public class RememberMeProcessingFilter implements Filter, InitializingBean,
|
|||
}
|
||||
|
||||
// Fire event
|
||||
if (this.context != null) {
|
||||
context.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
if (this.eventPublisher != null) {
|
||||
eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
SecurityContextHolder.getContext().getAuthentication(),
|
||||
this.getClass()));
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -110,7 +110,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* @see net.sf.acegisecurity.ui.switchuser.SwitchUserGrantedAuthority
|
||||
*/
|
||||
public class SwitchUserProcessingFilter implements Filter, InitializingBean,
|
||||
ApplicationContextAware {
|
||||
ApplicationEventPublisherAware {
|
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SwitchUserProcessingFilter.class);
|
||||
|
@ -122,7 +122,7 @@ public class SwitchUserProcessingFilter implements Filter, InitializingBean,
|
|||
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private ApplicationContext context;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
// ~ Instance fields
|
||||
// ========================================================
|
||||
|
@ -133,9 +133,9 @@ public class SwitchUserProcessingFilter implements Filter, InitializingBean,
|
|||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setApplicationContext(ApplicationContext context)
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
|
||||
throws BeansException {
|
||||
this.context = context;
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,8 +267,8 @@ public class SwitchUserProcessingFilter implements Filter, InitializingBean,
|
|||
}
|
||||
|
||||
// publish event
|
||||
if (this.context != null) {
|
||||
context.publishEvent(new AuthenticationSwitchUserEvent(current,
|
||||
if (this.eventPublisher != null) {
|
||||
eventPublisher.publishEvent(new AuthenticationSwitchUserEvent(current,
|
||||
originalUser));
|
||||
}
|
||||
|
||||
|
@ -337,8 +337,8 @@ public class SwitchUserProcessingFilter implements Filter, InitializingBean,
|
|||
}
|
||||
|
||||
// publish event
|
||||
if (this.context != null) {
|
||||
context.publishEvent(new AuthenticationSwitchUserEvent(
|
||||
if (this.eventPublisher != null) {
|
||||
eventPublisher.publishEvent(new AuthenticationSwitchUserEvent(
|
||||
SecurityContextHolder.getContext().getAuthentication(),
|
||||
targetUser));
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -76,20 +76,20 @@ import javax.servlet.http.HttpServletResponse;
|
|||
* @version $Id$
|
||||
*/
|
||||
public class X509ProcessingFilter implements Filter, InitializingBean,
|
||||
ApplicationContextAware {
|
||||
ApplicationEventPublisherAware {
|
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(X509ProcessingFilter.class);
|
||||
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private ApplicationContext context;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setApplicationContext(ApplicationContext context) {
|
||||
this.context = context;
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher context) {
|
||||
this.eventPublisher = context;
|
||||
}
|
||||
|
||||
public void setAuthenticationManager(
|
||||
|
@ -187,8 +187,8 @@ public class X509ProcessingFilter implements Filter, InitializingBean,
|
|||
SecurityContextHolder.getContext().setAuthentication(authResult);
|
||||
|
||||
// Fire event
|
||||
if (this.context != null) {
|
||||
context.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
if (this.eventPublisher != null) {
|
||||
eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(
|
||||
authResult, this.getClass()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
|||
public void testCallbackIsInvokedWhenPermissionGranted()
|
||||
throws Exception {
|
||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||
si.setApplicationContext(MockApplicationContext.getContext());
|
||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
|
@ -100,7 +100,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
|||
public void testCallbackIsNotInvokedWhenPermissionDenied()
|
||||
throws Exception {
|
||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||
si.setApplicationContext(MockApplicationContext.getContext());
|
||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
|
|
|
@ -147,7 +147,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
|||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setRunAsManager(new MockRunAsManager());
|
||||
interceptor.setApplicationContext(MockApplicationContext.getContext());
|
||||
interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
|
||||
// Setup a mock config attribute definition
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition();
|
||||
|
@ -199,7 +199,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
|||
* test access denied events as the abstract parent enforces that logic,
|
||||
* which is extensively tested separately.
|
||||
*
|
||||
* @throws Throwable DOCUMENT ME!
|
||||
*/
|
||||
public void testSuccessfulInvocation() throws Throwable {
|
||||
// Setup the FilterSecurityInterceptor
|
||||
|
@ -207,7 +206,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
|||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setRunAsManager(new MockRunAsManager());
|
||||
interceptor.setApplicationContext(MockApplicationContext.getContext());
|
||||
interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
|
||||
// Setup a mock config attribute definition
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition();
|
||||
|
|
Loading…
Reference in New Issue