150a84470cf56c9435bf94b3f0fb1db17cb54345
[utils] / security / src / main / java / org / wamblee / usermgt / hibernate / AuthorizationComponent.java
1 /*
2  * Copyright 2008 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.cache.EhCache;
25 import org.wamblee.security.authorization.AuthorizationService;
26 import org.wamblee.security.authorization.hibernate.AuthorizationMappingFiles;
27 import org.wamblee.system.adapters.DefaultContainer;
28 import org.wamblee.system.adapters.ObjectConfiguration;
29 import org.wamblee.system.components.ORMappingConfig;
30 import org.wamblee.system.core.Component;
31 import org.wamblee.system.core.DefaultProvidedInterface;
32 import org.wamblee.system.core.DefaultRequiredInterface;
33 import org.wamblee.system.core.ProvidedInterface;
34 import org.wamblee.system.core.Scope;
35 import org.wamblee.system.spring.component.HibernateComponent;
36 import org.wamblee.usermgt.UserAccessor;
37 import org.wamblee.usermgt.UserAdministration;
38 import org.wamblee.usermgt.UserGroupRepositoryComponent;
39
40 public class AuthorizationComponent extends DefaultContainer {
41
42     private ProvidedInterface TRANSACTION_MGR = new DefaultProvidedInterface(
43             "transactionManager", PlatformTransactionManager.class);
44     private ProvidedInterface HIBERNATE_TEMPLATE = new DefaultProvidedInterface(
45             "hibernateTemplate", HibernateTemplate.class);
46     private ProvidedInterface AUTHORIZATION_SERVICE = new DefaultProvidedInterface(
47             "authorizationService", AuthorizationService.class);
48
49     public AuthorizationComponent(String aName, boolean aExposeInternals)
50             throws IOException {
51         super(aName);
52        
53         ObjectConfiguration authConfig = new ObjectConfiguration(AuthorizationMappingFiles.class);
54         authConfig.getSetterConfig().initAllSetters();
55         addComponent("mappingFiles", new AuthorizationMappingFiles(), authConfig); 
56
57         Component<?> hibernate = new HibernateComponent("hibernate");
58         addComponent(hibernate);
59
60         Component<?> authorization = new AuthorizationLightComponent("authorization");
61         addComponent(authorization);
62
63         addRequiredInterface(new DefaultRequiredInterface("datasource", DataSource.class));
64         addRequiredInterface(new DefaultRequiredInterface("userAccessor",
65                 UserAccessor.class));
66         addRequiredInterface(new DefaultRequiredInterface("ormconfig", ORMappingConfig.class));
67
68         if (aExposeInternals) {
69             addProvidedInterface(TRANSACTION_MGR);
70             addProvidedInterface(HIBERNATE_TEMPLATE);
71         }
72         addProvidedInterface(AUTHORIZATION_SERVICE);
73     }
74 }