1 package org
.argeo
.security
.core
;
3 import java
.beans
.PropertyDescriptor
;
5 import org
.springframework
.beans
.BeansException
;
6 import org
.springframework
.beans
.PropertyValues
;
7 import org
.springframework
.beans
.factory
.config
.InstantiationAwareBeanPostProcessor
;
8 import org
.springframework
.context
.ApplicationEvent
;
9 import org
.springframework
.context
.ApplicationListener
;
10 import org
.springframework
.context
.event
.ContextRefreshedEvent
;
13 * Executes with a system authentication the instantiation and initialization
14 * methods of the application context where it has been defined.
16 public class AuthenticatedApplicationContextInitialization
extends
17 AbstractSystemExecution
implements InstantiationAwareBeanPostProcessor
,
19 // private Log log = LogFactory
20 // .getLog(AuthenticatedApplicationContextInitialization.class);
22 @SuppressWarnings("rawtypes")
23 public Object
postProcessBeforeInstantiation(Class beanClass
,
24 String beanName
) throws BeansException
{
25 // we authenticate when any bean is instantiated
26 // we will deauthenticate only when the application context has been
27 // refreshed in order to be able to deal with factory beans has well
28 if (!isAuthenticatedBySelf()) {
29 authenticateAsSystem();
34 public boolean postProcessAfterInstantiation(Object bean
, String beanName
)
35 throws BeansException
{
39 public PropertyValues
postProcessPropertyValues(PropertyValues pvs
,
40 PropertyDescriptor
[] pds
, Object bean
, String beanName
)
41 throws BeansException
{
45 public Object
postProcessBeforeInitialization(Object bean
, String beanName
)
46 throws BeansException
{
47 // authenticateAsSystem();
51 public Object
postProcessAfterInitialization(Object bean
, String beanName
)
52 throws BeansException
{
53 // NOTE: in case there was an exception in on the initialization method
54 // we expect the underlying thread to die and thus the system
55 // authentication to be lost. We have currently no way to catch the
56 // exception and perform the deauthentication by ourselves.
57 // deauthenticateAsSystem();
61 public void onApplicationEvent(ApplicationEvent event
) {
62 if (event
instanceof ContextRefreshedEvent
) {
63 // make sure that we have deauthenticated after the application
64 // context was initialized/refreshed
65 // deauthenticateAsSystem();