2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.core
;
18 import java
.beans
.PropertyDescriptor
;
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
;
28 * Executes with a system authentication the instantiation and initialization
29 * methods of the application context where it has been defined.
31 public class AuthenticatedApplicationContextInitialization
extends
32 AbstractSystemExecution
implements InstantiationAwareBeanPostProcessor
,
34 // private Log log = LogFactory
35 // .getLog(AuthenticatedApplicationContextInitialization.class);
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();
49 public boolean postProcessAfterInstantiation(Object bean
, String beanName
)
50 throws BeansException
{
54 public PropertyValues
postProcessPropertyValues(PropertyValues pvs
,
55 PropertyDescriptor
[] pds
, Object bean
, String beanName
)
56 throws BeansException
{
60 public Object
postProcessBeforeInitialization(Object bean
, String beanName
)
61 throws BeansException
{
62 // authenticateAsSystem();
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();
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();