- added security test for Torque Fulcrum Turbine service integration, cft. README.txt test section
- updated mysl connector to version 5.1.44 in archetype pom
git-svn-id: https://svn.apache.org/repos/asf/turbine/maven/archetypes/trunk/turbine-webapp-4.0@1816877 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 448528e..ed5ba5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,10 @@
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.0.1</version>
+ <!-- skip tests in generated archetype's pom, here the integration-test would be skipped -->
+ <!--configuration>
+ <skip>true</skip>
+ </configuration-->
</plugin>
</plugins>
</pluginManagement>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c231563..daeae8a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,26 @@
</properties>
<body>
+ <release version="1.0.2" date="in Subversion">
+ <action type="update" dev="gk" due-to="Jeffery Painter">
+ Added security test to show Turbine Fulcrum Torque consistency
+ </action>
+ <action type="fix" dev="gk" due-to="Jeffery Painter">
+ Fix OM classes and schema, SQL autoincrement by default used
+ </action>
+ <action type="update" dev="gk">
+ war plugin 3.2, mysql connector 5.1.44 Update
+ </action>
+ <action type="update" dev="gk">
+ Integrate JSON, Localization, Model Examples
+ </action>
+ <action type="update" dev="gk">
+ Using Torque Services, Code Cleanup, Removing Classes
+ </action>
+ <action type="update" dev="gk">
+ Turbine 4.0, JUNit 4.12
+ </action>
+ </release>
<release version="1.0.1" date="in Subversion">
<action dev="gk" type="add">
Password change action, Check anonymous login
diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml
index b6481b5..7ea70dd 100644
--- a/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -53,6 +53,25 @@
</requiredProperty>
</requiredProperties>
<fileSets>
+ <fileSet filtered="true" packaged="true">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="false" packaged="false">
+ <directory>src/test/logs</directory>
+ <includes>
+ <include>**/*.log</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" packaged="false">
+ <directory>src/test/conf</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
diff --git a/src/main/resources/archetype-resources/docs/README.txt b/src/main/resources/archetype-resources/docs/README.txt
index 1e82085..f53acf0 100644
--- a/src/main/resources/archetype-resources/docs/README.txt
+++ b/src/main/resources/archetype-resources/docs/README.txt
@@ -21,9 +21,9 @@
About this archetype
-Turbine Version: Turbine 4.0-M2.
+Turbine Version: Turbine 4.0.
-# Quick Guide to using the new Turbine 4.0-M2 maven archetype
+# Quick Guide to using the new Turbine 4.0 maven archetype
for skeleton application generation
## Local database Setup
@@ -62,7 +62,8 @@
### Notes
-When invoking archetype:generate like above, you already have set Turbine goals generate-sources,pre-integration-test and you can then skip them later.
+When invoking archetype:generate like above, you already have set Turbine goals generate-sources,pre-integration-test
+and you can then skip them later.
Be aware, when you set both mvn commands goals (which are maven phases actually), i.e with
@@ -119,6 +120,26 @@
action.login=LoginUser in TurbineResources.properties and changing Login.vm appropriately (commented form)
+## Tests
+
+Prerequisites
+- at least Turbine version 4.0.1
+- database was build successfully e.g. with archetype.
+- running mysql
+
+If running from integration test, check/update
+- in pom.xml turbine.core property,
+- target/test-classes/projects/first/project/integrationtest/src/test/conf/torque/TorqueTest.properties or
+ META-INF/maven/archetype-metadata.xml
+
+The security test is by default skipped as it requires a running mysql. It tests many of the Fulcrum Torque Turbine security aspects,
+activate it by calling
+
+mvn test -DskipTests=false
+
+CAVEAT: If initialization fails, double check your database credentials! If invalid the error might be somewhat hidden behind a
+ Torque exception!
+
## Eclipse
To enable application development in Eclipse, run the following command
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
index 61d85b1..933bd05 100644
--- a/src/main/resources/archetype-resources/pom.xml
+++ b/src/main/resources/archetype-resources/pom.xml
@@ -51,7 +51,21 @@
</includes>
</resource>
</resources>
+ <testSourceDirectory>src/test/java</testSourceDirectory>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ </testResources>
<plugins>
+ <!-- test will not fail in turbien 4.0.1 -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>#var("skipTests")</skipTests>
+ </configuration>
+ </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
@@ -232,7 +246,7 @@
<dependency>
<artifactId>mysql-connector-java</artifactId>
<groupId>mysql</groupId>
- <version>5.1.40</version>
+ <version>5.1.44</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
@@ -326,6 +340,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.fulcrum</groupId>
+ <artifactId>fulcrum-testcontainer</artifactId>
+ <version>1.0.7</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
@@ -335,6 +355,7 @@
<fulcrum.json>1.1.1</fulcrum.json>
<fulcrum.security>1.1.1</fulcrum.security>
<turbine.core>4.0</turbine.core>
+ <skipTests>true</skipTests>
</properties>
diff --git a/src/main/resources/archetype-resources/src/test/conf/torque/TorqueTest.properties b/src/main/resources/archetype-resources/src/test/conf/torque/TorqueTest.properties
new file mode 100644
index 0000000..5375724
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/conf/torque/TorqueTest.properties
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+torque.applicationRoot = .
+#pipeline.default.descriptor = src/test/conf/torque/turbine-classic-pipeline.xml
+# torque.defaults.pool.defaultMaxActive=30
+torque.defaults.pool.testOnBorrow=true
+torque.defaults.pool.validationQuery=SELECT 1
+
+torque.idbroker.cleverquantity=true
+torque.idbroker.prefetch=true
+torque.idbroker.usenewconnection=true
+
+#torque.database.default=default
+torque.database.schema =
+
+# supported auto, hsqldb, mysql..
+#torque.database.default.adapter=hsqldb
+
+#torque.dsfactory.default.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+
+#torque.dsfactory.default.pool.testOnBorrow=true
+#torque.dsfactory.default.pool.validationQuery=SELECT 1 from INFORMATION_SCHEMA.SYSTEM_USERS
+#torque.dsfactory.default.connection.driver = org.hsqldb.jdbcDriver
+#torque.dsfactory.default.connection.url = jdbc:hsqldb:.
+#torque.dsfactory.default.connection.user = sa
+#torque.dsfactory.default.connection.password =
+
+##################
+#
+# For JNDI configuration please see: https://db.apache.org/torque/torque-4.0/documentation/orm-reference/initialisation-configuration.html
+#
+#
+#torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
+#torque.dsfactory.${turbine_database_name}.jndi.path=java:comp/env/${turbine_database_jndipath}
+#torque.dsfactory.${turbine_database_name}.jndi.ttl=300000
+
+# -------------------------------------------------------------------
+#
+# Shared Pool Data Source Factory
+#
+# -------------------------------------------------------------------
+#torque.database.default=turbine
+torque.database.${turbine_database_name}.adapter=${turbine_database_adapter}
+
+#torque.database.${turbine_database_name}.user=${turbine_database_user}
+#torque.database.${turbine_database_name}.password=${turbine_database_password}
+#
+#torque.defaults.pool.maxActive = 30
+#torque.defaults.pool.testOnBorrow = true
+#torque.defaults.pool.validationQuery = SELECT 1
+#
+#torque.defaults.connection.driver = ${turbine_database_driver}
+#torque.defaults.connection.url = ${turbine_database_url}${turbine_database_name}
+#torque.defaults.connection.user = ${turbine_database_user}
+#torque.defaults.connection.password = ${turbine_database_password}
+#
+torque.dsfactory.${turbine_database_name}.connection.driver = ${turbine_database_driver}
+torque.dsfactory.${turbine_database_name}.connection.url = ${turbine_database_url}${turbine_database_name}
+torque.dsfactory.${turbine_database_name}.connection.user = ${turbine_database_user}
+torque.dsfactory.${turbine_database_name}.connection.password = ${turbine_database_password}
+torque.dsfactory.${turbine_database_name}.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+# -------------------------------------------------------------------
+
+# Comment if not using shared data source factory
+torque.database.default=${turbine_database_name}
+
+
+
diff --git a/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumComponentConfiguration.xml b/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumComponentConfiguration.xml
new file mode 100644
index 0000000..612e0a8
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumComponentConfiguration.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<!--
+ This configuration file for Avalon components is used for testing the Fulcrum components
+ with Turbine.
+-->
+
+<componentConfig>
+ <!-- Torque Component -->
+ <torque>
+ <configfile>src/test/conf/torque/TorqueTest.properties</configfile>
+ </torque>
+ <cache cacheInitialSize="20" cacheCheckFrequency="5"/>
+ <mimetype/>
+ <crypto>
+ <algorithm>
+ <unix>org.apache.fulcrum.crypto.provider.UnixCrypt</unix>
+ <clear>org.apache.fulcrum.crypto.provider.ClearCrypt</clear>
+ <java>org.apache.fulcrum.crypto.provider.JavaCrypt</java>
+ <oldjava>org.apache.fulcrum.crypto.provider.OldJavaCrypt</oldjava>
+ </algorithm>
+ </crypto>
+
+ <factory/>
+ <pool/>
+ <parser>
+ <parameterEncoding>utf-8</parameterEncoding>
+ <automaticUpload>true</automaticUpload>
+ </parser>
+
+ <!-- These components belong to the Fulcrum-Security services -->
+ <securityService/>
+ <authenticator/>
+ <modelManager/>
+ <aclFactory/>
+
+ <userManager>
+ <className>${package}.om.TurbineUser</className>
+ <peerClassName>${package}.om.TurbineUserPeerImpl</peerClassName>
+ </userManager>
+ <groupManager>
+ <className>${package}.om.TurbineGroup</className>
+ <peerClassName>${package}.om.TurbineGroupPeerImpl</peerClassName>
+ </groupManager>
+ <roleManager>
+ <className>${package}.om.TurbineRole</className>
+ <peerClassName>${package}.om.TurbineRolePeerImpl</peerClassName>
+ </roleManager>
+ <permissionManager>
+ <className>${package}.om.TurbinePermission</className>
+ <peerClassName>${package}.om.TurbinePermissionPeerImpl</peerClassName>
+ </permissionManager>
+ <peerManager/>
+
+
+
+</componentConfig>
diff --git a/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumRoleConfiguration.xml b/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumRoleConfiguration.xml
new file mode 100644
index 0000000..9187ccb
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/conf/torque/fulcrumRoleConfiguration.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<!--
+ This configuration file for Avalon components is used for testing the Fulcrum Components with
+ Turbine.
+-->
+
+<role-list>
+ <!-- Torque Component Role Configuration -->
+ <role name="org.apache.torque.avalon.Torque"
+ shorthand="torque"
+ default-class="org.apache.torque.avalon.TorqueComponent" />
+
+ <role
+ name="org.apache.fulcrum.cache.GlobalCacheService"
+ shorthand="cache"
+ default-class="org.apache.fulcrum.cache.impl.DefaultGlobalCacheService"/>
+
+ <role
+ name="org.apache.fulcrum.mimetype.MimeTypeService"
+ shorthand="mimetype"
+ default-class="org.apache.fulcrum.mimetype.DefaultMimeTypeService"/>
+
+ <role
+ name="org.apache.fulcrum.crypto.CryptoService"
+ shorthand="crypto"
+ default-class="org.apache.fulcrum.crypto.DefaultCryptoService"/>
+
+ <role
+ name="org.apache.fulcrum.localization.LocalizationService"
+ shorthand="localization"
+ default-class="org.apache.fulcrum.localization.DefaultLocalizationService"/>
+
+ <role
+ name="org.apache.fulcrum.factory.FactoryService"
+ shorthand="factory"
+ default-class="org.apache.fulcrum.factory.DefaultFactoryService"/>
+
+ <role
+ name="org.apache.fulcrum.pool.PoolService"
+ shorthand="pool"
+ default-class="org.apache.fulcrum.pool.DefaultPoolService"/>
+
+ <role
+ name="org.apache.fulcrum.parser.ParserService"
+ shorthand="parser"
+ default-class="org.apache.fulcrum.parser.DefaultParserService"/>
+
+ <role
+ name="org.apache.fulcrum.xslt.XSLTService"
+ shorthand="xslt"
+ default-class="org.apache.fulcrum.xslt.DefaultXSLTService"/>
+
+ <!-- These components belong to the Fulcrum-Security services -->
+ <role
+ name="org.apache.fulcrum.security.SecurityService"
+ shorthand="securityService"
+ default-class="org.apache.fulcrum.security.BaseSecurityService"/>
+
+<role
+ name="org.apache.fulcrum.security.UserManager"
+ shorthand="userManager"
+ early-init="true"
+ default-class="org.apache.fulcrum.security.torque.turbine.TorqueTurbineUserManagerImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.GroupManager"
+ shorthand="groupManager"
+ default-class="org.apache.fulcrum.security.torque.turbine.TorqueTurbineGroupManagerImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.RoleManager"
+ shorthand="roleManager"
+ default-class="org.apache.fulcrum.security.torque.turbine.TorqueTurbineRoleManagerImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.PermissionManager"
+ shorthand="permissionManager"
+ default-class="org.apache.fulcrum.security.torque.turbine.TorqueTurbinePermissionManagerImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.torque.peer.PeerManager"
+ shorthand="peerManager"
+ default-class="org.apache.fulcrum.security.torque.peer.PeerManagerDefaultImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.ModelManager"
+ shorthand="modelManager"
+ default-class="org.apache.fulcrum.security.torque.turbine.TorqueTurbineModelManagerImpl"/>
+
+ <role
+ name="org.apache.fulcrum.security.authenticator.Authenticator"
+ shorthand="authenticator"
+ default-class="org.apache.fulcrum.security.authenticator.TextMatchAuthenticator"/>
+
+ <role
+ name="org.apache.fulcrum.security.model.ACLFactory"
+ shorthand="aclFactory"
+ default-class="org.apache.fulcrum.security.model.turbine.TurbineACLFactory"/>
+
+
+
+</role-list>
+
diff --git a/src/main/resources/archetype-resources/src/test/java/services/security/AbstractTurbineTorqueModelManagerTest.java b/src/main/resources/archetype-resources/src/test/java/services/security/AbstractTurbineTorqueModelManagerTest.java
new file mode 100644
index 0000000..6609a51
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/java/services/security/AbstractTurbineTorqueModelManagerTest.java
@@ -0,0 +1,378 @@
+package ${package}.services.security;
+
+import static org.hamcrest.CoreMatchers.describedAs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.apache.fulcrum.security.GroupManager;
+import org.apache.fulcrum.security.PermissionManager;
+import org.apache.fulcrum.security.RoleManager;
+import org.apache.fulcrum.security.SecurityService;
+import org.apache.fulcrum.security.UserManager;
+import org.apache.fulcrum.security.entity.ExtendedUser;
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.Permission;
+import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.turbine.TurbineModelManager;
+import org.apache.fulcrum.security.model.turbine.entity.TurbineGroup;
+import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
+import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
+import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.EntityExistsException;
+import org.apache.fulcrum.security.util.PermissionSet;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.fulcrum.testcontainer.BaseUnit4Test;
+import org.apache.torque.ConstraintViolationException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Initialization of services in implementing tests
+ * @author Eric Pugh
+ *
+ */
+public abstract class AbstractTurbineTorqueModelManagerTest extends BaseUnit4Test
+{
+ protected Role role;
+
+ protected TurbineModelManager modelManager;
+
+ protected RoleManager roleManager;
+
+ protected GroupManager groupManager;
+
+ protected PermissionManager permissionManager;
+
+ protected UserManager userManager;
+
+ protected SecurityService securityService;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ securityService = (SecurityService) lookup(SecurityService.ROLE);
+ roleManager = securityService.getRoleManager();
+ userManager = securityService.getUserManager();
+ groupManager = securityService.getGroupManager();
+ permissionManager = securityService.getPermissionManager();
+ modelManager = (TurbineModelManager) securityService.getModelManager();
+ }
+
+
+ @Test
+ public void testGetGlobalGroup() throws Exception
+ {
+ Group global = modelManager.getGlobalGroup();
+ assertNotNull(global);
+ assertEquals(global.getName(), modelManager.getGlobalGroupName());
+ }
+ @Test
+ public void testGrantRolePermission() throws Exception
+ {
+ Permission permission = permissionManager.getPermissionInstance();
+ permission.setName("ANSWER_PHONE");
+ checkAndAddPermission( permission );
+ role = roleManager.getRoleInstance("RECEPTIONIST");
+ checkAndAddRole( role );
+ checkAndGrant( permission );
+ role = roleManager.getRoleById(role.getId());
+ PermissionSet permissions = ((TurbineRole) role).getPermissions();
+ assertEquals(1, permissions.size());
+ assertTrue(((TurbineRole) role).getPermissions().contains(permission));
+ }
+
+ @Test
+ public void testRevokeRolePermission() throws Exception
+ {
+ Permission permission = securityService.getPermissionManager().getPermissionInstance();
+ permission.setName("ANSWER_FAX");
+ checkAndAddPermission( permission );
+ role = roleManager.getRoleInstance("SECRETARY");
+ checkAndAddRole( role );
+ checkAndGrant( permission );
+ role = roleManager.getRoleById(role.getId());
+ PermissionSet permissions = ((TurbineRole) role).getPermissions();
+ assertEquals(1, permissions.size());
+ checkAndRevoke( permission );
+ role = roleManager.getRoleById(role.getId());
+ permissions = ((TurbineRole) role).getPermissions();
+ assertEquals(0, permissions.size());
+ assertFalse(((TurbineRole) role).getPermissions().contains(permission));
+ }
+ @Test
+ public void testRevokeAllRole() throws Exception
+ {
+ Permission permission = securityService.getPermissionManager().getPermissionInstance();
+ Permission permission2 = securityService.getPermissionManager().getPermissionInstance();
+ permission.setName("SEND_SPAM");
+ permission2.setName("ANSWER_EMAIL");
+ checkAndAddPermission( permission );
+ checkAndAddPermission( permission2 );
+ role = roleManager.getRoleInstance("HELPER");
+ checkAndAddRole( role );
+ checkAndGrant( permission );
+ checkAndGrant( permission2);
+ role = roleManager.getRoleById(role.getId());
+ PermissionSet permissions = ((TurbineRole) role).getPermissions();
+ assertEquals(2, permissions.size());
+ try {
+ modelManager.revokeAll(role);
+ } catch (Exception e) {
+ System.out.println( "Might fail " + e.getMessage() );
+ }
+ role = roleManager.getRoleById(role.getId());
+ permissions = ((TurbineRole) role).getPermissions();
+ assertEquals(0, permissions.size());
+ }
+
+ @Test
+ public void testRevokeAllUser() throws Exception
+ {
+ Group group = securityService.getGroupManager().getGroupInstance();
+ group.setName("TEST_REVOKEALLUSER_GROUP");
+ group = checkAndAddGroup( group );
+
+ role = securityService.getRoleManager().getRoleInstance();
+ role.setName("TEST_REVOKEALLUSER_ROLE");
+ checkAndAddRole( role );
+
+ User user = userManager.getUserInstance("calvin");
+ user = checkAndAddUser( user, "calvin" );
+ try {
+ modelManager.grant(user, group, role);
+ } catch (DataBackendException e ){
+ if (e.getCause() != null && e.getCause() instanceof ConstraintViolationException) {
+ System.out.println( "error due to " + e.getCause().getMessage() );
+ } else {
+ System.out.println( "error due to " + e.getMessage() );
+ }
+ }
+
+ group = groupManager.getGroupById(group.getId());
+ Set<TurbineUserGroupRole> userGroupRoleSet = ((TurbineGroup) group).getUserGroupRoleSet();
+ assertEquals(1, userGroupRoleSet.size());
+ Set<TurbineUserGroupRole> userGroupRoleSet2 = ((TurbineGroup) group).getUserGroupRoleSet();
+ assertEquals(1, userGroupRoleSet2.size());
+
+ try {
+ modelManager.revokeAll(user);
+ } catch (Exception e) {
+
+ }
+ group = groupManager.getGroupById(group.getId());
+ assertEquals(0, ((TurbineGroup) group).getUserGroupRoleSet().size());
+ role = securityService.getRoleManager().getRoleByName("TEST_REVOKEALLUSER_ROLE");
+
+ // assertFalse(((TurbineRole) role).getGroups().contains(group));
+
+ }
+
+ @Test
+ public void testGrantUserGroupRole() throws Exception
+ {
+ Group group = securityService.getGroupManager().getGroupInstance();
+ group.setName("TEST_GROUP");
+ group = checkAndAddGroup( group );
+ role = roleManager.getRoleInstance();
+ role.setName("TEST_Role");
+ checkAndAddRole( role );
+ User user = userManager.getUserInstance("Clint");
+
+ user = checkAndAddUser( user, "clint" );
+
+ try {
+ modelManager.grant(user, group, role);
+ } catch (DataBackendException e ){
+ if (e.getCause() != null && e.getCause() instanceof ConstraintViolationException) {
+ System.out.println( "error due to " + e.getCause().getMessage() );
+ } else {
+ System.out.println( "error due to " + e.getMessage() );
+ }
+ }
+ boolean ugrFound = false;
+ TurbineUserGroupRole ugrTest = null;
+ for (TurbineUserGroupRole ugr : ((TurbineUser) user).getUserGroupRoleSet())
+ {
+ if (ugr.getUser().equals(user) && ugr.getGroup().equals(group) && ugr.getRole().equals(role))
+ {
+ ugrFound = true;
+ ugrTest = ugr;
+ break;
+ }
+ }
+ assertTrue(ugrFound);
+ assertTrue(ugrTest.getGroup().equals(group));
+ assertTrue(ugrTest.getUser().equals(user));
+
+ }
+ @Test
+ public void testRevokeUserGroupRole() throws Exception
+ {
+ Group group = securityService.getGroupManager().getGroupInstance();
+ group.setName("TEST_REVOKE");
+ group = checkAndAddGroup( group );
+ User user = userManager.getUserInstance("Lima");
+
+ user = checkAndAddUser( user, "pet" );
+ role = roleManager.getRoleInstance();
+ role.setName("TEST_REVOKE_ROLE");
+ checkAndAddRole( role );
+ try {
+ modelManager.grant(user, group, role);
+ } catch (DataBackendException e ){
+ if (e.getCause() != null && e.getCause() instanceof ConstraintViolationException) {
+ System.out.println( "error due to " + e.getCause().getMessage() );
+ } else {
+ System.out.println( "error due to " + e.getMessage() );
+ }
+ }
+ try {
+ modelManager.revoke(user, group, role);
+ } catch (DataBackendException e ){
+ if (e.getCause() != null && e.getCause() instanceof ConstraintViolationException) {
+ System.out.println( "error due to " + e.getCause().getMessage() );
+ } else {
+ System.out.println( "error due to " + e.getMessage() );
+ }
+ }
+ boolean ugrFound = false;
+ for (TurbineUserGroupRole ugr : ((TurbineUser) user).getUserGroupRoleSet())
+ {
+ if (ugr.getUser().equals(user) && ugr.getGroup().equals(group) && ugr.getRole().equals(role))
+ {
+ ugrFound = true;
+ break;
+ }
+ }
+ assertFalse(ugrFound);
+ }
+
+ private void checkAndAddPermission( Permission permission )
+ throws DataBackendException, UnknownEntityException, EntityExistsException
+ {
+ // cleanup if using real db
+ Permission dbPermission;
+ if (securityService.getPermissionManager().checkExists( permission )) {
+ dbPermission = securityService.getPermissionManager().getPermissionByName( permission.getName() );
+ // this might fail as it is referenced
+// try {
+// securityService.getPermissionManager().removePermission( permission );
+// } catch (Exception e) {
+// System.out.println("removing permission failed" + e.getMessage() );
+// }
+ } else {
+ dbPermission =securityService.getPermissionManager().addPermission(permission);
+ }
+ permission.setId( dbPermission.getId() );
+
+ }
+
+ // adds user but might be
+ private User checkAndAddUser( User user, String password )
+ throws DataBackendException, UnknownEntityException, EntityExistsException
+ {
+ if (user instanceof ExtendedUser) {
+ // set first last name which might be required almost always
+ ((ExtendedUser)user).setFirstName( user.getName() );
+ ((ExtendedUser)user).setLastName( user.getName() );
+ }
+ if (userManager.checkExists( user )) {
+ return userManager.getUser( user.getName() );
+ //userManager.removeUser( dbUser );
+ } else {
+ return userManager.addUser(user, password );
+ }
+ }
+
+ private Group checkAndAddGroup( Group group )
+ throws DataBackendException, UnknownEntityException, EntityExistsException
+ {
+ Group dbGroup;
+ // cleanup if using real db
+ if (securityService.getGroupManager().checkExists( group )) {
+ return securityService.getGroupManager().getGroupByName( group.getName() );
+ // might fail as it is referenced
+// try {
+// securityService.getGroupManager().removeGroup( group );
+// } catch (Exception e) {
+// System.out.println("removing group failed" + e.getMessage() );
+// }
+ } else {
+ return securityService.getGroupManager().addGroup(group);
+ }
+ }
+
+
+ private void checkAndAddRole( Role role )
+ throws DataBackendException, UnknownEntityException, EntityExistsException
+ {
+ Role dbRole;
+ // cleanup if using real db
+ if (securityService.getRoleManager().checkExists( role )) {
+ dbRole = securityService.getRoleManager().getRoleByName( role.getName() );
+ // might fail as it is referenced
+// try {
+// securityService.getRoleManager().removeRole( role );
+// } catch (Exception e) {
+// System.out.println("removing role failed " + e.getMessage() );
+// }
+ } else {
+ dbRole = securityService.getRoleManager().addRole(role);
+ }
+ if (this.role != null) {
+ this.role.setId( dbRole.getId() );
+ } else {
+ this.role =dbRole;
+ }
+
+ }
+
+ private void checkAndGrant( Permission permission )
+ throws UnknownEntityException
+ {
+ // short cut if duplicate entry use acl ...
+ try {
+ modelManager.grant(role, permission);
+ } catch (DataBackendException e) {
+ System.out.println( "Might be duplicate TODO ACL check" + e.getMessage() );
+ }
+ }
+
+ private void checkAndRevoke( Permission permission )
+ throws UnknownEntityException
+ {
+ // short cut if duplicate entry use acl ...
+ try {
+ modelManager.revoke(role, permission);
+ } catch (DataBackendException e) {
+ System.out.println( "Might be duplicate TODO ACL check" + e.getMessage() );
+ }
+ }
+
+}
diff --git a/src/main/resources/archetype-resources/src/test/java/services/security/TurbineTorqueDefaultModelManagerTest.java b/src/main/resources/archetype-resources/src/test/java/services/security/TurbineTorqueDefaultModelManagerTest.java
new file mode 100644
index 0000000..fc66a47
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/java/services/security/TurbineTorqueDefaultModelManagerTest.java
@@ -0,0 +1,71 @@
+package ${package}.services.security;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Ignore;
+
+/**
+ * Test Fulcrum Integration.
+ *
+ * Stub for further tests, relying on Fulcrum.
+ *
+ * @author gkallidis
+ * @version $Id:$
+ */
+public class TurbineTorqueDefaultModelManagerTest
+ extends AbstractTurbineTorqueModelManagerTest
+{
+
+ @Override
+ @Before
+ public void setUp() throws Exception
+ {
+ try
+ {
+ // just Fulcrum
+ setConfigurationFileName("src/test/conf/torque/fulcrumComponentConfiguration.xml");
+ setRoleFileName("src/test/conf/torque/fulcrumRoleConfiguration.xml");
+ super.setUp();
+
+ }
+ catch (Exception e)
+ {
+ fail(e.toString());
+ }
+ }
+
+ @Test
+ public void testDummy() {
+ // all tests in abstract
+ }
+
+ @Override
+ @After
+ public void tearDown()
+ {
+ modelManager = null;
+ securityService = null;
+ }
+
+}
diff --git a/src/main/resources/archetype-resources/src/test/resources/log4j.properties b/src/main/resources/archetype-resources/src/test/resources/log4j.properties
new file mode 100644
index 0000000..1576a34
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/resources/log4j.properties
@@ -0,0 +1,71 @@
+
+# Turbine logging configuration
+#
+# If we don't know the logging facility, put it into the
+# turbine.log
+#
+log4j.rootLogger = INFO, app, console
+
+#
+# Avalon log
+#
+log4j.logger.avalon = DEBUG, app, console
+log4j.additivity.avalon = false
+
+
+#
+# sql log
+# allows TRACE
+log4j.logger.org.apache.torque.util = DEBUG, sql, console
+log4j.additivity.org.apache.torque.util = false
+
+#
+# Torque log
+# allows TRACE
+log4j.logger.org.apache.torque = DEBUG, torque
+log4j.additivity.org.apache.torque = false
+
+
+# #
+# Logfile definitions
+#
+
+# application.log
+log4j.appender.app = org.apache.log4j.RollingFileAppender
+log4j.appender.app.file = src/test/logs/application.log
+log4j.appender.app.MaxFileSize=5MB
+log4j.appender.app.MaxBackupIndex=5
+log4j.appender.app.layout = org.apache.log4j.PatternLayout
+log4j.appender.app.layout.conversionPattern = %d [%t] %-5p %c - %m%n
+log4j.appender.app.append = true
+
+#
+# sql.log
+#
+log4j.appender.sql = org.apache.log4j.RollingFileAppender
+log4j.appender.sql.file = src/test/logs/sql.log
+log4j.appender.sql.MaxFileSize=5MB
+log4j.appender.sql.MaxBackupIndex=5
+log4j.appender.sql.layout = org.apache.log4j.PatternLayout
+log4j.appender.sql.layout.conversionPattern = %d [%t] %-5p %c - %m%n
+log4j.appender.sql.append = true
+
+#
+# console
+#
+log4j.appender.console = org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout = org.apache.log4j.PatternLayout
+log4j.appender.console.layout.conversionPattern = %d [%t] %-5p %C{1} - %m%n
+
+#
+# torque.log
+#
+log4j.appender.torque = org.apache.log4j.RollingFileAppender
+log4j.appender.torque.MaxFileSize=5MB
+log4j.appender.torque.MaxBackupIndex=5
+log4j.appender.torque.file = src/test/logs/torque.log
+log4j.appender.torque.layout = org.apache.log4j.PatternLayout
+log4j.appender.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n
+log4j.appender.torque.append = false
+
+