1 package org
.argeo
.security
.core
;
3 import java
.beans
.PropertyDescriptor
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.springframework
.beans
.BeansException
;
8 import org
.springframework
.beans
.PropertyValues
;
9 import org
.springframework
.beans
.factory
.config
.InstantiationAwareBeanPostProcessor
;
10 import org
.springframework
.context
.ApplicationEvent
;
11 import org
.springframework
.context
.ApplicationListener
;
12 import org
.springframework
.context
.event
.ContextRefreshedEvent
;
15 * Executes with a system authentication the instantiation and initialization
16 * methods of the application context where it has been defined.
18 public class AuthenticatedApplicationContextInitialization
extends
19 AbstractSystemExecution
implements InstantiationAwareBeanPostProcessor
,
21 private Log log
= LogFactory
22 .getLog(AuthenticatedApplicationContextInitialization
.class);
24 @SuppressWarnings("rawtypes")
25 public Object
postProcessBeforeInstantiation(Class beanClass
,
26 String beanName
) throws BeansException
{
27 // we authenticate when any beans is instantiated
28 // we will deauthenticate only when the application context has been
29 // refreshed in order to be able to deal with factory beans has well
30 if (!isAuthenticatedBySelf()) {
31 authenticateAsSystem();
32 if (log
.isDebugEnabled())
33 log
.debug("Application context initialization authenticated for thread "
34 + Thread
.currentThread().getName());
39 public boolean postProcessAfterInstantiation(Object bean
, String beanName
)
40 throws BeansException
{
44 public PropertyValues
postProcessPropertyValues(PropertyValues pvs
,
45 PropertyDescriptor
[] pds
, Object bean
, String beanName
)
46 throws BeansException
{
50 public Object
postProcessBeforeInitialization(Object bean
, String beanName
)
51 throws BeansException
{
52 // authenticateAsSystem();
56 public Object
postProcessAfterInitialization(Object bean
, String beanName
)
57 throws BeansException
{
58 // NOTE: in case there was an exception in on the initialization method
59 // we expect the underlying thread to die and thus the system
60 // authentication to be lost. We have currently no way to catch the
61 // exception and perform the deauthentication by ourselves.
62 // deauthenticateAsSystem();
66 public void onApplicationEvent(ApplicationEvent event
) {
67 if (event
instanceof ContextRefreshedEvent
) {
68 // make sure that we have deauthenticated after the application
69 // context was initialized/refreshed
70 deauthenticateAsSystem();
71 if (log
.isDebugEnabled())
72 log
.debug("Application context initialization deauthenticated for thread "
73 + Thread
.currentThread().getName());