]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1397 roles is tied to a tenant. tenant id is added to role at create time.
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 5 Apr 2010 22:04:44 +0000 (22:04 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 5 Apr 2010 22:04:44 +0000 (22:04 +0000)
test: authz-mgt

M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java
M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java
M    services/authorization/jaxb/src/main/resources/roles.xsd
M    services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql
M    services/authorization/pstore/src/main/resources/db/mysql/test_authorization.sql
M    services/authorization/pstore/src/main/resources/db/mysql/authorization.sql
M    services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java

services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java
services/authorization/jaxb/src/main/resources/roles.xsd
services/authorization/pstore/src/main/resources/db/mysql/authorization.sql
services/authorization/pstore/src/main/resources/db/mysql/authorization_index.sql
services/authorization/pstore/src/main/resources/db/mysql/test_authorization.sql
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java

index b0667ee2f67b082ec787fb6525609cf3defa5930..c01c204e55ab63c1810ad8767f01a753baffe8f4 100644 (file)
@@ -53,10 +53,17 @@ public class RoleDocumentHandler
         String id = UUID.randomUUID().toString();
         Role role = wrapDoc.getWrappedObject();
         role.setCsid(id);
+        //FIXME: if admin updating the role is a CS admin rather than
+        //the tenant admin, tenant id should be retrieved from the request
+        role.setTenantId(getServiceContext().getTenantId());
     }
 
     @Override
     public void handleUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
+        Role role = wrapDoc.getWrappedObject();
+        //FIXME: if admin updating the role is a CS admin rather than
+        //the tenant admin, tenant id should be retrieved from the request
+        role.setTenantId(getServiceContext().getTenantId());
     }
 
     @Override
@@ -103,6 +110,7 @@ public class RoleDocumentHandler
         rolesList.setRoles(list);
         for (Object obj : wrapDoc.getWrappedObject()) {
             Role role = (Role) obj;
+            sanitize(role);
             list.add(role);
         }
         return rolesList;
@@ -148,5 +156,6 @@ public class RoleDocumentHandler
      * @param role
      */
     private void sanitize(Role role) {
+        role.setTenantId(null);
     }
 }
index fcf288797ef9420868a3be6f87cc3201eb395f54..9686fc6175fa9b50b585a552473ecb34a4833c44 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+
 package org.collectionspace.services.authorization.storage;
 
 import org.collectionspace.services.authorization.Role;
index ddf75ef0209cf2e0ff7f9c73906c5d928c7662bf..32e76eaca7260ecbacd3faeb17cab4ce60ef0255 100644 (file)
                     </xs:appinfo>
                 </xs:annotation>
             </xs:element>
+            <xs:element name="tenant_id" type="xs:string" minOccurs="1">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <hj:basic>
+                            <orm:column name="tenant_id" length="128" nullable="false"/>
+                        </hj:basic>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:element>
             <xs:element name="createdAt" type="xs:dateTime">
                 <xs:annotation>
                     <xs:appinfo>
index f4c7e6aac03461b85fe1dccde240e0a83822a83e..33b5cf107b10ee3795de24d271f8a829b18fcb0d 100644 (file)
@@ -7,6 +7,6 @@ drop table if exists users_roles;
 create table permissions (csid varchar(128) not null, attribute_name varchar(128), created_at datetime not null, description varchar(255), effect varchar(32) not null, resource_name varchar(128) not null, updated_at datetime, primary key (csid));
 create table permissions_actions (HJID bigint not null auto_increment, name varchar(128) not null, ACTIONS_PERMISSION_CSID varchar(128), primary key (HJID));
 create table permissions_roles (HJID bigint not null auto_increment, created_at datetime not null, permission_id varchar(128) not null, role_id varchar(128) not null, updated_at datetime, primary key (HJID), unique (permission_id, role_id));
-create table roles (csid varchar(128) not null, created_at datetime not null, description varchar(255), rolegroup varchar(255), rolename varchar(200) not null, updated_at datetime, primary key (csid), unique (rolename));
+create table roles (csid varchar(128) not null, created_at datetime not null, description varchar(255), rolegroup varchar(255), rolename varchar(200) not null, tenant_id varchar(128) not null, updated_at datetime, primary key (csid), unique (rolename));
 create table users_roles (HJID bigint not null auto_increment, created_at datetime not null, role_id varchar(128) not null, updated_at datetime, username varchar(128) not null, primary key (HJID), unique (username, role_id));
 alter table permissions_actions add index FK85F82042E2DC84FD (ACTIONS_PERMISSION_CSID), add constraint FK85F82042E2DC84FD foreign key (ACTIONS_PERMISSION_CSID) references permissions (csid);
index ed1376783acee2470c25739970b3c5b4a57c7a49..6d9a19740fa352d023301abd55868f435bd5d51d 100644 (file)
@@ -6,6 +6,7 @@
 use cspace;
 CREATE INDEX index_rolename ON roles (rolename);
 CREATE INDEX index_rolegroup ON roles (rolegroup);
+CREATE INDEX index_tenant_id ON roles (tenant_id);
 CREATE INDEX index_username ON users_roles (username);
 CREATE INDEX index_role_id ON users_roles (role_id);
 CREATE INDEX index_permission_id ON permissions_roles (permission_id);
index 6972aa1d91566c88cc9a2f8500b34d31d047c9ba..b63777d0ac814337bf22b4b6b254576fc80a8010 100644 (file)
@@ -5,10 +5,10 @@
 --\r
 use cspace;\r
 \r
-insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`) values ('1', 'ROLE_ADMINISTRATOR', 'admin', '2010-02-17 16:31:48');\r
-insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`) values ('2', 'ROLE_USERS', 'collections', '2010-02-17 16:31:48');\r
-insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`) values ('3', 'ROLE_COLLECTIONS_MANAGER', 'collections', '2010-02-17 16:31:48');\r
-insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`) values ('4', 'ROLE_COLLECTIONS_REGISTRAR', 'collections', '2010-02-17 16:31:48');\r
+insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`, `tenant_id`) values ('1', 'ROLE_ADMINISTRATOR', 'admin', '2010-02-17 16:31:48', '0');\r
+insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`, `tenant_id`) values ('2', 'ROLE_USERS', 'collections', '2010-02-17 16:31:48', '1');\r
+insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`, `tenant_id`) values ('3', 'ROLE_COLLECTIONS_MANAGER', 'collections', '2010-02-17 16:31:48', '1');\r
+insert into `roles` (`csid`, `rolename`, `rolegroup`, `created_at`, `tenant_id`) values ('4', 'ROLE_COLLECTIONS_REGISTRAR', 'collections', '2010-02-17 16:31:48', '1');\r
 \r
 insert into `users_roles`(`username`, `role_id`, `created_at`) values ('test', '1', '2010-02-17 16:31:48');\r
 insert into `users_roles`(`username`, `role_id`, `created_at`) values ('test', '2', '2010-02-17 16:31:48');\r
index 6fcb2b57719d5e72d2b4a8f22da212b401c8839c..d9d11e56d7ef1880c248bdc51ab3eb2019155277 100644 (file)
@@ -325,7 +325,6 @@ public class JpaStorageClientImpl implements StorageClient {
             handler.prepare(Action.UPDATE);
             Object entity = handler.getCommonPart();
             setCsid(entity, id);
-            setValue(entity, "setUpdatedAtItem", Date.class, new Date());
             DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(entity);
             handler.handle(Action.UPDATE, wrapDoc);
             emf = getEntityManagerFactory();
@@ -340,7 +339,11 @@ public class JpaStorageClientImpl implements StorageClient {
                 logger.error(msg);
                 throw new DocumentNotFoundException(msg);
             }
-            em.merge(entity);
+            entity = em.merge(entity);
+            setValue(entity, "setUpdatedAtItem", Date.class, new Date());
+            if (logger.isDebugEnabled()) {
+                logger.debug("merged entity=" + entity.toString());
+            }
             em.getTransaction().commit();
             handler.complete(Action.UPDATE, wrapDoc);
         } catch (BadRequestException bre) {