You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by tv...@apache.org on 2006/09/21 22:56:38 UTC

svn commit: r448680 [1/4] - in /jakarta/turbine/fulcrum/trunk/security/torque: ./ schema/ src/java/org/apache/fulcrum/security/torque/basic/ src/java/org/apache/fulcrum/security/torque/dynamic/ src/java/org/apache/fulcrum/security/torque/om/map/ src/ja...

Author: tv
Date: Thu Sep 21 13:56:36 2006
New Revision: 448680

URL: http://svn.apache.org/viewvc?view=rev&rev=448680
Log:
First step towards a Torque security service implementation

Added:
    jakarta/turbine/fulcrum/trunk/security/torque/maven.xml
    jakarta/turbine/fulcrum/trunk/security/torque/project.properties
    jakarta/turbine/fulcrum/trunk/security/torque/project.xml
    jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml
    jakarta/turbine/fulcrum/trunk/security/torque/schema/id-table-schema.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicPermissionManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicRoleManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicUserManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueBasicUserGroupMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueDynamicGroupRoleMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueDynamicRolePermissionMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueDynamicUserDelegatesMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueDynamicUserGroupMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueGroupMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorquePermissionMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueRoleMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueTurbineRolePermissionMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueTurbineUserGroupRoleMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/om/map/TorqueUserMapBuilder.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineGroupManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineModelManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbinePermissionManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineRoleManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineUserManagerImpl.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/BasicTorqueComponentConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/BasicTorqueRoleConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/DynamicTorqueComponentConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/DynamicTorqueRoleConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/Torque.properties
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/TurbineTorqueComponentConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/TurbineTorqueRoleConfig.xml
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/log4j.properties
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/StartingSecurityServicesTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueGroupManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorquePermissionManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueRoleManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueUserManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/TorqueTurbineModelManagerTest.java
    jakarta/turbine/fulcrum/trunk/security/torque/xdocs/navigation.xml

Added: jakarta/turbine/fulcrum/trunk/security/torque/maven.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/maven.xml?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/maven.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/maven.xml Thu Sep 21 13:56:36 2006
@@ -0,0 +1,21 @@
+<project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
+
+  <preGoal name="java:compile">
+    <attainGoal name="torque-gen:prepare"/>
+    <attainGoal name="torque:om"/>
+  </preGoal>
+
+  <goal name="torque-gen:prepare">
+    <property file="project.properties" />
+    
+    <copy todir="${torque.schema.dir}">
+      <fileset dir="schema">
+        <include name="*" />
+      </fileset>
+      <filterset>
+        <filter token="DATABASE_DEFAULT" value="${torque.project}"/>
+      </filterset>
+    </copy>
+  </goal>
+
+</project>
\ No newline at end of file

Added: jakarta/turbine/fulcrum/trunk/security/torque/project.properties
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/project.properties?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/project.properties (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/project.properties Thu Sep 21 13:56:36 2006
@@ -0,0 +1,153 @@
+# -------------------------------------------------------------------
+# Copyright 2001-2004 The Apache Software Foundation
+#
+# 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.
+# -------------------------------------------------------------------
+maven.multiproject.type=jar
+maven.junit.usefile=true
+maven.junit.fork=true
+
+# -------------------------------------------------------------------
+#
+# T O R Q U E  C O N F I G U R A T I O N  F I L E
+#
+# $Id: project.properties,v 1.1 2005/09/09 12:09:49 tvan Exp $
+#
+# -------------------------------------------------------------------
+# This file contains the most commonly used properties. For a
+# a complete list of build properties, please refer to:
+#   http://jakarta.apache.org/turbine/torque/properties-reference.xml
+# -------------------------------------------------------------------
+
+# -------------------------------------------------------------------
+#
+#  P R O J E C T
+#
+# -------------------------------------------------------------------
+# This is the name of your Torque project. Your non-Java generated 
+# files will be named using the project name selected below. If your
+# project=killerapp then you will have a generated:
+#
+#   killerapp-schema.sql
+#
+# The custom is then to also rename your project XML schema from
+# project-schema.xml to killerapp-schema.xml. This is required 
+# for a few targets such as datasql, datadump, and datadtd.
+# -------------------------------------------------------------------
+
+torque.project = fulcrum
+
+
+# -------------------------------------------------------------------
+#
+#  T A R G E T  D A T A B A S E
+#
+# -------------------------------------------------------------------
+# This is the target database, only considered when generating
+# the SQL for your Torque project. Your possible choices are:
+#
+#   axion, cloudscape, db2, db2400, hypersonic, interbase, mssql,
+#   mysql, oracle, postgresql, sapdb, sybase
+# -------------------------------------------------------------------
+
+torque.database = mysql
+
+
+# -------------------------------------------------------------------
+#
+#  O B J E C T  M O D E L  I N F O R M A T I O N
+#
+# -------------------------------------------------------------------
+# These settings will allow you to customize the way your
+# Peer-based object model is created.
+# -------------------------------------------------------------------
+# addGetByNameMethod
+#   If true, Torque adds methods to get database fields by name/position.
+#
+# addIntakeRetrievable
+#   If true, the data objects will implement Intake's Retrievable 
+#   interface
+#
+# addSaveMethod
+#   If true, Torque adds tracking code to determine how to save objects.
+#
+# addTimeStamp
+#   If true, Torque true puts time stamps in generated om files.
+#
+# basePrefix
+#   A string to pre-pend to the file names of base data and peer objects.
+#
+# complexObjectModel
+#   If true, Torque generates data objects with collection support and 
+#   methods to easily retreive foreign key relationships.
+#
+# targetPackage
+#   Sets the Java package the om files will generated to, e.g. 
+#   "com.company.project.om".
+#
+# useClasspath
+#   If true, Torque will not look in the <code>templatePath</code> directory,
+#   for templates, but instead load them from the classpath, allowing you to 
+#   use Torque without extracted it from the jar.
+#
+# useManagers
+#   If true, Torque will generate Manager classes that use JCS for caching.
+#   Still considered experimental.
+#
+# objectIsCaching
+#   If true, Torque generates data objects that cache their foreign
+#   key relationships. If this is not desired (because the underlying objects
+#   can be manipulated from other code), set this property to false. This currently
+#   cannot combined with the manager setting from above.
+# -------------------------------------------------------------------
+
+torque.targetPackage = org.apache.fulcrum.security.torque.om
+torque.useClasspath = true
+
+torque.output.dir = ./target
+torque.schema.dir = ${torque.output.dir}/schema 
+
+torque.addGetByNameMethod = true
+torque.addIntakeRetrievable = false
+torque.addSaveMethod = true
+torque.addTimeStamp = true
+torque.basePrefix = Base
+torque.complexObjectModel = false
+torque.correctGetters = true
+torque.useManagers = false
+torque.objectIsCaching = false
+
+# -------------------------------------------------------------------
+#
+#  D A T A B A S E  S E T T I N G S
+#
+# -------------------------------------------------------------------
+# JDBC connection settings. This is used by the JDBCToXML task that
+# will create an XML database schema from JDBC metadata. These
+# settings are also used by the SQL Ant task to initialize your
+# Torque system with the generated SQL.
+#
+# sameJavaName
+#   If true, the JDBC task will set the javaName attribute for the tables 
+#   and columns to be the same as SQL name.
+# -------------------------------------------------------------------
+
+torque.database.driver = org.gjt.mm.mysql.Driver
+torque.database.createUrl = jdbc:mysql://localhost:3306/mysql
+torque.database.buildUrl = jdbc:mysql://localhost:3306/fulcrum
+torque.database.url = jdbc:mysql://localhost:3306/fulcrum
+torque.database.user = root
+torque.database.password = 
+torque.database.host = localhost
+
+torque.sameJavaName = false

Added: jakarta/turbine/fulcrum/trunk/security/torque/project.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/project.xml?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/project.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/project.xml Thu Sep 21 13:56:36 2006
@@ -0,0 +1,134 @@
+<?xml version="1.0"?>
+<project>
+  <extend>${basedir}/../project.xml</extend>
+  <id>fulcrum-security-torque</id>
+  <name>Fulcrum Security Torque Impl</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>fulcrum</groupId>   
+      <artifactId>fulcrum-security-api</artifactId>
+      <version>1.0.8-dev</version>
+    </dependency>   
+    <dependency>
+      <groupId>fulcrum</groupId>   
+      <artifactId>fulcrum-crypto</artifactId>
+      <version>1.0.5</version>
+    </dependency>  
+    
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.4</version>
+    </dependency>      
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.1</version>
+    </dependency>  
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.1</version>
+    </dependency>      
+    <dependency>
+      <groupId>cryptix</groupId>
+      <artifactId>cryptix</artifactId>
+      <version>3.2.0</version>
+      <url>http://www.cryptix.org/</url>
+    </dependency>    
+    
+<!-- Needed for Torque -->
+    <dependency>
+      <artifactId>torque</artifactId>
+      <groupId>torque</groupId>
+      <version>3.2</version>
+      <url>http://db.apache.org/torque</url>
+    </dependency>
+
+    <dependency>
+      <artifactId>commons-beanutils</artifactId>
+      <groupId>commons-beanutils</groupId>
+      <version>1.7.0</version>
+      <url>http://jakarta.apache.org/commons/beanutils/</url>
+    </dependency>
+
+    <dependency>
+      <artifactId>commons-configuration</artifactId>
+      <groupId>commons-configuration</groupId>
+      <version>1.2</version>
+      <url>http://jakarta.apache.org/commons/configuration/</url>
+    </dependency>
+
+    <dependency>
+      <artifactId>commons-dbcp</artifactId>
+      <groupId>commons-dbcp</groupId>
+      <version>1.2.1</version>
+      <url>http://jakarta.apache.org/commons/dbcp/</url>
+    </dependency>
+
+    <dependency>
+      <artifactId>commons-pool</artifactId>
+      <groupId>commons-pool</groupId>
+      <version>1.3</version>
+      <url>http://jakarta.apache.org/commons/pool/</url>
+    </dependency>
+
+    <dependency>
+      <artifactId>jcs</artifactId>
+      <groupId>jcs</groupId>
+      <version>20030822.182132</version>
+      <!-- version>1.2.7.0</version -->
+      <url>http://jakarta.apache.org/jcs/</url>
+    </dependency>
+ 
+    <!-- dependency>
+      <artifactId>concurrent</artifactId>
+      <groupId>concurrent</groupId>
+      <version>1.0</version>
+    </dependency -->
+ 
+    <dependency>
+      <artifactId>village</artifactId>
+      <groupId>village</groupId>
+      <version>2.0</version>
+    </dependency>
+
+    <dependency>
+      <artifactId>maven-torque-plugin</artifactId>
+      <groupId>torque</groupId>
+      <version>3.2</version>
+      <type>plugin</type>
+    </dependency>
+
+    <dependency>
+      <artifactId>mysql-connector-java</artifactId>
+      <groupId>mm.mysql</groupId>
+      <version>3.1.12-bin</version>
+    </dependency> 
+
+  </dependencies>
+  <build>
+    <sourceDirectory>${basedir}/src/java/</sourceDirectory>
+    <unitTestSourceDirectory>${basedir}/src/test/</unitTestSourceDirectory>
+    <unitTest>
+      <includes>
+        <include>**/*Test.*</include>
+        <include>**/*TestCase.*</include>
+      </includes>
+      <excludes>
+        <include>**/Abstract*.*</include>
+      </excludes>
+      <resources>
+        <resource>
+          <directory>${basedir}/src/test</directory>
+          <includes>
+            <include>**/*.*</include>
+          </includes>
+        </resource>
+      </resources>      
+    </unitTest>   
+  </build>
+
+</project>
+

Added: jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml Thu Sep 21 13:56:36 2006
@@ -0,0 +1,179 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Copyright 2001-2005 The Apache Software Foundation.
+
+ 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.
+-->
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
+
+<!-- ====================================================================     -->
+<!--                                                                          -->
+<!-- F U L C R U M  S E C U R I T Y  S C H E M A                                      -->
+<!--                                                                          -->
+<!-- ====================================================================     -->
+<!-- @author: <a href="mailto:tv@apache.org">Thomas Vandahl</a> -->
+<!-- @version $Id: torque-security-schema.xml,v 1.1 2005/09/26 14:10:04 tvan Exp $ -->
+<!-- ====================================================================     -->
+
+<database name="@DATABASE_DEFAULT@">
+
+  <table name="FULCRUM_PERMISSION" javaName="TorquePermission" idMethod="idbroker">
+    <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
+    <column name="PERMISSION_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+
+    <unique>
+      <unique-column name="PERMISSION_NAME"/>
+    </unique>
+
+  </table>
+
+  <table name="FULCRUM_ROLE" javaName="TorqueRole" idMethod="idbroker">
+    <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
+    <column name="ROLE_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+
+    <unique>
+        <unique-column name="ROLE_NAME"/>
+    </unique>
+
+  </table>
+
+  <table name="FULCRUM_GROUP" javaName="TorqueGroup" idMethod="idbroker">
+    <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
+    <column name="GROUP_NAME" required="true" type="VARCHAR" size="64" javaName="Name"/>
+
+    <unique>
+        <unique-column name="GROUP_NAME"/>
+    </unique>
+
+  </table>
+
+  <table name="FULCRUM_USER" javaName="TorqueUser" idMethod="idbroker">
+    <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
+    <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+    <column name="PASSWORD_VALUE" required="true" size="16" type="VARCHAR" javaName="Password"/>
+<!--
+    <column name="FIRST_NAME" required="true" size="64" type="VARCHAR"/>
+    <column name="LAST_NAME" required="true" size="64" type="VARCHAR"/>
+    <column name="EMAIL" size="64" type="VARCHAR"/>
+    <column name="CONFIRM_VALUE" size="16" type="VARCHAR" javaName="Confirmed"/>
+    <column name="MODIFIED" type="TIMESTAMP"/>
+    <column name="CREATED" type="TIMESTAMP" javaName="CreateDate"/>
+    <column name="LAST_LOGIN" type="TIMESTAMP"/>
+    <column name="OBJECTDATA" type="VARBINARY"/>
+-->
+    <unique>
+        <unique-column name="LOGIN_NAME"/>
+    </unique>
+
+  </table>
+
+  <!-- Basic Security Model -->
+  <table name="BASIC_USER_GROUP" javaName="TorqueBasicUserGroup">
+    <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_USER">
+      <reference local="USER_ID" foreign="USER_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_GROUP">
+      <reference local="GROUP_ID" foreign="GROUP_ID"/>
+    </foreign-key>
+  </table>
+
+  <!-- Dynamic Security Model -->
+  <table name="DYNAMIC_ROLE_PERMISSION" javaName="TorqueDynamicRolePermission">
+    <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_ROLE">
+      <reference local="ROLE_ID" foreign="ROLE_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_PERMISSION">
+      <reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="DYNAMIC_USER_GROUP" javaName="TorqueDynamicUserGroup">
+    <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_USER">
+      <reference local="USER_ID" foreign="USER_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_GROUP">
+      <reference local="GROUP_ID" foreign="GROUP_ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="DYNAMIC_GROUP_ROLE" javaName="TorqueDynamicGroupRole">
+    <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_GROUP">
+      <reference local="GROUP_ID" foreign="GROUP_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_ROLE">
+      <reference local="ROLE_ID" foreign="ROLE_ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="DYNAMIC_USER_DELEGATES" javaName="TorqueDynamicUserDelegates">
+    <column name="DELEGATOR_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="DELEGATEE_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_USER">
+      <reference local="DELEGATOR_USER_ID" foreign="USER_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_USER">
+      <reference local="DELEGATEE_USER_ID" foreign="USER_ID"/>
+    </foreign-key>
+  </table>
+
+  <!-- Turbine Security Model -->
+  <table name="TURBINE_ROLE_PERMISSION" javaName="TorqueTurbineRolePermission">
+    <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_ROLE">
+      <reference local="ROLE_ID" foreign="ROLE_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_PERMISSION">
+      <reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
+    </foreign-key>
+  </table>
+
+  <table name="TURBINE_USER_GROUP_ROLE" javaName="TorqueTurbineUserGroupRole">
+    <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+    <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+    <foreign-key foreignTable="FULCRUM_USER">
+      <reference local="USER_ID" foreign="USER_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_GROUP">
+      <reference local="GROUP_ID" foreign="GROUP_ID"/>
+    </foreign-key>
+
+    <foreign-key foreignTable="FULCRUM_ROLE">
+      <reference local="ROLE_ID" foreign="ROLE_ID"/>
+    </foreign-key>
+  </table>
+
+</database>

Added: jakarta/turbine/fulcrum/trunk/security/torque/schema/id-table-schema.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/schema/id-table-schema.xml?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/schema/id-table-schema.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/schema/id-table-schema.xml Thu Sep 21 13:56:36 2006
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Copyright 2001-2005 The Apache Software Foundation.
+
+ 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.
+-->
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
+
+<!-- ==================================================================== -->
+<!--                                                                      -->
+<!-- I D  B R O K E R  S C H E M A                                        -->
+<!--                                                                      -->
+<!-- ==================================================================== -->
+<!-- This is the XML schema use by Torque to generate the SQL for         -->
+<!-- ID_TABLE table used by the id broker mechanism in Torque.            -->
+<!-- ==================================================================== -->
+<!-- @author: <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>       -->
+<!-- @version $Id: id-table-schema.xml,v 1.2 2005/09/23 12:19:52 tvan Exp $ -->
+<!-- ==================================================================== -->
+
+<database name="@DATABASE_DEFAULT@">
+  <table name="ID_TABLE" idMethod="idbroker">
+    <column name="ID_TABLE_ID" required="true" primaryKey="true" type="INTEGER"/>
+    <column name="TABLE_NAME" required="true" size="255" type="VARCHAR"/>
+    <column name="NEXT_ID" type="INTEGER"/>
+    <column name="QUANTITY" type="INTEGER"/>
+
+    <unique>
+      <unique-column name="TABLE_NAME"/>
+    </unique>
+
+  </table>
+</database>

Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java Thu Sep 21 13:56:36 2006
@@ -0,0 +1,350 @@
+package org.apache.fulcrum.security.torque.basic;
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  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.
+ */
+import java.sql.Connection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fulcrum.security.UserManager;
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
+import org.apache.fulcrum.security.spi.AbstractGroupManager;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueGroup;
+import org.apache.fulcrum.security.torque.om.TorqueGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueUser;
+import org.apache.fulcrum.security.torque.om.TorqueUserPeer;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.EntityExistsException;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.fulcrum.security.util.UserSet;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueBasicGroupManagerImpl extends AbstractGroupManager
+{
+    /**
+     * Retrieve a Group object with specified name.
+     *
+     * @param name the name of the Group.
+     * @return an object representing the Group with specified name.
+     * @throws DataBackendException if there was an error accessing the
+     *         data backend.
+     * @throws UnknownEntityException if the group does not exist.
+     */
+    public Group getGroupByName(String name)
+        throws DataBackendException, UnknownEntityException
+    {
+        Group group = getGroupInstance();
+        List groups = Collections.EMPTY_LIST;
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+            
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueGroupPeer.GROUP_NAME, name);
+
+            groups = TorqueGroupPeer.doSelect(criteria, con);
+
+            if (groups.size() == 1)
+            {
+                TorqueGroup g = (TorqueGroup) groups.get(0);
+                
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((BasicGroup)group).setUsers(getUsersForGroup(group, con));
+            }
+
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        if (groups.size() == 0)
+        {
+            throw new UnknownEntityException("Could not find group" + name);
+        }
+
+        if (groups.size() > 1)
+        {
+            throw new DataBackendException("Multiple Groups with same name '" + name + "'");
+        }
+
+        return group;
+    }
+
+    /**
+     * Retrieves all groups defined in the system.
+     *
+     * @return the names of all groups defined in the system.
+     * @throws DataBackendException if there was an error accessing the
+     *         data backend.
+     */
+    public GroupSet getAllGroups() throws DataBackendException
+    {
+        GroupSet groupSet = new GroupSet();
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+
+            List groups = TorqueGroupPeer.doSelect(new Criteria(), con);
+            
+            for (Iterator i = groups.iterator(); i.hasNext();)
+            {
+                Group group = getGroupInstance();
+                TorqueGroup g = (TorqueGroup)i.next();
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((BasicGroup)group).setUsers(getUsersForGroup(group, con));
+
+                groupSet.add(group);
+            }
+
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        return groupSet;
+    }
+
+    /**
+        * Removes a Group from the system.
+        *
+        * @param group The object describing the group to be removed.
+        * @throws DataBackendException if there was an error accessing the data
+        *         backend.
+        * @throws UnknownEntityException if the group does not exist.
+        */
+    public synchronized void removeGroup(Group group)
+        throws DataBackendException, UnknownEntityException
+    {
+        try
+        {
+            TorqueGroupPeer.doDelete(SimpleKey.keyFor((Integer)group.getId()));
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Removing Group '" + group + "' failed", e);
+        }
+    }
+
+    /**
+        * Renames an existing Group.
+        *
+        * @param group The object describing the group to be renamed.
+        * @param name the new name for the group.
+        * @throws DataBackendException if there was an error accessing the data
+        *         backend.
+        * @throws UnknownEntityException if the group does not exist.
+        */
+    public synchronized void renameGroup(Group group, String name)
+        throws DataBackendException, UnknownEntityException
+    {
+        if (checkExists(group))
+        {
+            group.setName(name);
+
+            try
+            {
+                TorqueGroup g = new TorqueGroup();
+                g.setId((Integer)group.getId());
+                g.setName(name);
+                g.setNew(false);
+                g.save();
+            }
+            catch (Exception e)
+            {
+                throw new DataBackendException("Renaming Group '" + group + "' failed", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Unknown group '" + group + "'");
+        }
+    }
+
+    /**
+     * Determines if the <code>Group</code> exists in the security system.
+     *
+     * @param groupName a <code>Group</code> value
+     * @return true if the group name exists in the system, false otherwise
+     * @throws DataBackendException when more than one Group with
+     *         the same name exists.
+     */
+    public boolean checkExists(String groupName) throws DataBackendException
+    {
+        List groups;
+
+        try
+        {
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueGroupPeer.GROUP_NAME, groupName);
+
+            groups = TorqueGroupPeer.doSelect(criteria);
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        if (groups.size() > 1)
+        {
+            throw new DataBackendException(
+                    "Multiple groups with same name '" + groupName + "'");
+        }
+
+        return (groups.size() == 1);
+    }
+
+    /**
+    * Creates a new group with specified attributes.
+    *
+    * @param group the object describing the group to be created.
+    * @return a new Group object that has id set up properly.
+    * @throws DataBackendException if there was an error accessing the data
+    *         backend.
+    * @throws EntityExistsException if the group already exists.
+    */
+    protected synchronized Group persistNewGroup(Group group)
+        throws DataBackendException
+    {
+        try
+        {
+            TorqueGroup g = new TorqueGroup();
+            g.setName(group.getName());
+            g.save();
+            
+            group.setId(g.getId());
+        }
+        catch (Exception e)
+        {
+            throw new DataBackendException("Adding Group '" + group + "' failed", e);
+        }
+        
+        return group;
+    }
+
+    /**
+     * Retrieve a Group object with specified id.
+     *
+     * @param id
+     *            the id of the Group.
+     * @return an object representing the Group with specified id.
+     * @throws DataBackendException
+     *             if there was an error accessing the data backend.
+     * @throws UnknownEntityException
+     *             if the group does not exist.
+     */
+    public Group getGroupById(Object id)
+        throws DataBackendException, UnknownEntityException
+    {
+        Group group = getGroupInstance();
+
+        if (id != null && id instanceof Integer)
+        {
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+                
+                TorqueGroup g = TorqueGroupPeer.retrieveByPK((Integer)id, con);
+                
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((BasicGroup)group).setUsers(getUsersForGroup(group, con));
+
+                Transaction.commit(con);
+            }
+            catch (NoRowsException e)
+            {
+                Transaction.safeRollback(con);
+                throw new UnknownEntityException("Group with id '" + id + "' does not exist.", e);
+            }
+            catch (TorqueException e)
+            {
+                Transaction.safeRollback(con);
+                throw new DataBackendException("Error retrieving group information", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Invalid group id '" + group.getId() + "'");
+        }
+
+        return group;
+    }
+
+    /**
+     * Provides the users for the given group
+     *  
+     * @param group the group for which the users should be retrieved  
+     * @param con a database connection
+     */
+    private UserSet getUsersForGroup(Group group, Connection con)
+        throws TorqueException, DataBackendException
+    {
+        UserSet userSet = new UserSet();
+        
+        Criteria criteria = new Criteria();
+        criteria.addJoin(TorqueBasicUserGroupPeer.USER_ID, TorqueUserPeer.USER_ID);
+        criteria.add(TorqueBasicUserGroupPeer.GROUP_ID, (Integer)group.getId());
+        
+        List users = TorqueUserPeer.doSelect(criteria, con);
+        UserManager userManager = getUserManager();
+        
+        for (Iterator i = users.iterator(); i.hasNext();)
+        {
+            TorqueUser u = (TorqueUser)i.next();
+            User user = userManager.getUserInstance();
+            
+            user.setId(u.getId());
+            user.setName(u.getName());
+            user.setPassword(u.getPassword());
+            userSet.add(user);
+        }
+        
+        return userSet;
+    }
+}
\ No newline at end of file

Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java Thu Sep 21 13:56:36 2006
@@ -0,0 +1,180 @@
+package org.apache.fulcrum.security.torque.basic;
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  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.
+ */
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.basic.BasicModelManager;
+import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
+import org.apache.fulcrum.security.model.basic.entity.BasicUser;
+import org.apache.fulcrum.security.spi.AbstractManager;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.util.Criteria;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueBasicModelManagerImpl extends AbstractManager implements BasicModelManager
+{
+    /**
+     * Puts a user in a group.
+     *
+     * This method is used when adding a user to a group
+     *
+     * @param user the User.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if the account is not present.
+     */
+    public synchronized void grant(User user, Group group) throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = false;
+        boolean userExists = false;
+        
+        try
+        {
+            groupExists = getGroupManager().checkExists(group);
+            userExists = getUserManager().checkExists(user);
+            if (groupExists && userExists)
+            {
+                ((BasicUser) user).addGroup(group);
+                ((BasicGroup) group).addUser(user);
+                
+                TorqueBasicUserGroup ug = new TorqueBasicUserGroup();
+                ug.setGroupId((Integer)group.getId());
+                ug.setUserId((Integer)user.getId());
+                ug.save();
+
+                return;
+            }
+        }
+        catch (Exception e)
+        {
+            throw new DataBackendException("grant('" + user.getName() + user.getId() + "', '" + group.getName() + group.getId() + "') failed", e);
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!userExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
+        }
+    }
+
+    /**
+     * Removes a user in a group.
+     *
+     * This method is used when removing a user to a group
+     *
+     * @param user the User.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if the user or group is not present.
+     */
+    public synchronized void revoke(User user, Group group) throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = false;
+        boolean userExists = false;
+        
+        try
+        {
+            groupExists = getGroupManager().checkExists(group);
+            userExists = getUserManager().checkExists(user);
+            if (groupExists && userExists)
+            {
+                ((BasicUser) user).removeGroup(group);
+                ((BasicGroup) group).removeUser(user);
+                
+                Criteria criteria = new Criteria();
+                criteria.add(TorqueBasicUserGroupPeer.GROUP_ID, (Integer)group.getId());
+                criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
+                TorqueBasicUserGroupPeer.doDelete(criteria);
+
+                return;
+            }
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("revoke('" + user.getName() + "', '" + group.getName() + "') failed", e);
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!userExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
+        }
+    }
+
+    /**
+     * Revokes all groups from a user
+     *
+     * This method is used when deleting an account.
+     *
+     * @param user the User.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if the account is not present.
+     */
+    public synchronized void revokeAll(User user)
+        throws DataBackendException, UnknownEntityException
+    {
+        boolean userExists = false;
+        userExists = getUserManager().checkExists(user);
+        if (userExists)
+        {
+            BasicUser u = (BasicUser) user;
+            
+            // copy to avoid ConcurrentModificationException
+            List groups = new ArrayList(u.getGroups());
+
+            for (Iterator i = groups.iterator(); i.hasNext();)
+            {
+                Group group = (Group)i.next();
+                u.removeGroup(group);
+            }
+
+            try
+            {
+                Criteria criteria = new Criteria();
+                criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
+                TorqueBasicUserGroupPeer.doDelete(criteria);
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("revokeAll('" + user.getName() + "') failed", e);
+            }
+
+            return;
+        }
+        else
+        {
+            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
+        }
+    }
+}
\ No newline at end of file

Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java Thu Sep 21 13:56:36 2006
@@ -0,0 +1,353 @@
+package org.apache.fulcrum.security.torque.basic;
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  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.
+ */
+import java.sql.Connection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fulcrum.security.GroupManager;
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.basic.entity.BasicUser;
+import org.apache.fulcrum.security.spi.AbstractUserManager;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueGroup;
+import org.apache.fulcrum.security.torque.om.TorqueGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueUser;
+import org.apache.fulcrum.security.torque.om.TorqueUserPeer;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.EntityExistsException;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.fulcrum.security.util.UserSet;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueBasicUserManagerImpl extends AbstractUserManager
+{
+    /**
+     * Check whether a specified user's account exists.
+     *
+     * The login name is used for looking up the account.
+     *
+     * @param userName The name of the user to be checked.
+     * @return true if the specified account exists
+     * @throws DataBackendException if there was an error accessing
+     *         the data backend.
+     */
+    public boolean checkExists(String userName) throws DataBackendException
+    {
+        List users;
+
+        try
+        {
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueUserPeer.LOGIN_NAME, userName.toLowerCase());
+
+            users = TorqueUserPeer.doSelect(criteria);
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Error retrieving user information", e);
+        }
+
+        if (users.size() > 1)
+        {
+            throw new DataBackendException("Multiple Users with same username '" + userName + "'");
+        }
+        
+        return (users.size() == 1);
+    }
+
+    /**
+     * Retrieve a user from persistent storage using username as the
+     * key.
+     *
+     * @param userName the name of the user.
+     * @return an User object.
+     * @exception UnknownEntityException if the user's account does not
+     *            exist in the database.
+     * @exception DataBackendException if there is a problem accessing the
+     *            storage.
+     */
+    public User getUser(String userName) throws UnknownEntityException, DataBackendException
+    {
+        User user = getUserInstance();
+        List users = Collections.EMPTY_LIST;
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+            
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueUserPeer.LOGIN_NAME, userName.toLowerCase());
+
+            users = TorqueUserPeer.doSelect(criteria, con);
+
+            if (users.size() == 1)
+            {
+                TorqueUser u = (TorqueUser) users.get(0);
+                
+                user.setId(u.getId());
+                user.setName(u.getName());
+                user.setPassword(u.getPassword());
+                
+                // Add groups if they exist
+                ((BasicUser)user).setGroups(getGroupsForUser(user, con));
+            }
+            
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving user information", e);
+        }
+
+        if (users.size() == 0)
+        {
+            throw new UnknownEntityException("Unknown user '" + userName + "'");
+        }
+
+        if (users.size() > 1)
+        {
+            throw new DataBackendException("Multiple Users with same username '" + userName + "'");
+        }
+
+        return user;
+    }
+
+    /**
+       * Retrieves all users defined in the system.
+       *
+       * @return the names of all users defined in the system.
+       * @throws DataBackendException if there was an error accessing the data
+       *         backend.
+       */
+    public UserSet getAllUsers() throws DataBackendException
+    {
+        UserSet userSet = new UserSet();
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+            
+            List users = TorqueUserPeer.doSelect(new Criteria(), con);
+
+            for (Iterator i = users.iterator(); i.hasNext();)
+            {
+                User user = getUserInstance();
+                TorqueUser u = (TorqueUser)i.next();
+                user.setId(u.getId());
+                user.setName(u.getName());
+                user.setPassword(u.getPassword());
+
+                // Add groups if they exist
+                ((BasicUser)user).setGroups(getGroupsForUser(user, con));
+                
+                userSet.add(user);
+            }
+
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving all users", e);
+        }
+        
+        return userSet;
+    }
+
+    /**
+    * Removes an user account from the system.
+    *
+    * @param user the object describing the account to be removed.
+    * @throws DataBackendException if there was an error accessing the data
+    *         backend.
+    * @throws UnknownEntityException if the user account is not present.
+    */
+    public synchronized void removeUser(User user) throws DataBackendException, UnknownEntityException
+    {
+        try
+        {
+            TorqueUserPeer.doDelete(SimpleKey.keyFor((Integer)user.getId()));
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Removing User '" + user + "' failed", e);
+        }
+    }
+
+    /**
+       * Creates new user account with specified attributes.
+       *
+       * @param user the object describing account to be created.
+       * @param password The password to use for the account.
+       *
+       * @throws DataBackendException if there was an error accessing the
+       *         data backend.
+       * @throws EntityExistsException if the user account already exists.
+       */
+    protected synchronized User persistNewUser(User user) throws DataBackendException
+    {
+        try
+        {
+            TorqueUser u = new TorqueUser();
+            
+            u.setName(user.getName());
+            u.setPassword(user.getPassword());
+            u.save();
+
+            user.setId(u.getId());
+        }
+        catch (Exception e)
+        {
+            throw new DataBackendException("Adding User '" + user + "' failed", e);
+        }
+        
+        return user;
+    }
+
+    /**
+       * Stores User attributes. The User is required to exist in the system.
+       *
+       * @param role The User to be stored.
+       * @throws DataBackendException if there was an error accessing the data
+       *         backend.
+       * @throws UnknownEntityException if the role does not exist.
+       */
+    public synchronized void saveUser(User user) throws DataBackendException, UnknownEntityException
+    {
+        if (checkExists(user))
+        {
+            try
+            {
+                TorqueUser u = new TorqueUser();
+                
+                u.setId((Integer)user.getId());
+                u.setName(user.getName());
+                u.setPassword(user.getPassword());
+                u.setNew(false);
+                u.save();
+            }
+            catch (Exception e)
+            {
+                throw new DataBackendException("Saving User '" + user + "' failed", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Unknown user '" + user + "'");
+        }
+    }
+
+    /**
+     * Retrieve a User object with specified id.
+     *
+     * @param id
+     *            the id of the User.
+     * @return an object representing the User with specified id.
+     * @throws DataBackendException
+     *             if there was an error accessing the data backend.
+     * @throws UnknownEntityException
+     *             if the user does not exist.
+     */
+    public User getUserById(Object id)
+        throws DataBackendException, UnknownEntityException
+    {
+        User user = getUserInstance();
+
+        if (id != null && id instanceof Integer)
+        {
+            Connection con = null;
+            
+            try
+            {
+                con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+                
+                TorqueUser u = TorqueUserPeer.retrieveByPK((Integer)id, con);
+
+                user.setId(u.getId());
+                user.setName(u.getName());
+                user.setPassword(u.getPassword());
+
+                // Add groups if they exist
+                ((BasicUser)user).setGroups(getGroupsForUser(user, con));
+                
+                Transaction.commit(con);
+            }
+            catch (NoRowsException e)
+            {
+                Transaction.safeRollback(con);
+                throw new UnknownEntityException("User with id '" + id + "' does not exist.", e);
+            }
+            catch (TorqueException e)
+            {
+                Transaction.safeRollback(con);
+                throw new DataBackendException("Error retrieving user information", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Invalid user id '" + user.getId() + "'");
+        }
+
+        return user;
+    }
+    
+    /**
+     * Provides the groups for the given user
+     *  
+     * @param user the user for which the groups should be retrieved  
+     * @param con a database connection
+     */
+    private GroupSet getGroupsForUser(User user, Connection con)
+        throws TorqueException, DataBackendException
+    {
+        GroupSet groupSet = new GroupSet();
+        
+        Criteria criteria = new Criteria();
+        criteria.addJoin(TorqueBasicUserGroupPeer.GROUP_ID, TorqueGroupPeer.GROUP_ID);
+        criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
+        
+        List groups = TorqueGroupPeer.doSelect(criteria, con);
+        GroupManager groupManager = getGroupManager();
+        
+        for (Iterator i = groups.iterator(); i.hasNext();)
+        {
+            TorqueGroup g = (TorqueGroup)i.next();
+            Group group = groupManager.getGroupInstance();
+            
+            group.setId(g.getId());
+            group.setName(g.getName());
+            groupSet.add(group);
+        }
+        
+        return groupSet;
+    }
+}

Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java?view=auto&rev=448680
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java Thu Sep 21 13:56:36 2006
@@ -0,0 +1,396 @@
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  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.
+ */
+import java.sql.Connection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fulcrum.security.RoleManager;
+import org.apache.fulcrum.security.UserManager;
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
+import org.apache.fulcrum.security.spi.AbstractGroupManager;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueGroup;
+import org.apache.fulcrum.security.torque.om.TorqueGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueRole;
+import org.apache.fulcrum.security.torque.om.TorqueRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueUser;
+import org.apache.fulcrum.security.torque.om.TorqueUserPeer;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.EntityExistsException;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.util.RoleSet;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.fulcrum.security.util.UserSet;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueDynamicGroupManagerImpl extends AbstractGroupManager
+{
+    /**
+     * Retrieve a Group object with specified name.
+     *
+     * @param name the name of the Group.
+     * @return an object representing the Group with specified name.
+     * @throws DataBackendException if there was an error accessing the
+     *         data backend.
+     * @throws UnknownEntityException if the group does not exist.
+     */
+    public Group getGroupByName(String name)
+        throws DataBackendException, UnknownEntityException
+    {
+        Group group = getGroupInstance();
+        List groups = Collections.EMPTY_LIST;
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+            
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueGroupPeer.GROUP_NAME, name);
+
+            groups = TorqueGroupPeer.doSelect(criteria, con);
+
+            if (groups.size() == 1)
+            {
+                TorqueGroup g = (TorqueGroup) groups.get(0);
+                
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((DynamicGroup)group).setUsers(getUsersForGroup(group, con));
+
+                // Add roles if they exist
+                ((DynamicGroup)group).setRoles(getRolesForGroup(group, con));
+            }
+
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        if (groups.size() == 0)
+        {
+            throw new UnknownEntityException("Could not find group" + name);
+        }
+
+        if (groups.size() > 1)
+        {
+            throw new DataBackendException("Multiple Groups with same name '" + name + "'");
+        }
+
+        return group;
+    }
+
+    /**
+     * Retrieves all groups defined in the system.
+     *
+     * @return the names of all groups defined in the system.
+     * @throws DataBackendException if there was an error accessing the
+     *         data backend.
+     */
+    public GroupSet getAllGroups() throws DataBackendException
+    {
+        GroupSet groupSet = new GroupSet();
+        Connection con = null;
+
+        try
+        {
+            con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+
+            List groups = TorqueGroupPeer.doSelect(new Criteria(), con);
+            
+            for (Iterator i = groups.iterator(); i.hasNext();)
+            {
+                Group group = getGroupInstance();
+                TorqueGroup g = (TorqueGroup)i.next();
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((DynamicGroup)group).setUsers(getUsersForGroup(group, con));
+
+                // Add roles if they exist
+                ((DynamicGroup)group).setRoles(getRolesForGroup(group, con));
+
+                groupSet.add(group);
+            }
+
+            Transaction.commit(con);
+        }
+        catch (TorqueException e)
+        {
+            Transaction.safeRollback(con);
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        return groupSet;
+    }
+
+    /**
+        * Removes a Group from the system.
+        *
+        * @param group The object describing the group to be removed.
+        * @throws DataBackendException if there was an error accessing the data
+        *         backend.
+        * @throws UnknownEntityException if the group does not exist.
+        */
+    public synchronized void removeGroup(Group group)
+        throws DataBackendException, UnknownEntityException
+    {
+        try
+        {
+            TorqueGroupPeer.doDelete(SimpleKey.keyFor((Integer)group.getId()));
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Removing Group '" + group + "' failed", e);
+        }
+    }
+
+    /**
+        * Renames an existing Group.
+        *
+        * @param group The object describing the group to be renamed.
+        * @param name the new name for the group.
+        * @throws DataBackendException if there was an error accessing the data
+        *         backend.
+        * @throws UnknownEntityException if the group does not exist.
+        */
+    public synchronized void renameGroup(Group group, String name)
+        throws DataBackendException, UnknownEntityException
+    {
+        if (checkExists(group))
+        {
+            group.setName(name);
+
+            try
+            {
+                TorqueGroup g = new TorqueGroup();
+                g.setId((Integer)group.getId());
+                g.setName(name);
+                g.setNew(false);
+                g.save();
+            }
+            catch (Exception e)
+            {
+                throw new DataBackendException("Renaming Group '" + group + "' failed", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Unknown group '" + group + "'");
+        }
+    }
+
+    /**
+     * Determines if the <code>Group</code> exists in the security system.
+     *
+     * @param groupName a <code>Group</code> value
+     * @return true if the group name exists in the system, false otherwise
+     * @throws DataBackendException when more than one Group with
+     *         the same name exists.
+     */
+    public boolean checkExists(String groupName) throws DataBackendException
+    {
+        List groups;
+
+        try
+        {
+            Criteria criteria = new Criteria();
+            criteria.add(TorqueGroupPeer.GROUP_NAME, groupName);
+
+            groups = TorqueGroupPeer.doSelect(criteria);
+        }
+        catch (TorqueException e)
+        {
+            throw new DataBackendException("Error retrieving group information", e);
+        }
+
+        if (groups.size() > 1)
+        {
+            throw new DataBackendException(
+                    "Multiple groups with same name '" + groupName + "'");
+        }
+
+        return (groups.size() == 1);
+    }
+
+    /**
+    * Creates a new group with specified attributes.
+    *
+    * @param group the object describing the group to be created.
+    * @return a new Group object that has id set up properly.
+    * @throws DataBackendException if there was an error accessing the data
+    *         backend.
+    * @throws EntityExistsException if the group already exists.
+    */
+    protected synchronized Group persistNewGroup(Group group)
+        throws DataBackendException
+    {
+        try
+        {
+            TorqueGroup g = new TorqueGroup();
+            g.setName(group.getName());
+            g.save();
+            
+            group.setId(g.getId());
+        }
+        catch (Exception e)
+        {
+            throw new DataBackendException("Adding Group '" + group + "' failed", e);
+        }
+        
+        return group;
+    }
+
+    /**
+     * Retrieve a Group object with specified id.
+     *
+     * @param id
+     *            the id of the Group.
+     * @return an object representing the Group with specified id.
+     * @throws DataBackendException
+     *             if there was an error accessing the data backend.
+     * @throws UnknownEntityException
+     *             if the group does not exist.
+     */
+    public Group getGroupById(Object id)
+        throws DataBackendException, UnknownEntityException
+    {
+        Group group = getGroupInstance();
+
+        if (id != null && id instanceof Integer)
+        {
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+                
+                TorqueGroup g = TorqueGroupPeer.retrieveByPK((Integer)id, con);
+                
+                group.setId(g.getId());
+                group.setName(g.getName());
+                
+                // Add users if they exist
+                ((DynamicGroup)group).setUsers(getUsersForGroup(group, con));
+
+                // Add roles if they exist
+                ((DynamicGroup)group).setRoles(getRolesForGroup(group, con));
+
+                Transaction.commit(con);
+            }
+            catch (NoRowsException e)
+            {
+                Transaction.safeRollback(con);
+                throw new UnknownEntityException("Group with id '" + id + "' does not exist.", e);
+            }
+            catch (TorqueException e)
+            {
+                Transaction.safeRollback(con);
+                throw new DataBackendException("Error retrieving group information", e);
+            }
+        }
+        else
+        {
+            throw new UnknownEntityException("Invalid group id '" + group.getId() + "'");
+        }
+
+        return group;
+    }
+
+    /**
+     * Provides the users for the given group
+     *  
+     * @param group the group for which the users should be retrieved  
+     * @param con a database connection
+     */
+    private UserSet getUsersForGroup(Group group, Connection con)
+        throws TorqueException, DataBackendException
+    {
+        UserSet userSet = new UserSet();
+        
+        Criteria criteria = new Criteria();
+        criteria.addJoin(TorqueDynamicUserGroupPeer.USER_ID, TorqueUserPeer.USER_ID);
+        criteria.add(TorqueDynamicUserGroupPeer.GROUP_ID, (Integer)group.getId());
+        
+        List users = TorqueUserPeer.doSelect(criteria, con);
+        UserManager userManager = getUserManager();
+        
+        for (Iterator i = users.iterator(); i.hasNext();)
+        {
+            TorqueUser u = (TorqueUser)i.next();
+            User user = userManager.getUserInstance();
+            
+            user.setId(u.getId());
+            user.setName(u.getName());
+            user.setPassword(u.getPassword());
+            userSet.add(user);
+        }
+        
+        return userSet;
+    }
+
+    /**
+     * Provides the roles for the given group
+     *  
+     * @param group the group for which the roles should be retrieved  
+     * @param con a database connection
+     */
+    private RoleSet getRolesForGroup(Group group, Connection con)
+        throws TorqueException, DataBackendException
+    {
+        RoleSet roleSet = new RoleSet();
+        
+        Criteria criteria = new Criteria();
+        criteria.addJoin(TorqueDynamicGroupRolePeer.ROLE_ID, TorqueRolePeer.ROLE_ID);
+        criteria.add(TorqueDynamicGroupRolePeer.GROUP_ID, (Integer)group.getId());
+        
+        List roles = TorqueRolePeer.doSelect(criteria, con);
+        RoleManager roleManager = getRoleManager();
+        
+        for (Iterator i = roles.iterator(); i.hasNext();)
+        {
+            TorqueRole r = (TorqueRole)i.next();
+            Role role = roleManager.getRoleInstance();
+            
+            role.setId(r.getId());
+            role.setName(r.getName());
+            roleSet.add(role);
+        }
+        
+        return roleSet;
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org