portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r692977 - in /portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java: JETSPEED-INF/ojb/security_repository.xml org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
Date Mon, 08 Sep 2008 01:38:54 GMT
Author: ate
Date: Sun Sep  7 18:38:54 2008
New Revision: 692977

URL: http://svn.apache.org/viewvc?rev=692977&view=rev
Log:
Starting new OJB mapping and access/query handling for JetspeedPrincipal, SecurityAttributes
and JetspeedPrincipalAssociation  

Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml?rev=692977&r1=692976&r2=692977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
Sun Sep  7 18:38:54 2008
@@ -17,134 +17,6 @@
 -->
 
 <descriptor-repository version="1.0">
-
-	<!--
-	   - S E C U R I T Y  U S E R
-	-->	
-	<class-descriptor
-	    class="org.apache.jetspeed.security.om.impl.InternalUserPrincipalImpl"
-	    proxy="dynamic"
-	    table="SECURITY_PRINCIPAL"
-	>
-	    <documentation>Represents a user principal.</documentation>
-	    <field-descriptor
-	        name="principalId"
-	        column="principal_id"
-	        jdbc-type="BIGINT"
-	        primarykey="true"
-	        indexed="true"
-	        autoincrement="true"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="classname"
-	        column="classname"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="254"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="isMappingOnly"
-	        column="is_mapping_only"
-	        jdbc-type="INTEGER"
-	        conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="type"
-	        column="sp_type"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="20"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="name"
-	        column="sp_name"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="200"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="creationDate"
-	        column="creation_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="modifiedDate"
-	        column="modified_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-      <field-descriptor
-          name="enabled"
-          column="is_enabled"
-          jdbc-type="INTEGER"
-          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-          nullable="false"
-      > 
-      </field-descriptor>      
-	    <collection-descriptor
-	        name="credentials"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalCredentialImpl"
-          proxy="true"
-          refresh="true"          
-	        auto-retrieve="true"
-	        auto-update="object"
-	        auto-delete="object"
-	    >
-	        <documentation>This is the reference to security credentials.</documentation>
-	        <inverse-foreignkey field-ref="principalId"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="rolePrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalRolePrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_USER_ROLE"
-	    >
-	        <documentation>This is the reference to role principals.</documentation>
-	        <fk-pointing-to-this-class column="USER_ID"/>
-	        <fk-pointing-to-element-class column="ROLE_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="groupPrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalGroupPrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_USER_GROUP"
-	    >
-	        <documentation>This is the reference to group principals.</documentation>
-	        <fk-pointing-to-this-class column="USER_ID"/>
-	        <fk-pointing-to-element-class column="GROUP_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="permissions"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalPermissionImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="PRINCIPAL_PERMISSION"
-	    >
-	        <documentation>This is the reference to a policy permission.</documentation>
-	        <fk-pointing-to-this-class column="PRINCIPAL_ID"/>
-	        <fk-pointing-to-element-class column="PERMISSION_ID"/>
-	    </collection-descriptor>
-	</class-descriptor>
 	
 	<!--
 	   - S E C U R I T Y  C R E D E N T I A L
@@ -269,326 +141,6 @@
 	</class-descriptor>
 	
 	<!--
-	   - S E C U R I T Y  R O L E
-	-->	
-	<class-descriptor
-	    class="org.apache.jetspeed.security.om.impl.InternalRolePrincipalImpl"
-	    proxy="dynamic"
-	    table="SECURITY_PRINCIPAL"
-	>
-	    <documentation>Represents a role principal.</documentation>
-		<field-descriptor
-	        name="principalId"
-	        column="principal_id"
-	        jdbc-type="BIGINT"
-	        primarykey="true"
-	        indexed="true"
-	        autoincrement="true"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="classname"
-	        column="classname"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="254"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="isMappingOnly"
-	        column="is_mapping_only"
-	        jdbc-type="INTEGER"
-	        conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="type"
-	        column="sp_type"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="20"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="name"
-	        column="sp_name"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="200"
-	    >
-	    </field-descriptor>	    	    
-	    <field-descriptor
-	        name="creationDate"
-	        column="creation_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="modifiedDate"
-	        column="modified_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-      <field-descriptor
-          name="enabled"
-          column="is_enabled"
-          jdbc-type="INTEGER"
-          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-          nullable="false"
-      >
-      </field-descriptor>      
-	    <collection-descriptor
-	        name="userPrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalUserPrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_USER_ROLE"
-	    >
-	        <documentation>This is the reference to user principals.</documentation>
-	        <fk-pointing-to-this-class column="ROLE_ID"/>
-	        <fk-pointing-to-element-class column="USER_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="groupPrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalGroupPrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_GROUP_ROLE"
-	    >
-	        <documentation>This is the reference to group principals.</documentation>
-	        <fk-pointing-to-this-class column="ROLE_ID"/>
-	        <fk-pointing-to-element-class column="GROUP_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="permissions"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalPermissionImpl"
-	        proxy="false"
-	        refresh="false"
-	        auto-retrieve="false"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="PRINCIPAL_PERMISSION"
-	    >
-	        <documentation>This is the reference to a policy permission.</documentation>
-	        <fk-pointing-to-this-class column="PRINCIPAL_ID"/>
-	        <fk-pointing-to-element-class column="PERMISSION_ID"/>
-	    </collection-descriptor>
-	</class-descriptor>
-	
-	<!--
-	   - S E C U R I T Y  G R O U P
-	-->	
-	<class-descriptor
-	    class="org.apache.jetspeed.security.om.impl.InternalGroupPrincipalImpl"
-	    proxy="dynamic"
-	    table="SECURITY_PRINCIPAL"
-	>
-	    <documentation>Represents a group principal.</documentation>
-		<field-descriptor
-	        name="principalId"
-	        column="principal_id"
-	        jdbc-type="BIGINT"
-	        primarykey="true"
-	        indexed="true"
-	        autoincrement="true"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="classname"
-	        column="classname"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="254"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="isMappingOnly"
-	        column="is_mapping_only"
-	        jdbc-type="INTEGER"
-	        conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-	        nullable="false"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="type"
-	        column="sp_type"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="20"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="name"
-	        column="sp_name"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="200"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="creationDate"
-	        column="creation_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="modifiedDate"
-	        column="modified_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-      <field-descriptor
-          name="enabled"
-          column="is_enabled"
-          jdbc-type="INTEGER"
-          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-          nullable="false"
-      >
-      </field-descriptor>      
-	    <collection-descriptor
-	        name="userPrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalUserPrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_USER_GROUP"
-	    >
-	        <documentation>This is the reference to user principals.</documentation>
-	        <fk-pointing-to-this-class column="GROUP_ID"/>
-	        <fk-pointing-to-element-class column="USER_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="rolePrincipals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalRolePrincipalImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="SECURITY_GROUP_ROLE"
-	    >
-	        <documentation>This is the reference to group principals.</documentation>
-	        <fk-pointing-to-this-class column="GROUP_ID"/>
-	        <fk-pointing-to-element-class column="ROLE_ID"/>
-	    </collection-descriptor>
-	    <collection-descriptor
-	        name="permissions"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalPermissionImpl"
-	        proxy="false"
-	        refresh="false"
-	        auto-retrieve="false"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="PRINCIPAL_PERMISSION"
-	    >
-	        <documentation>This is the reference to a policy permission.</documentation>
-	        <fk-pointing-to-this-class column="PRINCIPAL_ID"/>
-	        <fk-pointing-to-element-class column="PERMISSION_ID"/>
-	    </collection-descriptor>
-	</class-descriptor>
-	
-	<!--
-	   - S E C U R I T Y  P R I N C I P A L
-	-->	
-	<class-descriptor
-	    class="org.apache.jetspeed.security.om.impl.InternalPrincipalImpl"
-	    proxy="dynamic"
-	    table="SECURITY_PRINCIPAL"
-	>
-	    <documentation>Represents a security principal in the security policy.</documentation>
-	    <field-descriptor
-	        name="principalId"
-	        column="principal_id"
-	        jdbc-type="BIGINT"
-	        primarykey="true"
-	        indexed="true"
-	        autoincrement="true"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="classname"
-	        column="classname"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="254"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="isMappingOnly"
-	        column="is_mapping_only"
-	        jdbc-type="INTEGER"
-	        conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="type"
-	        column="sp_type"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="20"
-	    >
-	    </field-descriptor>	    
-	    <field-descriptor
-	        name="name"
-	        column="sp_name"
-	        jdbc-type="VARCHAR"
-	        nullable="false"
-	        length="200"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="creationDate"
-	        column="creation_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-	    <field-descriptor
-	        name="modifiedDate"
-	        column="modified_date"
-	        jdbc-type="TIMESTAMP"
-	        nullable="false"
-	    >
-	    </field-descriptor>
-      <field-descriptor
-          name="enabled"
-          column="is_enabled"
-          jdbc-type="INTEGER"
-          conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
-          nullable="false"
-      >
-      </field-descriptor>      
-	    <collection-descriptor
-	        name="permissions"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalPermissionImpl"
-	        proxy="true"
-	        refresh="true"
-	        auto-retrieve="true"
-	        auto-update="link"
-	        auto-delete="link"
-	        indirection-table="PRINCIPAL_PERMISSION"
-	    >
-	        <documentation>This is the reference to a policy permission.</documentation>
-	        <fk-pointing-to-this-class column="PRINCIPAL_ID"/>
-	        <fk-pointing-to-element-class column="PERMISSION_ID"/>
-	    </collection-descriptor>
-	</class-descriptor>
-	
-	<!--
 	   - S E C U R I T Y  P E R M I S S I O N
 	-->	
 	<class-descriptor
@@ -646,7 +198,7 @@
 	    </field-descriptor>
 	        <collection-descriptor
 	        name="principals"
-	        element-class-ref="org.apache.jetspeed.security.om.impl.InternalPrincipalImpl"
+	        element-class-ref="org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal"
 	        proxy="true"
 	        refresh="true"
 	        auto-retrieve="true"
@@ -661,59 +213,19 @@
 	</class-descriptor>
 
 
-   <!--
-   - S E C U R I T Y   A T T R I B U T E S ( D E P R E C A T E D )
-   -->
-  <class-descriptor
-      class="org.apache.jetspeed.security.attributes.SecurityAttributeImpl"
-      table="security_attributes"
-  >
-      <documentation>Represents a Security Principal Attribute definition.</documentation>
-      <field-descriptor
-          name="attributeId"
-          column="attr_id"
-          jdbc-type="BIGINT"
-          primarykey="true"
-          autoincrement="true"
-      />
-      <field-descriptor
-          name="principalId"
-          column="principal_id"
-          jdbc-type="BIGINT"
-          nullable="false"
-      />
-      <field-descriptor
-          name="name"
-          column="attr_name"
-          jdbc-type="VARCHAR"
-          nullable="false"
-          length="200"
-      />
-      <field-descriptor
-          name="type"
-          column="attr_type"
-          jdbc-type="VARCHAR"
-          nullable="false"
-          length="20"
-      />
-      <field-descriptor
-          name="value"
-          column="attr_value"
-          jdbc-type="VARCHAR"
-          nullable="true"
-          length="1000"
-      />      
-  </class-descriptor>
-
-
   <!--
      - J E T S P E E D   P R I N C I P A L
   --> 
   <class-descriptor
-      class="org.apache.jetspeed.security.impl.BaseJetspeedPrincipal"
+      class="org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal"
       table="SECURITY_PRINCIPAL"
-  >
+  >  
       <documentation>Represents a security principal in the security policy.</documentation>
+      
+      <extend-class class-ref="org.apache.jetspeed.security.impl.UserImpl"/>
+      <extend-class class-ref="org.apache.jetspeed.security.impl.RoleImpl"/>
+      <extend-class class-ref="org.apache.jetspeed.security.impl.GroupImpl"/>
+      
       <field-descriptor
           name="id"
           column="principal_id"
@@ -729,7 +241,7 @@
           jdbc-type="VARCHAR"
           nullable="false"
           conversion="org.apache.jetspeed.security.util.ojb.JetspeedPrincipalTypeFieldConversion"
-          length="20"
+          length="30"
       >
       </field-descriptor>     
       <field-descriptor
@@ -787,15 +299,32 @@
       >
       </field-descriptor>      
       <collection-descriptor
-          name="attributeValues"
+          name="attributes"
           element-class-ref="org.apache.jetspeed.security.impl.SecurityAttributeValue"
-          refresh="true"
           auto-retrieve="true"
           auto-update="true"
           auto-delete="none"
       >
         <inverse-foreignkey field-ref="principalId"/>
       </collection-descriptor>
+      <collection-descriptor
+          name="associationsFrom"
+          element-class-ref="org.apache.jetspeed.security.spi.JetspeedPrincipalAssociation"
+          auto-retrieve="false"
+          auto-update="none"
+          auto-delete="none"
+      >
+        <inverse-foreignkey field-ref="fromPrincipalId"/>
+      </collection-descriptor>
+      <collection-descriptor
+          name="associationsTo"
+          element-class-ref="org.apache.jetspeed.security.spi.JetspeedPrincipalAssociation"
+          auto-retrieve="false"
+          auto-update="none"
+          auto-delete="none"
+      >
+        <inverse-foreignkey field-ref="toPrincipalId"/>
+      </collection-descriptor>
   </class-descriptor>
   
    <!--
@@ -803,7 +332,7 @@
    -->
   <class-descriptor
       class="org.apache.jetspeed.security.SecurityAttributeValue"
-      table="security_attributes"
+      table="SECURITY_ATTRIBUTE"
   >
       <documentation>Represents a Security Principal Attribute definition.</documentation>
       <field-descriptor
@@ -836,4 +365,48 @@
       />      
   </class-descriptor>
 
+
+   <!--
+   - J E T S P E E D   P R I N C I P A L   A S S O C I A T I O N
+   -->
+  <class-descriptor
+      class="org.apache.jetspeed.security.spi.JetspeedPrincipalAssociation"
+      table="SECURITY_PRINCIPAL_ASSOC"
+  >
+      <documentation>Represents an association between two Security Principals</documentation>
+      <field-descriptor
+          name="fromPrincipalId"
+          column="from_principal_id"
+          jdbc-type="BIGINT"
+          primarykey="true"
+          access="anonymous"
+      />
+      <field-descriptor
+          name="toPrincipalId"
+          column="to_principal_id"
+          jdbc-type="BIGINT"
+          primarykey="true"
+          access="anonymous"
+      />
+      <field-descriptor
+          name="associationName"
+          column="assoc_name"
+          jdbc-type="VARCHAR"
+          length="30"
+          primarykey="true"
+      />
+      <reference-descriptor
+         name="from"
+         class-ref="org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal"
+      >
+         <foreignkey field-ref="fromPrincipalId"/>
+      </reference-descriptor>
+      <reference-descriptor
+         name="to"
+         class-ref="org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal"
+      >
+         <foreignkey field-ref="toPrincipalId"/>
+      </reference-descriptor>
+  </class-descriptor>
+
 </descriptor-repository>

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java?rev=692977&r1=692976&r2=692977&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
Sun Sep  7 18:38:54 2008
@@ -16,10 +16,13 @@
  */
 package org.apache.jetspeed.security.spi.impl;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.jetspeed.security.DependentPrincipalException;
+import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
+import org.apache.jetspeed.i18n.KeyedMessage;
 import org.apache.jetspeed.security.JetspeedPermission;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationReference;
@@ -27,106 +30,189 @@
 import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.security.PortalResourcePermission;
 import org.apache.jetspeed.security.PrincipalAlreadyExistsException;
-import org.apache.jetspeed.security.PrincipalAssociationNotAllowedException;
-import org.apache.jetspeed.security.PrincipalAssociationRequiredException;
-import org.apache.jetspeed.security.PrincipalAssociationUnsupportedException;
 import org.apache.jetspeed.security.PrincipalNotFoundException;
 import org.apache.jetspeed.security.PrincipalNotRemovableException;
 import org.apache.jetspeed.security.PrincipalUpdateException;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal;
 import org.apache.jetspeed.security.spi.JetspeedPermissionStorageManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalAssociationStorageManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalPermissionStorageManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager;
 import org.apache.jetspeed.security.spi.UserPasswordCredentialStorageManager;
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.ReportQueryByCriteria;
+import org.apache.ojb.broker.util.collections.ManageableArrayList;
+import org.springframework.dao.DataIntegrityViolationException;
 
 /**
  * @version $Id$
  */
-public class JetspeedSecurityPersistenceManager implements JetspeedPrincipalAccessManager,
+public class JetspeedSecurityPersistenceManager
+    extends InitablePersistenceBrokerDaoSupport
+    implements JetspeedPrincipalAccessManager,
                 JetspeedPrincipalStorageManager, UserPasswordCredentialStorageManager,
                 JetspeedPrincipalAssociationStorageManager, JetspeedPrincipalPermissionStorageManager,
                 JetspeedPermissionStorageManager
 {
+    public JetspeedSecurityPersistenceManager(String repositoryPath)
+    {
+        super(repositoryPath);
+    }
+    
     //
     // JetspeedPrincipalAccessManager interface implementation
     //
     public List<JetspeedPrincipal> getAssociatedFrom(String principalFromName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsTo.associationName", associationName);
+        criteria.addEqualTo("associationsTo.from.name", principalFromName);
+        Query query = QueryFactory.newQuery(to.getPrincipalClass(), criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
-    public List<JetspeedPrincipal> getAssociatedFrom(Long principalFromId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<JetspeedPrincipal> getAssociatedTo(String principalToName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsFrom.associationName", associationName);
+        criteria.addEqualTo("associationsFrom.to.name", principalToName);
+        Query query = QueryFactory.newQuery(from.getPrincipalClass(), criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
-    public List<String> getAssociatedNamesFrom(String principalFromName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<JetspeedPrincipal> getAssociatedFrom(Long principalFromId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsTo.associationName", associationName);
+        criteria.addEqualTo("associationsTo.from.id", principalFromId);
+        Query query = QueryFactory.newQuery(to.getPrincipalClass(), criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
-    public List<String> getAssociatedNamesFrom(Long principalFromId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<JetspeedPrincipal> getAssociatedTo(Long principalToId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsFrom.associationName", associationName);
+        criteria.addEqualTo("associationsFrom.to.id", principalToId);
+        Query query = QueryFactory.newQuery(from.getPrincipalClass(), criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
-    public List<String> getAssociatedNamesTo(String principalToName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<String> getAssociatedNamesFrom(String principalFromName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsTo.associationName", associationName);
+        criteria.addEqualTo("associationsTo.from.name", principalFromName);
+        ReportQueryByCriteria query = QueryFactory.newReportQuery(to.getPrincipalClass(),
criteria);
+        query.setAttributes(new String[]{"name"});
+        ArrayList<String> names = new ArrayList<String>();
+        for (Iterator<Object[]> iter = getPersistenceBroker(true).getReportQueryIteratorByQuery(query);
iter.hasNext(); )
+        {
+            names.add((String)iter.next()[0]);
+        }
+        return names;
     }
 
-    public List<String> getAssociatedNamesTo(Long principalToId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<String> getAssociatedNamesFrom(Long principalFromId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsTo.associationName", associationName);
+        criteria.addEqualTo("associationsTo.from.id", principalFromId);
+        ReportQueryByCriteria query = QueryFactory.newReportQuery(to.getPrincipalClass(),
criteria);
+        query.setAttributes(new String[]{"name"});
+        ArrayList<String> names = new ArrayList<String>();
+        for (Iterator<Object[]> iter = getPersistenceBroker(true).getReportQueryIteratorByQuery(query);
iter.hasNext(); )
+        {
+            names.add((String)iter.next()[0]);
+        }
+        return names;
     }
 
-    public List<JetspeedPrincipal> getAssociatedTo(String principalToName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<String> getAssociatedNamesTo(String principalToName, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsFrom.associationName", associationName);
+        criteria.addEqualTo("associationsFrom.to.name", principalToName);
+        ReportQueryByCriteria query = QueryFactory.newReportQuery(from.getPrincipalClass(),
criteria);
+        query.setAttributes(new String[]{"name"});
+        ArrayList<String> names = new ArrayList<String>();
+        for (Iterator<Object[]> iter = getPersistenceBroker(true).getReportQueryIteratorByQuery(query);
iter.hasNext(); )
+        {
+            names.add((String)iter.next()[0]);
+        }
+        return names;
     }
 
-    public List<JetspeedPrincipal> getAssociatedTo(Long principalToId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
+    public List<String> getAssociatedNamesTo(Long principalToId, JetspeedPrincipalType
from, JetspeedPrincipalType to, String associationName)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("associationsFrom.associationName", associationName);
+        criteria.addEqualTo("associationsFrom.to.id", principalToId);
+        ReportQueryByCriteria query = QueryFactory.newReportQuery(from.getPrincipalClass(),
criteria);
+        query.setAttributes(new String[]{"name"});
+        ArrayList<String> names = new ArrayList<String>();
+        for (Iterator<Object[]> iter = getPersistenceBroker(true).getReportQueryIteratorByQuery(query);
iter.hasNext(); )
+        {
+            names.add((String)iter.next()[0]);
+        }
+        return names;
     }
 
     public JetspeedPrincipal getPrincipal(Long id)
-    {
-        // TODO Auto-generated method stub
-        return null;
+    {        
+        Identity oid = getPersistenceBroker(true).serviceIdentity().buildIdentity(PersistentJetspeedPrincipal.class,
id);
+        return (JetspeedPrincipal)getPersistenceBroker(true).getObjectByIdentity(oid);
     }
 
     public JetspeedPrincipal getPrincipal(String principalName, JetspeedPrincipalType type)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("name", principalName);
+        Query query = QueryFactory.newQuery(type.getPrincipalClass(),criteria);
+        return (JetspeedPrincipal)getPersistenceBrokerTemplate().getObjectByQuery(query);
     }
 
     public List<String> getPrincipalNames(String nameFilter, JetspeedPrincipalType
type)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        if (nameFilter != null && nameFilter.length() > 0)
+        {
+            criteria.addLike("name", nameFilter+"%");
+        }
+        ReportQueryByCriteria query = QueryFactory.newReportQuery(type.getPrincipalClass(),criteria);
+        query.setAttributes(new String[]{"name"});
+        ArrayList<String> names = new ArrayList<String>();
+        for (Iterator<Object[]> iter = getPersistenceBroker(true).getReportQueryIteratorByQuery(query);
iter.hasNext(); )
+        {
+            names.add((String)iter.next()[0]);
+        }
+        return names;
     }
 
     public List<JetspeedPrincipal> getPrincipals(String nameFilter, JetspeedPrincipalType
type)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        if (nameFilter != null && nameFilter.length() > 0)
+        {
+            criteria.addLike("name", nameFilter+"%");
+        }
+        Query query = QueryFactory.newQuery(type.getPrincipalClass(),criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
     public List<JetspeedPrincipal> getPrincipalsByAttribute(String attributeName, String
attributeValue, JetspeedPrincipalType type)
     {
-        // TODO Auto-generated method stub
-        return null;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("attributes.name", attributeName);
+        criteria.addEqualTo("attributes.value", attributeValue);
+        Query query = QueryFactory.newQuery(type.getPrincipalClass(),criteria);
+        return (List<JetspeedPrincipal>) getPersistenceBroker(true).getCollectionByQuery(ManageableArrayList.class,
query);
     }
 
     public List<String> getPrincipals(JetspeedPermission permission)
@@ -143,73 +229,179 @@
 
     public boolean principalExists(String principalName, JetspeedPrincipalType type)
     {
-        // TODO Auto-generated method stub
-        return false;
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("name", principalName);
+        Query query = QueryFactory.newQuery(type.getPrincipalClass(),criteria);
+        return getPersistenceBroker(true).getCount(query) == 1;
+    }
+
+    public boolean principalExists(JetspeedPrincipal principal)
+    {
+        if (principal.getId() == null)
+        {
+            return principalExists(principal.getName(), principal.getType());
+        }
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("id", principal.getId());
+        Query query = QueryFactory.newQuery(principal.getType().getPrincipalClass(),criteria);
+        return getPersistenceBroker(true).getCount(query) == 1;
     }
 
     //
     // JetspeedPrincipalStorageManager interface implementation
     //
     public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference>
associations)
-                                                                                        
                         throws PrincipalAlreadyExistsException,
-                                                                                        
                         PrincipalAssociationRequiredException
+        throws PrincipalAlreadyExistsException
     {
-        // TODO Auto-generated method stub
+        if (principalExists(principal))
+        {
+            throw new PrincipalAlreadyExistsException();
+        }
+        try
+        {
+            getPersistenceBrokerTemplate().store(principal);
+        }
+        catch (Exception pbe)
+        {
+            KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
+                                                                   "addPrincipal",
+                                                                   pbe.getMessage());
+            logger.error(msg, pbe);
+            throw new RuntimeException(new SecurityException(msg, pbe));            
+        }
+        // Note: the (optional) required associations are expected to be stored by the calling
JetspeedPrincipalManager
     }
 
     public boolean isMapped()
     {
-        // TODO Auto-generated method stub
         return false;
     }
 
     public void removePrincipal(JetspeedPrincipal principal) throws PrincipalNotFoundException,
-                                                            PrincipalNotRemovableException,
DependentPrincipalException
+                                                            PrincipalNotRemovableException
     {
-        // TODO Auto-generated method stub
+        if (!principalExists(principal))
+        {
+            throw new PrincipalNotFoundException();
+        }
+        try
+        {
+            getPersistenceBrokerTemplate().delete(principal);
+        }
+        catch (Exception pbe)
+        {
+            if (pbe instanceof DataIntegrityViolationException)
+            {
+                logger.error(pbe.getMessage(), pbe);
+                throw new PrincipalNotRemovableException();
+            }
+            
+            KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
+                                                                   "removePrincipal",
+                                                                   pbe.getMessage());
+            logger.error(msg, pbe);
+            throw new RuntimeException(new SecurityException(msg, pbe));            
+        }
     }
 
     public void updatePrincipal(JetspeedPrincipal principal) throws PrincipalUpdateException,
                                                             PrincipalNotFoundException
     {
-        // TODO Auto-generated method stub
+        if (!principalExists(principal))
+        {
+            throw new PrincipalNotFoundException();
+        }
+        try
+        {
+            getPersistenceBrokerTemplate().store(principal);
+        }
+        catch (Exception pbe)
+        {
+            if (pbe instanceof DataIntegrityViolationException)
+            {
+                logger.error(pbe.getMessage(), pbe);
+                throw new PrincipalUpdateException();
+            }
+            
+            KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
+                                                                   "removePrincipal",
+                                                                   pbe.getMessage());
+            logger.error(msg, pbe);
+            throw new RuntimeException(new SecurityException(msg, pbe));            
+        }
     }
 
     //
     // JetspeedPrincipalStorageManager interface implementation
     //
-    public void addCredential(PasswordCredential credential)
-    {
-        // TODO Auto-generated method stub
-    }
-
-    public void removeCredential(PasswordCredential credential)
+    public PasswordCredential getPasswordCredential(User user)
     {
         // TODO Auto-generated method stub
+        return null;
     }
 
-    public void updateCredential(PasswordCredential credential)
+    public void storePasswordCredential(PasswordCredential credential) throws SecurityException
     {
         // TODO Auto-generated method stub
+        
     }
 
     //
     // JetspeedPrincipalAssociationStorageManager interface implementation
     //
     public void addAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName)
-                                                                                        
           throws PrincipalNotFoundException,
-                                                                                        
           PrincipalAssociationUnsupportedException,
-                                                                                        
           PrincipalAssociationNotAllowedException
+        throws PrincipalNotFoundException
     {
-        // TODO Auto-generated method stub
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("fromPrincipalId", from.getId());
+        criteria.addEqualTo("toPrincipalId", to.getId());
+        criteria.addEqualTo("associationName", associationName);
+        Query query = QueryFactory.newQuery(JetspeedPrincipalAssociation.class,criteria);
+        if (getPersistenceBroker(true).getCount(query) == 0)
+        {
+            try
+            {
+                getPersistenceBrokerTemplate().store(new JetspeedPrincipalAssociation(from,
to, associationName));
+            }
+            catch (Exception pbe)
+            {
+                if (pbe instanceof DataIntegrityViolationException)
+                {
+                    logger.error(pbe.getMessage(), pbe);
+                    throw new PrincipalNotFoundException();
+                }
+                
+                KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
+                                                                       "addAssociation",
+                                                                       pbe.getMessage());
+                logger.error(msg, pbe);
+                throw new RuntimeException(new SecurityException(msg, pbe));
+            }
+        }
     }
 
     public void removeAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName)
-                                                                                        
              throws PrincipalNotFoundException,
-                                                                                        
              PrincipalAssociationUnsupportedException,
-                                                                                        
              PrincipalAssociationRequiredException
     {
-        // TODO Auto-generated method stub
+        Criteria criteria = new Criteria();
+        criteria.addEqualTo("fromPrincipalId", from.getId());
+        criteria.addEqualTo("toPrincipalId", to.getId());
+        criteria.addEqualTo("associationName", associationName);
+        Query query = QueryFactory.newQuery(JetspeedPrincipalAssociation.class,criteria);
+        if (getPersistenceBroker(true).getCount(query) != 0)
+        {
+            try
+            {
+                getPersistenceBrokerTemplate().delete(new JetspeedPrincipalAssociation(from,
to, associationName));
+            }
+            catch (Exception pbe)
+            {
+                KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager",
+                                                                       "removeAssociation",
+                                                                       pbe.getMessage());
+                logger.error(msg, pbe);
+                throw new RuntimeException(new SecurityException(msg, pbe));
+            }
+        }
     }
 
     //



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


Mime
View raw message