]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AuthenticatedApplicationContextInitialization.java
Refactor JCR utils and home usage
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / core / AuthenticatedApplicationContextInitialization.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.core;
17
18 import java.beans.PropertyDescriptor;
19
20 import org.springframework.beans.BeansException;
21 import org.springframework.beans.PropertyValues;
22 import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
23 import org.springframework.context.ApplicationEvent;
24 import org.springframework.context.ApplicationListener;
25 import org.springframework.context.event.ContextRefreshedEvent;
26
27 /**
28 * Executes with a system authentication the instantiation and initialization
29 * methods of the application context where it has been defined.
30 */
31 public class AuthenticatedApplicationContextInitialization extends
32 AbstractSystemExecution implements InstantiationAwareBeanPostProcessor,
33 ApplicationListener {
34 // private Log log = LogFactory
35 // .getLog(AuthenticatedApplicationContextInitialization.class);
36
37 @SuppressWarnings("rawtypes")
38 public Object postProcessBeforeInstantiation(Class beanClass,
39 String beanName) throws BeansException {
40 // we authenticate when any bean is instantiated
41 // we will deauthenticate only when the application context has been
42 // refreshed in order to be able to deal with factory beans has well
43 if (!isAuthenticatedBySelf()) {
44 authenticateAsSystem();
45 }
46 return null;
47 }
48
49 public boolean postProcessAfterInstantiation(Object bean, String beanName)
50 throws BeansException {
51 return true;
52 }
53
54 public PropertyValues postProcessPropertyValues(PropertyValues pvs,
55 PropertyDescriptor[] pds, Object bean, String beanName)
56 throws BeansException {
57 return pvs;
58 }
59
60 public Object postProcessBeforeInitialization(Object bean, String beanName)
61 throws BeansException {
62 // authenticateAsSystem();
63 return bean;
64 }
65
66 public Object postProcessAfterInitialization(Object bean, String beanName)
67 throws BeansException {
68 // NOTE: in case there was an exception in on the initialization method
69 // we expect the underlying thread to die and thus the system
70 // authentication to be lost. We have currently no way to catch the
71 // exception and perform the deauthentication by ourselves.
72 // deauthenticateAsSystem();
73 return bean;
74 }
75
76 public void onApplicationEvent(ApplicationEvent event) {
77 if (event instanceof ContextRefreshedEvent) {
78 // make sure that we have deauthenticated after the application
79 // context was initialized/refreshed
80 // deauthenticateAsSystem();
81 }
82 }
83
84 }