From: erik Date: Mon, 12 May 2008 22:50:02 +0000 (+0000) Subject: Started work on componentizing the current user management. X-Git-Tag: wamblee-utils-0.2~1^2~151 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=e509c3ca4496543988a1cd3dee06859c86becc0b;p=utils Started work on componentizing the current user management. Also fixed several bugs in SpringComponent. --- diff --git a/security/pom.xml b/security/pom.xml index 140a904b..d213638c 100644 --- a/security/pom.xml +++ b/security/pom.xml @@ -15,7 +15,7 @@ wamblee.org security http://wamblee.org - + org.wamblee wamblee-support-general @@ -27,7 +27,18 @@ test-jar 0.2-SNAPSHOT - + + org.wamblee + wamblee-system-spring + 0.2-SNAPSHOT + + + org.wamblee + wamblee-system-spring + test-jar + 0.2-SNAPSHOT + + org.wamblee wamblee-support-spring 0.2-SNAPSHOT @@ -44,7 +55,7 @@ wamblee-hibernate-jpa 0.2-SNAPSHOT - + commons-codec commons-codec @@ -53,7 +64,7 @@ mysql mysql-connector-java - + org.springframework spring-beans @@ -78,7 +89,7 @@ 1.1 test - + diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java new file mode 100644 index 00000000..490c2305 --- /dev/null +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.usermgt.hibernate; + +import java.io.IOException; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import javax.sql.DataSource; + +import org.springframework.core.io.ClassPathResource; +import org.wamblee.system.core.DefaultProvidedInterface; +import org.wamblee.system.core.ProvidedInterface; +import org.wamblee.system.core.RequiredInterface; +import org.wamblee.system.spring.SpringComponent; + +public class ExternalDatasourceComponent extends SpringComponent { + + private static final String DATABASE_PROPERTIES = "properties/test.org.wamblee.security.database.properties"; + private static final String DATASOURCE_SPRING_CONFIG = "spring/test.org.wamblee.security.datasource.xml"; + + public ExternalDatasourceComponent(String aName) throws IOException { + super( + aName, + new String[] { DATASOURCE_SPRING_CONFIG }, + createProvidedMap(), new TreeMap()); + Properties props = new Properties(); + props.load(new ClassPathResource(DATABASE_PROPERTIES).getInputStream()); + for (Object key: props.keySet()) { + System.out.println("Key " + key + " value " + props.getProperty((String)key)); + } + addProperties(props); + } + + private static Map createProvidedMap() { + Map provided = new TreeMap(); + provided.put("dataSource", new DefaultProvidedInterface("datasource", + DataSource.class)); + return provided; + } + +} diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java new file mode 100644 index 00000000..b4c69ea7 --- /dev/null +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java @@ -0,0 +1,66 @@ +/* + * Copyright 2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.usermgt.hibernate; + +import java.io.IOException; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import javax.sql.DataSource; + +import org.hibernate.SessionFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.orm.hibernate3.HibernateTemplate; +import org.springframework.transaction.PlatformTransactionManager; +import org.wamblee.system.core.DefaultProvidedInterface; +import org.wamblee.system.core.DefaultRequiredInterface; +import org.wamblee.system.core.ProvidedInterface; +import org.wamblee.system.core.RequiredInterface; +import org.wamblee.system.spring.SpringComponent; + +public class HibernateComponent extends SpringComponent { + + private static final String HIBERNATE_PROPERTIES = "properties/test.org.wamblee.security.hibernate.properties"; + private static final String HIBERNATE_SPRING_CONFIG = "spring/test.org.wamblee.security.database.xml"; + + public HibernateComponent(String aName) throws IOException { + super(aName, new String[] { HIBERNATE_SPRING_CONFIG}, + createProvided(), createRequired()); + + Properties props = new Properties(); + props.load(new ClassPathResource(HIBERNATE_PROPERTIES).getInputStream()); + addProperties(props); + } + + private static Map createRequired() { + Map required = new TreeMap(); + required.put(new DefaultRequiredInterface("datasource", DataSource.class), "datasource"); + return required; + } + + private static Map createProvided() { + Map provided = new TreeMap(); + + provided.put("transactionManager", new DefaultProvidedInterface( + "transactionMgr", PlatformTransactionManager.class)); + provided.put("sessionFactory", new DefaultProvidedInterface( + "sessionFactory", SessionFactory.class)); + provided.put("org.springframework.orm.hibernate3.HibernateTemplate", new DefaultProvidedInterface( + "hibernateTemplate", HibernateTemplate.class)); + return provided; + } +} diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java index 9d5e80b6..23403cc8 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java @@ -20,8 +20,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Set; +import javax.sql.DataSource; + import org.wamblee.cache.Cache; import org.wamblee.general.BeanKernel; +import org.wamblee.system.adapters.DefaultContainer; +import org.wamblee.system.adapters.ObjectConfiguration; +import org.wamblee.system.core.Component; +import org.wamblee.system.core.Scope; import org.wamblee.usermgt.Group; import org.wamblee.usermgt.GroupSet; import org.wamblee.usermgt.InMemoryUserSetTest; @@ -48,14 +54,42 @@ public class HibernateUserSetTest extends InMemoryUserSetTest { super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class); } + private DefaultContainer _container; + private Scope _scope; + + private DataSource _datasource; + /* (non-Javadoc) * @see org.wamblee.usermgt.InMemoryUserSetTest#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); + + _container = new DefaultContainer("top"); + Component ds = new ExternalDatasourceComponent("datasource"); + _container.addComponent(ds); + + ObjectConfiguration config = new ObjectConfiguration(HibernateUserSetTest.class); + config.getSetterConfig().clear().add("datasource"); + _container.addComponent("testcase", this, config); + _scope = _container.start(); + + Object my = _scope.getInterfaceImplementation(ds.getProvidedInterfaces()[0], Object.class); + clearUserCache(); } + + public void setDatasource(DataSource aDatasource) { + _datasource = aDatasource; + } + + + @Override + protected void tearDown() throws Exception { + _container.stop(_scope); + super.tearDown(); + } /** * Clears the user cache. diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java new file mode 100644 index 00000000..3c406ea9 --- /dev/null +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java @@ -0,0 +1,52 @@ +/* + * Copyright 2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.usermgt.hibernate; + +import java.util.Map; +import java.util.TreeMap; + +import org.hibernate.SessionFactory; +import org.wamblee.system.core.DefaultProvidedInterface; +import org.wamblee.system.core.DefaultRequiredInterface; +import org.wamblee.system.core.ProvidedInterface; +import org.wamblee.system.core.RequiredInterface; +import org.wamblee.system.spring.SpringComponent; +import org.wamblee.usermgt.GroupSet; +import org.wamblee.usermgt.UserSet; + +public class UserGroupRepositoryComponent extends SpringComponent { + + public UserGroupRepositoryComponent(String aName) { + super(aName, new String[] { "spring/test.org.wamblee.security.usermgt-repositories.xml" } , + createProvided(), createRequired()); + + } + + private static Map createRequired() { + Map required = new TreeMap(); + required.put(new DefaultRequiredInterface("sessionFactory", SessionFactory.class), "sessionFactory"); + return required; + } + + private static Map createProvided() { + Map provided = new TreeMap(); + provided.put(UserSet.class.getName(), new DefaultProvidedInterface("userset", UserSet.class)); + provided.put(GroupSet.class.getName(), new DefaultProvidedInterface("groupset", GroupSet.class)); + return provided; + } + + +} diff --git a/security/src/test/resources/spring/test.org.wamblee.security.datasource.xml b/security/src/test/resources/spring/test.org.wamblee.security.datasource.xml index ec3d26aa..5a75178e 100644 --- a/security/src/test/resources/spring/test.org.wamblee.security.datasource.xml +++ b/security/src/test/resources/spring/test.org.wamblee.security.datasource.xml @@ -1,15 +1,23 @@ - + - - - - ${database.driver} - ${database.url} - ${database.username} - ${database.password} - - - \ No newline at end of file + + + ${database.driver} + + + ${database.url} + + + ${database.username} + + + ${database.password} + + +