]> git.argeo.org Git - lgpl/argeo-commons.git/blob - core/AuthenticatedApplicationContextInitialization.java
Prepare next development cycle
[lgpl/argeo-commons.git] / core / AuthenticatedApplicationContextInitialization.java
1 package org.argeo.security.core;
2
3 import java.beans.PropertyDescriptor;
4
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;
11
12 /**
13 * Executes with a system authentication the instantiation and initialization
14 * methods of the application context where it has been defined.
15 */
16 public class AuthenticatedApplicationContextInitialization extends
17 AbstractSystemExecution implements InstantiationAwareBeanPostProcessor,
18 ApplicationListener {
19 // private Log log = LogFactory
20 // .getLog(AuthenticatedApplicationContextInitialization.class);
21
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();
30 }
31 return null;
32 }
33
34 public boolean postProcessAfterInstantiation(Object bean, String beanName)
35 throws BeansException {
36 return true;
37 }
38
39 public PropertyValues postProcessPropertyValues(PropertyValues pvs,
40 PropertyDescriptor[] pds, Object bean, String beanName)
41 throws BeansException {
42 return pvs;
43 }
44
45 public Object postProcessBeforeInitialization(Object bean, String beanName)
46 throws BeansException {
47 // authenticateAsSystem();
48 return bean;
49 }
50
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();
58 return bean;
59 }
60
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();
66 }
67 }
68
69 }