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
rolesList.setRoles(list);
for (Object obj : wrapDoc.getWrappedObject()) {
Role role = (Role) obj;
+ sanitize(role);
list.add(role);
}
return rolesList;
* @param role
*/
private void sanitize(Role role) {
+ role.setTenantId(null);
}
}
* 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;
</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>
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);
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);
--\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
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();
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) {