<?xml version="1.0"?>
<!--
Copyright 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.
-->
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_1.dtd">
<!-- Autogenerated by JDBCToXMLSchema! -->
<database>
<!--
    	CREATING TABLES FOR SINGLE SIGN ON (SSO)
    	It has dependency on the Security tables PRINCIPAL and CREDENTIALS
    -->
        
    <!--
       Create Site to Principals association Table
    -->
    <!--
       Create Security Principal Table
    -->
    <table name="SECURITY_PRINCIPAL">
        <column name="PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="CLASSNAME" required="true" size="254" type="VARCHAR"/>
        <column name="IS_MAPPING_ONLY" required="true" type="BIT"/>
        <column name="IS_ENABLED" required="true" type="BIT"/>
        <column name="FULL_PATH" required="true" size="254" type="VARCHAR"/>
        <column name="CREATION_DATE" required="true" type="TIMESTAMP"/>
        <column name="MODIFIED_DATE" required="true" type="TIMESTAMP"/>
        <unique name="UIX_SECURITY_PRINCIPAL">
          <unique-column name="FULL_PATH" />
        </unique>        
    </table>

    <!--
       Create Security Permission Table
    -->
    <table name="SECURITY_PERMISSION">
        <column name="PERMISSION_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="CLASSNAME" required="true" size="254" type="VARCHAR"/>
        <column name="NAME" required="true" size="254" type="VARCHAR"/>
        <column name="ACTIONS" required="true" size="254" type="VARCHAR"/>
        <column name="CREATION_DATE" required="true" type="TIMESTAMP"/>
        <column name="MODIFIED_DATE" required="true" type="TIMESTAMP"/>
    </table>
    
    <!--
       Create Security Principal Permission Table
    -->
    <table name="PRINCIPAL_PERMISSION">
        <column name="PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="PERMISSION_ID" primaryKey="true" required="true" type="INTEGER"/>
        <foreign-key foreignTable="SECURITY_PERMISSION" onDelete="cascade">
            <reference foreign="PERMISSION_ID" local="PERMISSION_ID"/>
        </foreign-key>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="PRINCIPAL_ID"/>
        </foreign-key>
    </table>
        
    <!--
       Create Security Credential Table
    -->
    <table name="SECURITY_CREDENTIAL">
        <column name="CREDENTIAL_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="PRINCIPAL_ID" required="true" type="INTEGER"/>
        <column name="VALUE" required="true" size="254" type="VARCHAR"/>
        <column name="TYPE" required="true" type="SMALLINT"/>
        <column name="CLASSNAME" size="254" type="VARCHAR"/>
        <column name="UPDATE_REQUIRED" required="true" type="BIT"/>
        <column name="IS_ENCODED" required="true" type="BIT"/>
        <column name="IS_ENABLED" required="true" type="BIT"/>
        <column name="AUTH_FAILURES" required="true" type="SMALLINT"/>
        <column name="IS_EXPIRED" required="true" type="BIT"/>
        <column name="CREATION_DATE" required="true" type="TIMESTAMP"/>
        <column name="MODIFIED_DATE" required="true" type="TIMESTAMP"/>
        <column name="PREV_AUTH_DATE" required="false" type="TIMESTAMP"/>
        <column name="LAST_AUTH_DATE" required="false" type="TIMESTAMP"/>
        <column name="EXPIRATION_DATE" required="false" type="DATE"/>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="PRINCIPAL_ID"/>
        </foreign-key>
    </table>
	

    <!--
       Create SiteTable
    -->
    <table name="SSO_SITE">
        <column name="SITE_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="NAME" required="true" size="254" type="VARCHAR"/>
        <column name="URL" required="true" size="254" type="VARCHAR"/>
        <column name="ALLOW_USER_SET" default="0" type="BIT"/>
        <column name="REQUIRES_CERTIFICATE" default="0" type="BIT"/>
        <unique name="UIX_SITE_URL">
          <unique-column name="URL" />
        </unique>                
    </table>
	
	
    <table name="SSO_SITE_TO_PRINCIPALS">
    	<column name="SITE_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
         <foreign-key foreignTable="SSO_SITE" onDelete="cascade">
            <reference foreign="SITE_ID" local="SITE_ID"/>
        </foreign-key>
       <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="PRINCIPAL_ID"/>
        </foreign-key>
    </table>
    
    <!--
       Create Principals to Remote Principals association Table
    -->
    
    <table name="SSO_PRINCIPAL_TO_REMOTE">
    	<column name="PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="REMOTE_PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
         <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="PRINCIPAL_ID"/>
        </foreign-key>
       <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="REMOTE_PRINCIPAL_ID"/>
        </foreign-key>
    </table>
    
    <table name="SSO_SITE_TO_REMOTE">
    	<column name="SITE_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="PRINCIPAL_ID" primaryKey="true" required="true" type="INTEGER"/>
         <foreign-key foreignTable="SSO_SITE" onDelete="cascade">
            <reference foreign="SITE_ID" local="SITE_ID"/>
        </foreign-key>
       <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="PRINCIPAL_ID"/>
        </foreign-key>
    </table>
         
    <!--
       Create Security User Role Table
    -->
    <table name="SECURITY_USER_ROLE">
        <column name="USER_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="ROLE_ID" primaryKey="true" required="true" type="INTEGER"/>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="ROLE_ID"/>
        </foreign-key>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="USER_ID"/>
        </foreign-key>
    </table>
    
    <!-- 
       Create Security User Group Table
    -->
    <table name="SECURITY_USER_GROUP">
        <column name="USER_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="GROUP_ID" primaryKey="true" required="true" type="INTEGER"/>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="GROUP_ID"/>
        </foreign-key>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="USER_ID"/>
        </foreign-key>
    </table>
    
    <!--
       Create Security Group Role Table
    -->
    <table name="SECURITY_GROUP_ROLE">
        <column name="GROUP_ID" primaryKey="true" required="true" type="INTEGER"/>
        <column name="ROLE_ID" primaryKey="true" required="true" type="INTEGER"/>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="GROUP_ID"/>
        </foreign-key>
        <foreign-key foreignTable="SECURITY_PRINCIPAL" onDelete="cascade">
            <reference foreign="PRINCIPAL_ID" local="ROLE_ID"/>
        </foreign-key>
    </table>

        
    
</database>
