(no commit message)
[utils] / security / jpatest / src / main / java / org / wamblee / usermgt / hibernate / AuthorizationComponent.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
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.wamblee.usermgt.hibernate;
17
18 import java.io.IOException;
19
20 import javax.sql.DataSource;
21
22 import org.springframework.orm.hibernate3.HibernateTemplate;
23 import org.springframework.transaction.PlatformTransactionManager;
24 import org.wamblee.security.authorization.AbstractAuthorizationService;
25 import org.wamblee.security.authorization.hibernate.AuthorizationMappingFiles;
26 import org.wamblee.system.adapters.DefaultContainer;
27 import org.wamblee.system.adapters.ObjectConfiguration;
28 import org.wamblee.system.components.ORMappingConfig;
29 import org.wamblee.system.core.Component;
30 import org.wamblee.system.core.DefaultProvidedInterface;
31 import org.wamblee.system.core.DefaultRequiredInterface;
32 import org.wamblee.system.core.ProvidedInterface;
33 import org.wamblee.system.spring.component.HibernateComponent;
34 import org.wamblee.usermgt.UserAccessor;
35
36 /**
37  * 
38  * @author $author$
39  * @version $Revision$
40  */
41 public class AuthorizationComponent extends DefaultContainer {
42     private ProvidedInterface transactionMgr = new DefaultProvidedInterface(
43         "transactionManager", PlatformTransactionManager.class);
44
45     private ProvidedInterface hibernateTemplate = new DefaultProvidedInterface(
46         "hibernateTemplate", HibernateTemplate.class);
47
48     private ProvidedInterface authorizationService = new DefaultProvidedInterface(
49         "authorizationService", AbstractAuthorizationService.class);
50
51     /**
52      * Creates a new AuthorizationComponent object.
53      * 
54      * 
55      */
56     public AuthorizationComponent(String aName, boolean aExposeInternals)
57         throws IOException {
58         super(aName);
59
60         ObjectConfiguration authConfig = new ObjectConfiguration(
61             AuthorizationMappingFiles.class);
62         authConfig.getSetterConfig().initAllSetters();
63         addComponent("mappingFiles", new AuthorizationMappingFiles(),
64             authConfig);
65
66         Component<?> hibernate = new HibernateComponent("hibernate");
67         addComponent(hibernate);
68
69         Component<?> authorization = new AuthorizationLightComponent(
70             "authorization");
71         addComponent(authorization);
72
73         addRequiredInterface(new DefaultRequiredInterface("datasource",
74             DataSource.class));
75         addRequiredInterface(new DefaultRequiredInterface("userAccessor",
76             UserAccessor.class));
77         addRequiredInterface(new DefaultRequiredInterface("ormconfig",
78             ORMappingConfig.class));
79
80         if (aExposeInternals) {
81             addProvidedInterface(transactionMgr);
82             addProvidedInterface(hibernateTemplate);
83         }
84
85         addProvidedInterface(authorizationService);
86     }
87 }