Get rid of security profiles and subjects

This commit is contained in:
Konstantin Krivopustov 2009-02-15 20:06:57 +00:00
parent c4279a546f
commit 11fe9d7e87
59 changed files with 570 additions and 1132 deletions

View File

@ -3,12 +3,12 @@
create table SYS_SERVER (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
NAME varchar(255),
ADDRESS varchar(255),
IS_RUNNING smallint,
@ -20,10 +20,10 @@ create table SYS_SERVER (
create table SYS_CONFIG (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
NAME varchar(255),
VALUE varchar(500),
primary key (ID)
@ -33,35 +33,15 @@ alter table SYS_CONFIG add constraint SYS_CONFIG_UNIQ_NAME unique (NAME)^
------------------------------------------------------------------------------------------------------------
create table SEC_USER (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
DELETE_TS datetime,
DELETED_BY binary(16),
LOGIN varchar(20),
PASSWORD varchar(32),
NAME varchar(255),
AD_USER varchar(100),
primary key (ID)
)^
alter table SEC_USER add constraint SEC_USER_UNIQ_LOGIN unique (LOGIN, DELETE_TS)^
------------------------------------------------------------------------------------------------------------
create table SEC_ROLE (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
NAME varchar(255),
IS_SUPER smallint,
primary key (ID)
@ -74,12 +54,12 @@ alter table SEC_ROLE add constraint SEC_ROLE_UNIQ_NAME unique (NAME, DELETE_TS)^
create table SEC_GROUP (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
NAME varchar(255),
PARENT_ID binary(16),
primary key (ID)
@ -92,7 +72,7 @@ alter table SEC_GROUP add constraint SEC_GROUP_PARENT foreign key (PARENT_ID) re
create table SEC_GROUP_HIERARCHY (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
GROUP_ID binary(16),
PARENT_ID binary(16),
LEVEL integer,
@ -105,78 +85,60 @@ alter table SEC_GROUP_HIERARCHY add constraint SEC_GROUP_HIERARCHY_PARENT foreig
------------------------------------------------------------------------------------------------------------
create table SEC_PROFILE (
create table SEC_USER (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
LOGIN varchar(20),
PASSWORD varchar(32),
NAME varchar(255),
AD_USER varchar(100),
GROUP_ID binary(16),
primary key (ID)
)^
alter table SEC_PROFILE add constraint SEC_PROFILE_GROUP foreign key (GROUP_ID) references SEC_GROUP(ID)^
alter table SEC_USER add constraint SEC_USER_UNIQ_LOGIN unique (LOGIN, DELETE_TS)^
alter table SEC_USER add constraint SEC_USER_GROUP foreign key (GROUP_ID) references SEC_GROUP(ID)^
------------------------------------------------------------------------------------------------------------
create table SEC_SUBJECT (
create table SEC_USER_ROLE (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATE_TS timestamp,
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
DELETE_TS datetime,
DELETED_BY binary(16),
IS_DEFAULT smallint,
UPDATE_TS timestamp,
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(20),
USER_ID binary(16),
PROFILE_ID binary(16),
START_DATE datetime,
END_DATE datetime,
primary key (ID)
)^
alter table SEC_SUBJECT add constraint SEC_SUBJECT_USER foreign key (USER_ID) references SEC_USER(ID)^
alter table SEC_SUBJECT add constraint SEC_SUBJECT_PROFILE foreign key (PROFILE_ID) references SEC_PROFILE(ID)^
------------------------------------------------------------------------------------------------------------
create table SEC_PROFILE_ROLE (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
DELETE_TS datetime,
DELETED_BY binary(16),
PROFILE_ID binary(16),
ROLE_ID binary(16),
primary key (ID)
)^
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_ROLE_PROFILE foreign key (PROFILE_ID) references SEC_PROFILE(ID)^
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_PROFILE foreign key (USER_ID) references SEC_USER(ID)^
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_ROLE_ROLE foreign key (ROLE_ID) references SEC_ROLE(ID)^
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_ROLE foreign key (ROLE_ID) references SEC_ROLE(ID)^
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_UNIQ_ROLE unique (PROFILE_ID, ROLE_ID, DELETE_TS)^
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_UNIQ_ROLE unique (USER_ID, ROLE_ID, DELETE_TS)^
------------------------------------------------------------------------------------------------------------
create table SEC_PERMISSION (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
TYPE integer,
TARGET varchar(100),
VALUE integer,
@ -193,12 +155,12 @@ alter table SEC_PERMISSION add constraint SEC_PERMISSION_UNIQUE unique (ROLE_ID,
create table SEC_CONSTRAINT (
ID binary(16),
CREATE_TS datetime,
CREATED_BY binary(16),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS datetime,
UPDATED_BY binary(16),
UPDATED_BY varchar(20),
DELETE_TS datetime,
DELETED_BY binary(16),
DELETED_BY varchar(20),
ENTITY_NAME varchar(50),
WHERE_CLAUSE varchar(500),
GROUP_ID binary(16),
@ -221,20 +183,14 @@ end^
------------------------------------------------------------------------------------------------------------
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME)
values (to_id('60885987-1b61-4247-94c7-dff348347f93'), current_timestamp, 0, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator')^
insert into SEC_GROUP (ID, CREATE_TS, VERSION, NAME, PARENT_ID)
values (to_id('0fa2b1a5-1d68-4d69-9fbd-dff348347f93'), current_timestamp, 0, 'Company', null)^
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, GROUP_ID)
values (to_id('bf83541f-f610-46f4-a268-dff348347f93'), current_timestamp, 0, 'Default', to_id('0fa2b1a5-1d68-4d69-9fbd-dff348347f93'))^
insert into SEC_SUBJECT (ID, CREATE_TS, VERSION, IS_DEFAULT, USER_ID, PROFILE_ID)
values (to_id('05d9d689-da68-4622-8952-f94dfb36ca07'), current_timestamp, 0, 1, to_id('60885987-1b61-4247-94c7-dff348347f93'), to_id('bf83541f-f610-46f4-a268-dff348347f93'))^
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME, GROUP_ID)
values (to_id('60885987-1b61-4247-94c7-dff348347f93'), current_timestamp, 0, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator', to_id('0fa2b1a5-1d68-4d69-9fbd-dff348347f93'))^
insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME, IS_SUPER)
values (to_id('0c018061-b26f-4de2-a5be-dff348347f93'), current_timestamp, 0, 'Administrators', 1)^
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
values (to_id('c838be0a-96d0-4ef4-a7c0-dff348347f93'), current_timestamp, 0, to_id('bf83541f-f610-46f4-a268-dff348347f93'), to_id('0c018061-b26f-4de2-a5be-dff348347f93'))^
insert into SEC_USER_ROLE (ID, CREATE_TS, VERSION, USER_ID, ROLE_ID)
values (to_id('c838be0a-96d0-4ef4-a7c0-dff348347f93'), current_timestamp, 0, to_id('60885987-1b61-4247-94c7-dff348347f93'), to_id('0c018061-b26f-4de2-a5be-dff348347f93'))^

View File

@ -3,12 +3,12 @@
create table SYS_SERVER (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
NAME varchar(255),
ADDRESS varchar(255),
IS_RUNNING smallint,
@ -20,10 +20,10 @@ create table SYS_SERVER (
create table SYS_CONFIG (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
NAME varchar(255),
VALUE varchar(500),
primary key (ID)
@ -33,35 +33,15 @@ alter table SYS_CONFIG add constraint SYS_CONFIG_UNIQ_NAME unique (NAME);
------------------------------------------------------------------------------------------------------------
create table SEC_USER (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
DELETE_TS timestamp,
DELETED_BY varchar(36),
LOGIN varchar(20),
PASSWORD varchar(32),
NAME varchar(255),
AD_USER varchar(100),
primary key (ID)
);
alter table SEC_USER add constraint SEC_USER_UNIQ_LOGIN unique (LOGIN, DELETE_TS);
------------------------------------------------------------------------------------------------------------
create table SEC_ROLE (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
NAME varchar(255),
IS_SUPER smallint,
primary key (ID)
@ -74,12 +54,12 @@ alter table SEC_ROLE add constraint SEC_ROLE_UNIQ_NAME unique (NAME, DELETE_TS);
create table SEC_GROUP (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
NAME varchar(255),
PARENT_ID varchar(36),
primary key (ID)
@ -92,7 +72,7 @@ alter table SEC_GROUP add constraint SEC_GROUP_PARENT foreign key (PARENT_ID) re
create table SEC_GROUP_HIERARCHY (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
GROUP_ID varchar(36),
PARENT_ID varchar(36),
LEVEL integer,
@ -105,78 +85,60 @@ alter table SEC_GROUP_HIERARCHY add constraint SEC_GROUP_HIERARCHY_PARENT foreig
------------------------------------------------------------------------------------------------------------
create table SEC_PROFILE (
create table SEC_USER (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
LOGIN varchar(20),
PASSWORD varchar(32),
NAME varchar(255),
AD_USER varchar(100),
GROUP_ID varchar(36),
primary key (ID)
);
alter table SEC_PROFILE add constraint SEC_PROFILE_GROUP foreign key (GROUP_ID) references SEC_GROUP(ID);
alter table SEC_USER add constraint SEC_USER_UNIQ_LOGIN unique (LOGIN, DELETE_TS);
alter table SEC_USER add constraint SEC_USER_GROUP foreign key (GROUP_ID) references SEC_GROUP(ID);
------------------------------------------------------------------------------------------------------------
create table SEC_SUBJECT (
create table SEC_USER_ROLE (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
IS_DEFAULT smallint,
DELETED_BY varchar(20),
USER_ID varchar(36),
PROFILE_ID varchar(36),
START_DATE timestamp,
END_DATE timestamp,
primary key (ID)
);
alter table SEC_SUBJECT add constraint SEC_SUBJECT_USER foreign key (USER_ID) references SEC_USER(ID);
alter table SEC_SUBJECT add constraint SEC_SUBJECT_PROFILE foreign key (PROFILE_ID) references SEC_PROFILE(ID);
------------------------------------------------------------------------------------------------------------
create table SEC_PROFILE_ROLE (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
DELETE_TS timestamp,
DELETED_BY varchar(36),
PROFILE_ID varchar(36),
ROLE_ID varchar(36),
primary key (ID)
);
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_ROLE_PROFILE foreign key (PROFILE_ID) references SEC_PROFILE(ID);
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_PROFILE foreign key (USER_ID) references SEC_USER(ID);
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_ROLE_ROLE foreign key (ROLE_ID) references SEC_ROLE(ID);
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_ROLE foreign key (ROLE_ID) references SEC_ROLE(ID);
alter table SEC_PROFILE_ROLE add constraint SEC_PROFILE_UNIQ_ROLE unique (PROFILE_ID, ROLE_ID, DELETE_TS);
alter table SEC_USER_ROLE add constraint SEC_USER_ROLE_UNIQ_ROLE unique (USER_ID, ROLE_ID, DELETE_TS);
------------------------------------------------------------------------------------------------------------
create table SEC_PERMISSION (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
TYPE integer,
TARGET varchar(100),
VALUE integer,
@ -193,12 +155,12 @@ alter table SEC_PERMISSION add constraint SEC_PERMISSION_UNIQUE unique (ROLE_ID,
create table SEC_CONSTRAINT (
ID varchar(36),
CREATE_TS timestamp,
CREATED_BY varchar(36),
CREATED_BY varchar(20),
VERSION integer,
UPDATE_TS timestamp,
UPDATED_BY varchar(36),
UPDATED_BY varchar(20),
DELETE_TS timestamp,
DELETED_BY varchar(36),
DELETED_BY varchar(20),
ENTITY_NAME varchar(50),
WHERE_CLAUSE varchar(500),
GROUP_ID varchar(36),
@ -209,20 +171,14 @@ alter table SEC_CONSTRAINT add constraint SEC_CONSTRAINT_GROUP foreign key (GROU
------------------------------------------------------------------------------------------------------------
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME)
values ('60885987-1b61-4247-94c7-dff348347f93', current_timestamp, 0, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator');
insert into SEC_GROUP (ID, CREATE_TS, VERSION, NAME, PARENT_ID)
values ('0fa2b1a5-1d68-4d69-9fbd-dff348347f93', current_timestamp, 0, 'Company', null);
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, GROUP_ID)
values ('bf83541f-f610-46f4-a268-dff348347f93', current_timestamp, 0, 'Default', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
insert into SEC_SUBJECT (ID, CREATE_TS, VERSION, IS_DEFAULT, USER_ID, PROFILE_ID)
values ('05d9d689-da68-4622-8952-f94dfb36ca07', current_timestamp, 0, 1, '60885987-1b61-4247-94c7-dff348347f93', 'bf83541f-f610-46f4-a268-dff348347f93');
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME, GROUP_ID)
values ('60885987-1b61-4247-94c7-dff348347f93', current_timestamp, 0, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME, IS_SUPER)
values ('0c018061-b26f-4de2-a5be-dff348347f93', current_timestamp, 0, 'Administrators', 1);
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
values ('c838be0a-96d0-4ef4-a7c0-dff348347f93', current_timestamp, 0, 'bf83541f-f610-46f4-a268-dff348347f93', '0c018061-b26f-4de2-a5be-dff348347f93');
insert into SEC_USER_ROLE (ID, CREATE_TS, VERSION, USER_ID, ROLE_ID)
values ('c838be0a-96d0-4ef4-a7c0-dff348347f93', current_timestamp, 0, '60885987-1b61-4247-94c7-dff348347f93', '0c018061-b26f-4de2-a5be-dff348347f93');

View File

@ -1,23 +1,11 @@
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME)
values ('40288137-1ef4-11c8-011e-f41247370001', current_timestamp, 0, 'abramov', '402881371ef411c8011ef411c8c50000', 'Dmitry Abramov');
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, GROUP_ID)
values ('40288137-1ef4-11c8-011e-f4157fa70002', current_timestamp, 0, 'Default', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, GROUP_ID)
values ('40288137-1ef4-11c8-011e-f415e4fc0004', current_timestamp, 0, 'Administrator', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
insert into SEC_SUBJECT (ID, CREATE_TS, VERSION, IS_DEFAULT, USER_ID, PROFILE_ID)
values ('efb58415-6c9f-4adb-bef7-f94dfb36ca07', current_timestamp, 0, 1, '40288137-1ef4-11c8-011e-f41247370001', '40288137-1ef4-11c8-011e-f4157fa70002');
insert into SEC_SUBJECT (ID, CREATE_TS, VERSION, IS_DEFAULT, USER_ID, PROFILE_ID)
values ('de933c93-0573-4720-ba0c-f94dfb36ca07', current_timestamp, 0, 1, '40288137-1ef4-11c8-011e-f41247370001', '40288137-1ef4-11c8-011e-f415e4fc0004');
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME, GROUP_ID)
values ('40288137-1ef4-11c8-011e-f41247370001', current_timestamp, 0, 'abramov', '402881371ef411c8011ef411c8c50000', 'Dmitry Abramov', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME, IS_SUPER)
values ('40288137-1ef4-11c8-011e-f416e4150005', current_timestamp, 0, 'Users', 0);
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
values ('40288137-1ef4-11c8-011e-f41aaa740006', current_timestamp, 0, '40288137-1ef4-11c8-011e-f4157fa70002', '40288137-1ef4-11c8-011e-f416e4150005');
insert into SEC_USER_ROLE (ID, CREATE_TS, VERSION, USER_ID, ROLE_ID)
values ('40288137-1ef4-11c8-011e-f41aaa740006', current_timestamp, 0, '40288137-1ef4-11c8-011e-f41247370001', '40288137-1ef4-11c8-011e-f416e4150005');
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
values ('40288137-1ef4-11c8-011e-f41aaa740007', current_timestamp, 0, '40288137-1ef4-11c8-011e-f415e4fc0004', '0c018061-b26f-4de2-a5be-dff348347f93');
insert into SEC_USER_ROLE (ID, CREATE_TS, VERSION, USER_ID, ROLE_ID)
values ('40288137-1ef4-11c8-011e-f41aaa740007', current_timestamp, 0, '40288137-1ef4-11c8-011e-f41247370001', '0c018061-b26f-4de2-a5be-dff348347f93');

View File

@ -10,11 +10,9 @@
<class>com.haulmont.cuba.core.entity.Config</class>
<class>com.haulmont.cuba.security.entity.User</class>
<class>com.haulmont.cuba.security.entity.Role</class>
<class>com.haulmont.cuba.security.entity.UserRole</class>
<class>com.haulmont.cuba.security.entity.Group</class>
<class>com.haulmont.cuba.security.entity.GroupHierarchy</class>
<class>com.haulmont.cuba.security.entity.Profile</class>
<class>com.haulmont.cuba.security.entity.ProfileRole</class>
<class>com.haulmont.cuba.security.entity.Subject</class>
<class>com.haulmont.cuba.security.entity.Permission</class>
<class>com.haulmont.cuba.security.entity.Constraint</class>

View File

@ -25,6 +25,8 @@ import java.util.Set;
public abstract class PersistenceProvider
{
public static final int LOGIN_FIELD_LEN = 20;
private static PersistenceProvider instance;
public static final String PERSISTENCE_XML = "cuba.PersistenceXml";

View File

@ -81,10 +81,7 @@ public abstract class SecurityProvider
}
protected void setQueryParam(Query query, String paramName) {
if ("currentSubjectId".equals(paramName)) {
query.setParameter("currentSubjectId", __currentUserSession().getSubjectId());
}
else if ("currentUserLogin".equals(paramName)) {
if ("currentUserLogin".equals(paramName)) {
query.setParameter("currentUserLogin", __currentUserSession().getLogin());
}
else if ("currentUserId".equals(paramName)) {

View File

@ -21,7 +21,7 @@ public interface BaseEntity<T> extends Entity<T>
void setCreateTs(Date date);
UUID getCreatedBy();
String getCreatedBy();
void setCreatedBy(UUID createdBy);
void setCreatedBy(String createdBy);
}

View File

@ -28,7 +28,7 @@ public class BaseLongIdEntity implements BaseEntity<Long>
private Date createTs;
@Column(name = "CREATED_BY")
private UUID createdBy;
private String createdBy;
public Long getId() {
return id;
@ -54,11 +54,11 @@ public class BaseLongIdEntity implements BaseEntity<Long>
this.createTs = createTs;
}
public UUID getCreatedBy() {
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(UUID createdBy) {
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
}

View File

@ -30,9 +30,8 @@ public class BaseUuidEntity implements BaseEntity<UUID>
@Column(name = "CREATE_TS")
protected Date createTs;
@Persistent
@Column(name = "CREATED_BY")
protected UUID createdBy;
@Column(name = "CREATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
protected String createdBy;
public BaseUuidEntity() {
id = UuidProvider.createUuid();
@ -58,11 +57,11 @@ public class BaseUuidEntity implements BaseEntity<UUID>
this.createTs = createTs;
}
public UUID getCreatedBy() {
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(UUID createdBy) {
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}

View File

@ -34,9 +34,8 @@ public class Config extends BaseUuidEntity implements Versioned, Updatable
@Column(name = "UPDATE_TS")
private Date updateTs;
@Persistent
@Column(name = "UPDATED_BY")
private UUID updatedBy;
@Column(name = "UPDATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
private String updatedBy;
@Column(name = "NAME")
private String name;
@ -60,11 +59,11 @@ public class Config extends BaseUuidEntity implements Versioned, Updatable
this.updateTs = updateTs;
}
public UUID getUpdatedBy() {
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(UUID updatedBy) {
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}

View File

@ -11,7 +11,6 @@
package com.haulmont.cuba.core.entity;
import java.util.Date;
import java.util.UUID;
public interface DeleteDeferred extends Updatable
{
@ -21,7 +20,7 @@ public interface DeleteDeferred extends Updatable
void setDeleteTs(Date deleteTs);
UUID getDeletedBy();
String getDeletedBy();
void setDeletedBy(UUID deletedBy);
void setDeletedBy(String deletedBy);
}

View File

@ -16,9 +16,6 @@ import javax.persistence.MappedSuperclass;
import javax.persistence.Column;
import javax.persistence.Version;
import java.util.Date;
import java.util.UUID;
import org.apache.openjpa.persistence.Persistent;
@MappedSuperclass
public class StandardEntity
@ -32,16 +29,14 @@ public class StandardEntity
@Column(name = "UPDATE_TS")
protected Date updateTs;
@Persistent
@Column(name = "UPDATED_BY")
protected UUID updatedBy;
@Column(name = "UPDATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
protected String updatedBy;
@Column(name = "DELETE_TS")
protected Date deleteTs;
@Persistent
@Column(name = "DELETED_BY")
protected UUID deletedBy;
@Column(name = "DELETED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN)
protected String deletedBy;
public Integer getVersion() {
return version;
@ -59,11 +54,11 @@ public class StandardEntity
this.updateTs = updateTs;
}
public UUID getUpdatedBy() {
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(UUID updatedBy) {
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
@ -79,11 +74,11 @@ public class StandardEntity
this.deleteTs = deleteTs;
}
public UUID getDeletedBy() {
public String getDeletedBy() {
return deletedBy;
}
public void setDeletedBy(UUID deletedBy) {
public void setDeletedBy(String deletedBy) {
this.deletedBy = deletedBy;
}
}

View File

@ -11,7 +11,6 @@
package com.haulmont.cuba.core.entity;
import java.util.Date;
import java.util.UUID;
public interface Updatable
{
@ -19,7 +18,7 @@ public interface Updatable
void setUpdateTs(Date updateTs);
UUID getUpdatedBy();
String getUpdatedBy();
void setUpdatedBy(UUID updatedBy);
void setUpdatedBy(String updatedBy);
}

View File

@ -73,7 +73,7 @@ public class EntityManagerImpl implements EntityManager
public void remove(Entity entity) {
if (entity instanceof DeleteDeferred) {
((DeleteDeferred) entity).setDeleteTs(TimeProvider.currentTimestamp());
((DeleteDeferred) entity).setDeletedBy(SecurityProvider.currentUserSession().getSubjectId());
((DeleteDeferred) entity).setDeletedBy(SecurityProvider.currentUserSession().getLogin());
}
else {
jpaEm.remove(entity);

View File

@ -69,7 +69,7 @@ public class EntityLifecycleListener extends AbstractLifecycleListener
}
private void __beforePersist(BaseEntity entity) {
entity.setCreatedBy(SecurityProvider.currentUserSession().getSubjectId());
entity.setCreatedBy(SecurityProvider.currentUserSession().getLogin());
Date ts = TimeProvider.currentTimestamp();
entity.setCreateTs(ts);
@ -79,7 +79,7 @@ public class EntityLifecycleListener extends AbstractLifecycleListener
}
private void __beforeUpdate(Updatable entity) {
entity.setUpdatedBy(SecurityProvider.currentUserSession().getSubjectId());
entity.setUpdatedBy(SecurityProvider.currentUserSession().getLogin());
entity.setUpdateTs(TimeProvider.currentTimestamp());
}

View File

@ -13,16 +13,12 @@ package com.haulmont.cuba.security.app;
import com.haulmont.cuba.security.global.LoginServiceRemote;
import com.haulmont.cuba.security.global.LoginException;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.security.entity.Profile;
import javax.ejb.Local;
import java.util.List;
import java.util.Locale;
@Local
public interface LoginService extends LoginServiceRemote
{
UserSession loginActiveDirectory(String activeDirectoryUser, Locale locale) throws LoginException;
UserSession loginActiveDirectory(String activeDirectoryUser, String profileName, Locale locale) throws LoginException;
}

View File

@ -29,20 +29,6 @@ public class LoginServiceBean implements LoginService, LoginServiceRemote
return Locator.lookupLocal(LoginWorker.JNDI_NAME);
}
public UserSession login(String login, String password, String profileName, Locale locale) throws LoginException {
try {
return getLoginWorker().login(login, password, profileName, locale);
} catch (Exception e) {
log.error("Login error", e);
if (e instanceof LoginException)
throw ((LoginException) e);
else if (e instanceof RuntimeException)
throw ((RuntimeException) e);
else
throw new RuntimeException(e);
}
}
public UserSession login(String activeDirectoryUser, String profileName, Locale locale) throws LoginException {
try {
return getLoginWorker().login(activeDirectoryUser, profileName, locale);
@ -71,20 +57,6 @@ public class LoginServiceBean implements LoginService, LoginServiceRemote
}
}
public UserSession loginActiveDirectory(String activeDirectoryUser, String profileName, Locale locale) throws LoginException {
try {
return getLoginWorker().loginActiveDirectory(activeDirectoryUser, profileName, locale);
} catch (Exception e) {
log.error("Login error", e);
if (e instanceof LoginException)
throw ((LoginException) e);
else if (e instanceof RuntimeException)
throw ((RuntimeException) e);
else
throw new RuntimeException(e);
}
}
public void logout() {
try {
getLoginWorker().logout();

View File

@ -10,8 +10,6 @@
*/
package com.haulmont.cuba.security.app;
import com.haulmont.cuba.security.global.LoginServiceRemote;
import javax.ejb.Local;
@Local

View File

@ -13,9 +13,7 @@ package com.haulmont.cuba.security.app;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.security.global.LoginException;
import com.haulmont.cuba.security.global.NoUserSessionException;
import com.haulmont.cuba.security.entity.Profile;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.Subject;
import com.haulmont.cuba.security.resource.Messages;
import com.haulmont.cuba.security.sys.UserSessionManager;
import com.haulmont.cuba.core.PersistenceProvider;
@ -40,9 +38,8 @@ public class LoginWorkerBean implements LoginWorker
{
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createQuery(
"select u " +
" from sec$User u join fetch u.subjects" +
" where u.login = ?1 and u.password = ?2");
"select u from sec$User u " +
"where u.login = ?1 and u.password = ?2");
q.setParameter(1, login);
q.setParameter(2, password);
List list = q.getResultList();
@ -62,9 +59,8 @@ public class LoginWorkerBean implements LoginWorker
{
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createQuery(
"select u " +
" from sec$User u join fetch u.subjects" +
" where u.activeDirectoryUser = ?1");
"select u from sec$User u " +
"where u.activeDirectoryUser = ?1");
q.setParameter(1, activeDirectoryUser);
List list = q.getResultList();
if (list.isEmpty()) {
@ -78,55 +74,22 @@ public class LoginWorkerBean implements LoginWorker
}
}
public UserSession login(String login, String password, Locale locale) throws LoginException {
return login(login, password, null, locale);
}
public UserSession login(String login, String password, String profileName, Locale locale)
public UserSession login(String login, String password, Locale locale)
throws LoginException
{
User user = loadUser(login, password, locale);
UserSession session = findProfile(user, profileName, locale);
UserSession session = UserSessionManager.getInstance().createSession(user, locale);
log.info("Logged in: " + session);
return session;
}
public UserSession loginActiveDirectory(String activeDirectoryUser, Locale locale) throws LoginException {
return loginActiveDirectory(activeDirectoryUser, null, locale);
}
public UserSession loginActiveDirectory(String activeDirectoryUser, String profileName, Locale locale) throws LoginException {
User user = loadUser(activeDirectoryUser, locale);
UserSession session = findProfile(user, profileName, locale);
UserSession session = UserSessionManager.getInstance().createSession(user, locale);
log.info("Logged in: " + session);
return session;
}
private UserSession findProfile(User user, String profileName, Locale locale) throws LoginException {
Subject subject = null;
if (profileName == null) {
for (Subject s : user.getSubjects()) {
subject = s;
if (subject.isDefaultSubject())
break;
}
if (subject == null)
throw new LoginException(Messages.getString("LoginException.NoProfile", locale));
}
else {
for (Subject s : user.getSubjects()) {
if (profileName.equals(s.getProfile().getName())) {
subject = s;
break;
}
}
if (subject == null)
throw new LoginException(Messages.getString("LoginException.InvalidProfile", locale), profileName);
}
return UserSessionManager.getInstance().createSession(user, subject, locale);
}
public void logout() {
try {
UserSession session = SecurityProvider.currentUserSession();

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 26.11.2008 12:37:01
*
* $Id$
*/
package com.haulmont.cuba.security.entity;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.Listeners;
import com.haulmont.cuba.core.entity.annotation.OnDelete;
import com.haulmont.cuba.core.global.DeletePolicy;
import javax.persistence.*;
import java.util.Set;
import java.io.Serializable;
import org.apache.commons.lang.BooleanUtils;
@Entity(name = "sec$Profile")
@Table(name = "SEC_PROFILE")
public class Profile extends StandardEntity
{
private static final long serialVersionUID = 8037692798864039665L;
@Column(name = "NAME")
private String name;
@OneToMany(mappedBy = "profile")
@OnDelete(DeletePolicy.CASCADE)
private Set<ProfileRole> profileRoles;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "GROUP_ID")
private Group group;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<ProfileRole> getProfileRoles() {
return profileRoles;
}
public void setProfileRoles(Set<ProfileRole> profileRoles) {
this.profileRoles = profileRoles;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 10.02.2009 17:22:38
*
* $Id$
*/
package com.haulmont.cuba.security.entity;
import com.haulmont.cuba.core.entity.StandardEntity;
import javax.persistence.*;
import java.util.Date;
import org.apache.commons.lang.BooleanUtils;
@Entity(name = "sec$Subject")
@Table(name = "SEC_SUBJECT")
public class Subject extends StandardEntity
{
private static final long serialVersionUID = 837722143973534603L;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
private User user;
@ManyToOne(optional = false)
@JoinColumn(name = "PROFILE_ID")
private Profile profile;
@Column(name = "IS_DEFAULT")
private Boolean defaultSubject;
@Column(name = "START_DATE")
private Date startDate;
@Column(name = "END_DATE")
private Date endDate;
public boolean isDefaultSubject() {
return BooleanUtils.isTrue(defaultSubject);
}
public void setDefaultSubject(boolean defaultSubject) {
this.defaultSubject = defaultSubject;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Profile getProfile() {
return profile;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}

View File

@ -11,6 +11,8 @@
package com.haulmont.cuba.security.entity;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.OnDeleteInverse;
import com.haulmont.cuba.core.global.DeletePolicy;
import javax.persistence.*;
import java.util.Set;
@ -33,8 +35,13 @@ public class User extends StandardEntity
@Column(name = "AD_USER", length = 100)
private String activeDirectoryUser;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "GROUP_ID")
@OnDeleteInverse(DeletePolicy.DENY)
private Group group;
@OneToMany(mappedBy = "user")
private Set<Subject> subjects;
private Set<UserRole> userRoles;
public String getLogin() {
return login;
@ -68,15 +75,23 @@ public class User extends StandardEntity
this.activeDirectoryUser = activeDirectoryUser;
}
public Set<Subject> getSubjects() {
return subjects;
public Group getGroup() {
return group;
}
public void setSubjects(Set<Subject> subjects) {
this.subjects = subjects;
public void setGroup(Group group) {
this.group = group;
}
public Set<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
public String toString() {
return name;
return login;
}
}

View File

@ -16,27 +16,28 @@ import com.haulmont.cuba.core.global.DeletePolicy;
import javax.persistence.*;
@Entity(name = "sec$ProfileRole")
@Table(name = "SEC_PROFILE_ROLE")
public class ProfileRole extends StandardEntity
@Entity(name = "sec$UserRole")
@Table(name = "SEC_USER_ROLE")
public class UserRole extends StandardEntity
{
private static final long serialVersionUID = 6151402331592361210L;
private static final long serialVersionUID = 8543853035155300992L;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "PROFILE_ID")
private Profile profile;
@JoinColumn(name = "USER_ID")
@OnDeleteInverse(DeletePolicy.CASCADE)
private User user;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "ROLE_ID")
@OnDeleteInverse(DeletePolicy.CASCADE)
private Role role;
public Profile getProfile() {
return profile;
public User getUser() {
return user;
}
public void setProfile(Profile profile) {
this.profile = profile;
public void setUser(User user) {
this.user = user;
}
public Role getRole() {

View File

@ -20,8 +20,6 @@ public interface LoginServiceRemote
UserSession login(String login, String password, Locale locale) throws LoginException;
UserSession login(String login, String password, String profileName, Locale locale) throws LoginException;
void logout();
void ping();

View File

@ -24,21 +24,17 @@ public class UserSession implements Serializable
private final UUID userId;
private final String login;
private final String name;
private final UUID subjectId;
private final String profile;
private final String[] roles;
private final Locale locale;
private final Map<String, Integer>[] permissions;
private final Map<String, List<String>> constraints;
public UserSession(User user, Subject subject, String[] roles, Locale locale) {
public UserSession(User user, String[] roles, Locale locale) {
this.id = UuidProvider.createUuid();
this.userId = user.getId();
this.login = user.getLogin();
this.name = user.getName();
this.subjectId = subject.getId();
this.profile = subject.getProfile().getName();
this.roles = roles;
Arrays.sort(this.roles);
@ -69,14 +65,6 @@ public class UserSession implements Serializable
return name;
}
public UUID getSubjectId() {
return subjectId;
}
public String getProfile() {
return profile;
}
public String[] getRoles() {
return roles;
}
@ -120,7 +108,6 @@ public class UserSession implements Serializable
return "UserSession{" +
"id=" + id +
", login='" + login + '\'' +
", profile='" + profile + '\'' +
'}';
}
}

View File

@ -36,20 +36,19 @@ public class UserSessionManager
sessions = new UserSessionsCache();
}
public UserSession createSession(User user, Subject subject, Locale locale) {
Profile profile = subject.getProfile();
public UserSession createSession(User user, Locale locale) {
List<String> roleNames = new ArrayList<String>();
List<Role> roles = new ArrayList<Role>();
for (ProfileRole profileRole : profile.getProfileRoles()) {
if (profileRole.getRole() != null) {
roleNames.add(profileRole.getRole().getName());
roles.add(profileRole.getRole());
for (UserRole userRole : user.getUserRoles()) {
if (userRole.getRole() != null) {
roleNames.add(userRole.getRole().getName());
roles.add(userRole.getRole());
}
}
UserSession session = new UserSession(
user, subject, roleNames.toArray(new String[roleNames.size()]), locale);
user, roleNames.toArray(new String[roleNames.size()]), locale);
compilePermissions(session, roles);
compileConstraints(session, profile.getGroup());
compileConstraints(session, user.getGroup());
sessions.add(session);
return session;
}

View File

@ -11,23 +11,21 @@
package com.haulmont.cuba.core;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.Profile;
import com.haulmont.cuba.security.entity.Group;
import com.haulmont.cuba.security.entity.Subject;
import com.haulmont.cuba.security.entity.UserRole;
import com.haulmont.cuba.security.entity.Role;
import com.haulmont.cuba.core.global.View;
import java.util.UUID;
import java.util.List;
import java.util.Set;
public class DeletedCollectionItemTest extends CubaTestCase
{
private UUID groupId;
private UUID userId;
private UUID profile1Id;
private UUID profile2Id;
private UUID subject1Id;
private UUID subject2Id;
private UUID role2Id;
private UUID userRole1Id;
private UUID userRole2Id;
protected void setUp() throws Exception {
super.setUp();
@ -45,47 +43,42 @@ public class DeletedCollectionItemTest extends CubaTestCase
userId = user.getId();
user.setName("testUser");
user.setLogin("testLogin");
user.setGroup(group);
em.persist(user);
Profile profile1 = new Profile();
profile1Id = profile1.getId();
profile1.setName("testProfile1");
profile1.setGroup(group);
em.persist(profile1);
Role role1 = em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93"));
Profile profile2 = new Profile();
profile2Id = profile2.getId();
profile2.setName("testProfile2");
profile2.setGroup(group);
em.persist(profile2);
UserRole userRole1 = new UserRole();
userRole1Id = userRole1.getId();
userRole1.setUser(user);
userRole1.setRole(role1);
em.persist(userRole1);
Subject subject1 = new Subject();
subject1Id = subject1.getId();
subject1.setUser(user);
subject1.setProfile(profile1);
em.persist(subject1);
Subject subject2 = new Subject();
subject2Id = subject2.getId();
subject2.setUser(user);
subject2.setProfile(profile2);
em.persist(subject2);
Role role2 = new Role();
role2Id = role2.getId();
role2.setName("role2");
em.persist(role2);
UserRole userRole2 = new UserRole();
userRole2Id = userRole2.getId();
userRole2.setUser(user);
userRole2.setRole(role2);
em.persist(userRole2);
tx.commitRetaining();
em = PersistenceProvider.getEntityManager();
Profile profile = em.find(Profile.class, profile2Id);
em.remove(profile);
UserRole ur = em.find(UserRole.class, userRole2Id);
em.remove(ur);
Group g = em.find(Group.class, groupId);
em.remove(g);
Role r = em.find(Role.class, role2Id);
em.remove(r);
tx.commit();
} finally {
tx.end();
}
}
protected void tearDown() throws Exception {
@ -93,14 +86,15 @@ public class DeletedCollectionItemTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createNativeQuery("delete from SEC_SUBJECT where ID = ? or ID = ?");
q.setParameter(1, subject1Id.toString());
q.setParameter(2, subject2Id.toString());
Query q;
q = em.createNativeQuery("delete from SEC_USER_ROLE where ID = ? or ID = ?");
q.setParameter(1, userRole1Id.toString());
q.setParameter(2, userRole2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_PROFILE where ID = ? or ID = ?");
q.setParameter(1, profile1Id.toString());
q.setParameter(2, profile2Id.toString());
q = em.createNativeQuery("delete from SEC_ROLE where ID = ?");
q.setParameter(1, role2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_USER where ID = ?");
@ -123,8 +117,8 @@ public class DeletedCollectionItemTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Group group = em.find(Group.class, groupId);
assertNull(group);
Role role = em.find(Role.class, role2Id);
assertNull(role);
tx.commit();
} finally {
@ -138,9 +132,9 @@ public class DeletedCollectionItemTest extends CubaTestCase
EntityManager em = PersistenceProvider.getEntityManager();
em.setDeleteDeferred(false);
Group group = em.find(Group.class, groupId);
assertNotNull(group);
assertTrue(group.isDeleted());
Role role = em.find(Role.class, role2Id);
assertNotNull(role);
assertTrue(role.isDeleted());
tx.commit();
} finally {
@ -157,17 +151,18 @@ public class DeletedCollectionItemTest extends CubaTestCase
new View(User.class, "testView")
.addProperty("name")
.addProperty("login")
.addProperty("subjects",
new View(Subject.class, "testView")
.addProperty("profile")
)
.addProperty("userRoles",
new View(UserRole.class, "testView")
.addProperty("role",
new View(Role.class, "testView")
.addProperty("name")))
);
User user = em.find(User.class, userId);
Set<Subject> subjects = user.getSubjects();
assertEquals(2, subjects.size());
for (Subject subject : subjects) {
System.out.println(subject.getProfile().getName());
Set<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
@ -186,17 +181,18 @@ public class DeletedCollectionItemTest extends CubaTestCase
new View(User.class, "testView")
.addProperty("name")
.addProperty("login")
.addProperty("subjects",
new View(Subject.class, "testView")
.addProperty("profile")
)
.addProperty("userRoles",
new View(UserRole.class, "testView")
.addProperty("role",
new View(Role.class, "testView")
.addProperty("name")))
);
User user = em.find(User.class, userId);
Set<Subject> subjects = user.getSubjects();
assertEquals(2, subjects.size());
for (Subject subject : subjects) {
System.out.println(subject.getProfile().getName());
Set<UserRole> userRoles = user.getUserRoles();
assertEquals(2, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
@ -214,10 +210,10 @@ public class DeletedCollectionItemTest extends CubaTestCase
q.setParameter(1, userId);
User user = (User) q.getSingleResult();
Set<Subject> subjects = user.getSubjects();
assertEquals(2, subjects.size());
for (Subject subject : subjects) {
System.out.println(subject.getProfile().getName());
Set<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
@ -231,14 +227,14 @@ public class DeletedCollectionItemTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createQuery("select u from sec$User u join fetch u.subjects where u.id = ?1");
Query q = em.createQuery("select u from sec$User u join fetch u.userRoles where u.id = ?1");
q.setParameter(1, userId);
User user = (User) q.getSingleResult();
Set<Subject> subjects = user.getSubjects();
assertEquals(2, subjects.size());
for (Subject subject : subjects) {
System.out.println(subject.getProfile().getName());
Set<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
@ -247,26 +243,26 @@ public class DeletedCollectionItemTest extends CubaTestCase
}
}
public void testManyToOne() {
Transaction tx = Locator.createTransaction();
try {
EntityManager em = PersistenceProvider.getEntityManager();
em.setView(
new View(Profile.class, "testView")
.addProperty("name")
.addProperty("group",
new View(Group.class, "testView")
.addProperty("name")
)
);
Profile profile = em.find(Profile.class, profile1Id);
assertNotNull(profile.getGroup());
assertTrue(profile.getGroup().isDeleted());
tx.commit();
} finally {
tx.end();
}
}
// public void testManyToOne() {
// Transaction tx = Locator.createTransaction();
// try {
// EntityManager em = PersistenceProvider.getEntityManager();
//
// em.setView(
// new View(Profile.class, "testView")
// .addProperty("name")
// .addProperty("group",
// new View(Group.class, "testView")
// .addProperty("name")
// )
// );
// Profile profile = em.find(Profile.class, profile1Id);
// assertNotNull(profile.getGroup());
// assertTrue(profile.getGroup().isDeleted());
//
// tx.commit();
// } finally {
// tx.end();
// }
// }
}

View File

@ -24,7 +24,7 @@ public class QueryTest extends CubaTestCase
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Query query = em.createQuery("select s from sec$Subject s where s.user.id = :user");
Query query = em.createQuery("select r from sec$UserRole r where r.user.id = :user");
query.setParameter("user", user);
List list = query.getResultList();

View File

@ -12,9 +12,7 @@ package com.haulmont.cuba.core;
import com.haulmont.cuba.core.global.View;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.Profile;
import com.haulmont.cuba.security.entity.Group;
import com.haulmont.cuba.security.entity.Subject;
import java.util.UUID;
@ -27,35 +25,16 @@ public class ViewTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
User user = new User();
userId = user.getId();
user.setName("testUser");
user.setLogin("login" + userId);
user.setPassword("000");
user.setGroup(group);
em.persist(user);
Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
Profile profile = new Profile();
profile.setName("testProfile1");
profile.setGroup(group);
em.persist(profile);
Subject subject = new Subject();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
profile = new Profile();
profile.setName("testProfile2");
profile.setGroup(group);
em.persist(profile);
subject = new Subject();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
tx.commit();
} finally {
tx.end();
@ -75,9 +54,9 @@ public class ViewTest extends CubaTestCase
View view = new View(User.class, "testUserView")
.addProperty("name")
.addProperty("login")
.addProperty("subjects",
new View(Subject.class, "testSubjectView")
.addProperty("profile")
.addProperty("group",
new View(Group.class, "testGroupView")
.addProperty("name")
);
q.setView(view);
@ -86,7 +65,7 @@ public class ViewTest extends CubaTestCase
tx.commit();
assertNull(user.getPassword());
assertEquals(2, user.getSubjects().size());
assertNotNull(user.getGroup().getName());
} finally {
tx.end();
}
@ -102,9 +81,9 @@ public class ViewTest extends CubaTestCase
View view = new View(User.class, "testUserView")
.addProperty("name")
.addProperty("login")
.addProperty("subjects",
new View(Subject.class, "testSubjectView")
.addProperty("profile")
.addProperty("group",
new View(Group.class, "testGroupView")
.addProperty("name")
);
em.setView(view);
@ -113,7 +92,7 @@ public class ViewTest extends CubaTestCase
tx.commit();
assertNull(user.getPassword());
assertEquals(2, user.getSubjects().size());
assertNotNull(user.getGroup().getName());
} finally {
tx.end();
}

View File

@ -32,15 +32,15 @@ public class ViewRepositoryTest extends CubaTestCase
assertNotNull(view);
assertNotNull(view.getProperty("name"));
assertNotNull(view.getProperty("login"));
assertNotNull(view.getProperty("subjects"));
assertNotNull(view.getProperty("userRoles"));
View subjectView = view.getProperty("subjects").getView();
assertNotNull(subjectView);
assertNotNull(subjectView.getProperty("profile"));
View userRolesView = view.getProperty("userRoles").getView();
assertNotNull(userRolesView);
assertNotNull(userRolesView.getProperty("role"));
View profileView = subjectView.getProperty("profile").getView();
assertNotNull(profileView);
assertNotNull(profileView.getProperty("name"));
View roleView = userRolesView.getProperty("role").getView();
assertNotNull(roleView);
assertNotNull(roleView.getProperty("name"));
}

View File

@ -3,14 +3,14 @@
<view entity="sec$User" name="test">
<property name="name"/>
<property name="login"/>
<property name="subjects" view="test"/>
<property name="userRoles" view="test"/>
</view>
<view entity="sec$Subject" name="test">
<property name="profile" view="test"/>
<view entity="sec$UserRole" name="test">
<property name="role" view="test"/>
</view>
<view entity="sec$Profile" name="test">
<view entity="sec$Role" name="test">
<property name="name"/>
</view>

View File

@ -12,8 +12,6 @@ package com.haulmont.cuba.core.sys;
import com.haulmont.cuba.core.SecurityProvider;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.Subject;
import com.haulmont.cuba.security.entity.Profile;
import com.haulmont.cuba.security.global.UserSession;
import org.apache.commons.codec.digest.DigestUtils;
@ -29,17 +27,8 @@ public class TestSecurityProvider extends SecurityProvider
user.setName("Test Administrator");
user.setPassword(DigestUtils.md5Hex("test_admin"));
Profile profile = new Profile();
profile.setId(UUID.fromString("bf83541f-f610-46f4-a268-dff348347f93"));
profile.setName("Default");
Subject subject = new Subject();
subject.setId(UUID.fromString("05d9d689-da68-4622-8952-f94dfb36ca07"));
subject.setUser(user);
subject.setProfile(profile);
UserSession session = new UserSession(user, subject, new String[]{"Administrators"}, Locale.getDefault());
session.addConstraint("sec$Group", "a.createdBy = :currentSubjectId");
UserSession session = new UserSession(user, new String[]{"Administrators"}, Locale.getDefault());
session.addConstraint("sec$Group", "a.createdBy = :currentUserLogin");
return session;
}

View File

@ -26,11 +26,10 @@ import org.apache.commons.codec.digest.DigestUtils;
public class ConstraintTest extends CubaTestCase
{
private static final String ADMIN_NAME = "admin";
private static final String ADMIN_PASSW = DigestUtils.md5Hex("admin");
private static final String PROFILE_NAME = "testProfile";
private static final String USER_LOGIN = "testUser";
private static final String USER_PASSW = DigestUtils.md5Hex("testUser");
private UUID constraintId, parentConstraintId, groupId, parentGroupId, profileId, subjectId;
private UUID constraintId, parentConstraintId, groupId, parentGroupId, userId;
protected void setUp() throws Exception {
super.setUp();
@ -39,8 +38,6 @@ public class ConstraintTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Group parentGroup = new Group();
parentGroupId = parentGroup.getId();
parentGroup.setName("testParentGroup");
@ -69,17 +66,12 @@ public class ConstraintTest extends CubaTestCase
constraint.setGroup(group);
em.persist(constraint);
Profile profile = new Profile();
profileId = profile.getId();
profile.setName(PROFILE_NAME);
profile.setGroup(group);
em.persist(profile);
Subject subject = new Subject();
subjectId = subject.getId();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
User user = new User();
userId = user.getId();
user.setLogin(USER_LOGIN);
user.setPassword(USER_PASSW);
user.setGroup(group);
em.persist(user);
tx.commit();
} finally {
@ -92,12 +84,10 @@ public class ConstraintTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createNativeQuery("delete from SEC_SUBJECT where ID = ?");
q.setParameter(1, subjectId.toString());
q.executeUpdate();
Query q;
q = em.createNativeQuery("delete from SEC_PROFILE where ID = ?");
q.setParameter(1, profileId.toString());
q = em.createNativeQuery("delete from SEC_USER where ID = ?");
q.setParameter(1, userId.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_CONSTRAINT where ID = ? or ID = ?");
@ -131,18 +121,18 @@ public class ConstraintTest extends CubaTestCase
public void test() throws LoginException {
LoginWorker lw = Locator.lookupLocal(LoginWorker.JNDI_NAME);
UserSession userSession = lw.login(ADMIN_NAME, ADMIN_PASSW, PROFILE_NAME, Locale.getDefault());
UserSession userSession = lw.login(USER_LOGIN, USER_PASSW, Locale.getDefault());
assertNotNull(userSession);
List<String> constraints = userSession.getConstraints("core$Server");
assertEquals(2, constraints.size());
DataService bs = Locator.lookupLocal(DataService.JNDI_NAME);
DataService.CollectionLoadContext ctx = new DataService.CollectionLoadContext(Group.class);
ctx.setQueryString("select g from sec$Group g where g.createTs <= :createTs").addParameter("createTs", new Date());
List<Group> list = bs.loadList(ctx);
assertTrue(list.size() > 0);
// DataService bs = Locator.lookupLocal(DataService.JNDI_NAME);
//
// DataService.CollectionLoadContext ctx = new DataService.CollectionLoadContext(Group.class);
// ctx.setQueryString("select g from sec$Group g where g.createTs <= :createTs").addParameter("createTs", new Date());
//
// List<Group> list = bs.loadList(ctx);
// assertTrue(list.size() > 0);
}
}

View File

@ -30,7 +30,7 @@ public class PermissionTest extends CubaTestCase
private static final String PERM_TARGET_ATTR = "core$Server:address";
private UUID role1Id, permission1Id, role2Id, permission2Id, userId, groupId,
profileId, profileRole1Id, profileRole2Id, subjectId;
userRole1Id, userRole2Id;
protected void setUp() throws Exception {
super.setUp();
@ -67,41 +67,30 @@ public class PermissionTest extends CubaTestCase
permission2.setValue(1);
em.persist(permission2);
User user = new User();
userId = user.getId();
user.setName(USER_NAME);
user.setLogin(USER_NAME);
user.setPassword(USER_PASSW);
em.persist(user);
Group group = new Group();
groupId = group.getId();
group.setName("testGroup");
em.persist(group);
Profile profile = new Profile();
profileId = profile.getId();
profile.setName(PROFILE_NAME);
profile.setGroup(group);
em.persist(profile);
User user = new User();
userId = user.getId();
user.setName(USER_NAME);
user.setLogin(USER_NAME);
user.setPassword(USER_PASSW);
user.setGroup(group);
em.persist(user);
ProfileRole profileRole1 = new ProfileRole();
profileRole1Id = profileRole1.getId();
profileRole1.setProfile(profile);
profileRole1.setRole(role1);
em.persist(profileRole1);
UserRole userRole1 = new UserRole();
userRole1Id = userRole1.getId();
userRole1.setUser(user);
userRole1.setRole(role1);
em.persist(userRole1);
ProfileRole profileRole2 = new ProfileRole();
profileRole2Id = profileRole2.getId();
profileRole2.setProfile(profile);
profileRole2.setRole(role2);
em.persist(profileRole2);
Subject subject = new Subject();
subjectId = subject.getId();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
UserRole userRole2 = new UserRole();
userRole2Id = userRole2.getId();
userRole2.setUser(user);
userRole2.setRole(role2);
em.persist(userRole2);
tx.commit();
} finally {
@ -114,17 +103,11 @@ public class PermissionTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
Query q = em.createNativeQuery("delete from SEC_SUBJECT where ID = ?");
q.setParameter(1, subjectId.toString());
q.executeUpdate();
Query q;
q = em.createNativeQuery("delete from SEC_PROFILE_ROLE where ID = ? or ID = ?");
q.setParameter(1, profileRole1Id.toString());
q.setParameter(2, profileRole2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_PROFILE where ID = ?");
q.setParameter(1, profileId.toString());
q = em.createNativeQuery("delete from SEC_USER_ROLE where ID = ? or ID = ?");
q.setParameter(1, userRole1Id.toString());
q.setParameter(2, userRole2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_USER where ID = ?");
@ -155,7 +138,7 @@ public class PermissionTest extends CubaTestCase
public void test() throws LoginException {
LoginWorker lw = Locator.lookupLocal(LoginWorker.JNDI_NAME);
UserSession userSession = lw.login(USER_NAME, USER_PASSW, PROFILE_NAME, Locale.getDefault());
UserSession userSession = lw.login(USER_NAME, USER_PASSW, Locale.getDefault());
assertNotNull(userSession);
boolean permitted = userSession.isPermitted(PermissionType.SCREEN, PERM_TARGET_SCREEN);

View File

@ -17,22 +17,6 @@ import java.util.UUID;
public class RelationsTest extends CubaTestCase
{
public void testProfile() {
UUID profileId = createProfile();
Transaction tx = Locator.createTransaction();
try {
EntityManager em = PersistenceProvider.getEntityManager();
Profile profile = em.find(Profile.class, profileId);
em.remove(profile);
tx.commit();
} finally {
tx.end();
}
}
public void testRole() {
UUID roleId = createRole();
@ -49,53 +33,21 @@ public class RelationsTest extends CubaTestCase
}
}
public UUID createProfile() {
Transaction tx = Locator.createTransaction();
try {
EntityManager em = PersistenceProvider.getEntityManager();
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Role role = em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93"));
Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
Profile profile = new Profile();
profile.setGroup(group);
profile.setName("RelationTest");
em.persist(profile);
ProfileRole profileRole = new ProfileRole();
profileRole.setProfile(profile);
profileRole.setRole(role);
em.persist(profileRole);
Subject subject = new Subject();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
tx.commit();
return profile.getId();
} finally {
tx.end();
}
}
public UUID createRole() {
Transaction tx = Locator.createTransaction();
try {
EntityManager em = PersistenceProvider.getEntityManager();
Profile profile = em.find(Profile.class, UUID.fromString("bf83541f-f610-46f4-a268-dff348347f93"));
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Role role = new Role();
role.setName("RelationTest");
em.persist(role);
ProfileRole profileRole = new ProfileRole();
profileRole.setProfile(profile);
profileRole.setRole(role);
em.persist(profileRole);
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(role);
em.persist(userRole);
tx.commit();

View File

@ -23,12 +23,6 @@ public class UserRoleTest extends CubaTestCase
try {
EntityManager em = PersistenceProvider.getEntityManager();
User user = new User();
UUID userId = user.getId();
user.setLogin("testUser1");
user.setName("Test User 1");
em.persist(user);
Role role = new Role();
role.setName("testRole1");
em.persist(role);
@ -37,35 +31,27 @@ public class UserRoleTest extends CubaTestCase
group.setName("testGroup1");
em.persist(group);
Profile profile = new Profile();
profile.setName("testProfile");
profile.setGroup(group);
em.persist(profile);
User user = new User();
UUID userId = user.getId();
user.setLogin("testUser1");
user.setName("Test User 1");
user.setGroup(group);
em.persist(user);
ProfileRole profileRole = new ProfileRole();
profileRole.setProfile(profile);
profileRole.setRole(role);
em.persist(profileRole);
Subject subject = new Subject();
subject.setUser(user);
subject.setProfile(profile);
em.persist(subject);
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(role);
em.persist(userRole);
tx.commitRetaining();
em = PersistenceProvider.getEntityManager();
user = em.find(User.class, userId);
Set<Subject> subjects = user.getSubjects();
assertEquals(1, subjects.size());
for (Subject s : subjects) {
assertEquals(profile.getName(), s.getProfile().getName());
Set<ProfileRole> roles = s.getProfile().getProfileRoles();
assertEquals(1, roles.size());
for (ProfileRole pr : roles) {
Role r = pr.getRole();
assertEquals(role.getName(), r.getName());
}
Set<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
Role r = ur.getRole();
assertEquals(role.getName(), r.getName());
}
} finally {
tx.end();

View File

@ -1,18 +1,18 @@
<screen-config>
<screen id="core$Server.browse"
class="com.haulmont.cuba.web.app.ui.DemoScreen"/>
<screen id="sec$User.browse"
template="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.xml"/>
<screen id="sec$User.edit"
template="/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.xml"/>
<screen id="sec$Group.browse"
template="/com/haulmont/cuba/web/app/ui/security/group/browse/security-group-browse.xml"/>
<screen id="sec$Role.browse"
class="com.haulmont.cuba.web.app.ui.TableDemoScreen"/>
<screen id="sec$User.browse"
template="/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse.xml"/>
<screen id="sec$User.edit"
template="/com/haulmont/cuba/web/app/ui/security/user/edit/user-edit.xml"/>
<screen id="sec$Group.browse"
template="/com/haulmont/cuba/web/app/ui/security/group/browse/group-browse.xml"/>
<screen id="sec$Role.browse"
template="/com/haulmont/cuba/web/app/ui/security/role/browse/role-browse.xml"/>
</screen-config>

View File

@ -24,8 +24,6 @@ import java.util.Locale;
import java.util.List;
import java.util.Collections;
import org.dom4j.Element;
public class AppWindow extends Window
{
private Connection connection;
@ -64,33 +62,12 @@ public class AppWindow extends Window
titleLayout.setSpacing(true);
titleLayout.setHeight(-1);
// Button navBtn = new Button(Messages.getString("navBtn"),
// new Button.ClickListener() {
// public void buttonClick(Button.ClickEvent event) {
// Navigator navigator = new Navigator(AppWindow.this);
// addWindow(navigator);
// }
// }
// );
// navBtn.setStyleName(Button.STYLE_LINK);
// titleLayout.addComponent(navBtn);
Label logoLabel = new Label(Messages.getString("logoLabel"));
titleLayout.addComponent(logoLabel);
Label label = new Label(String.format(Messages.getString("loggedInLabel"),
connection.getSession().getName(), connection.getSession().getProfile()));
titleLayout.addComponent(label);
Button profileBtn = new Button(Messages.getString("profileBtn"),
new Button.ClickListener()
{
public void buttonClick(Button.ClickEvent event) {
ChangeProfileWindow window = new ChangeProfileWindow();
window.center();
addWindow(window);
}
}
);
profileBtn.setStyleName(Button.STYLE_LINK);
titleLayout.addComponent(profileBtn);
Label loggedInLabel = new Label(String.format(Messages.getString("loggedInLabel"),
connection.getSession().getName()));
titleLayout.addComponent(loggedInLabel);
Button logoutBtn = new Button(Messages.getString("logoutBtn"),
new Button.ClickListener() {
@ -115,7 +92,7 @@ public class AppWindow extends Window
viewLogBtn.setStyleName(Button.STYLE_LINK);
titleLayout.addComponent(viewLogBtn);
// titleLayout.expand(navBtn);
titleLayout.expand(logoLabel);
rootLayout.addComponent(titleLayout);

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 05.01.2009 15:28:11
*
* $Id$
*/
package com.haulmont.cuba.web;
import com.haulmont.cuba.core.app.DataService;
import com.haulmont.cuba.core.global.DataServiceRemote;
import com.haulmont.cuba.security.entity.Subject;
import com.haulmont.cuba.security.global.LoginException;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.web.log.LogLevel;
import com.haulmont.cuba.web.resource.Messages;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.terminal.Sizeable;
import com.itmill.toolkit.ui.*;
import java.util.List;
public class ChangeProfileWindow extends Window
{
public ChangeProfileWindow() {
super(Messages.getString("changeProfileWindow.caption"));
setModal(true);
initUI();
}
private void initUI() {
ExpandLayout layout = new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL);
layout.setMargin(true);
layout.setSpacing(true);
setHeight(200, Sizeable.UNITS_PIXELS);
setWidth(400, Sizeable.UNITS_PIXELS);
Label label = new Label(Messages.getString("changeProfileWindow.label"));
layout.addComponent(label);
final ListSelect select = new ListSelect();
select.setMultiSelect(false);
select.setNullSelectionAllowed(false);
select.setSizeFull();
select.focus();
fillItems(select);
layout.addComponent(select);
layout.expand(select);
Button button = new Button(Messages.getString("changeProfileWindow.button"),
new Button.ClickListener()
{
public void buttonClick(Button.ClickEvent event) {
changeProfile((String) select.getValue());
Component parent = getParent();
if (parent != null && parent instanceof Window) {
((Window) parent).removeWindow(ChangeProfileWindow.this);
((Window) parent).open(new ExternalResource(App.getInstance().getURL()));
}
}
}
);
layout.addComponent(button);
setLayout(layout);
}
private void changeProfile(String profile) {
Connection connection = App.getInstance().getConnection();
try {
connection.changeProfile(profile);
} catch (LoginException e) {
App.getInstance().getAppLog().log(LogLevel.ERROR, "Unable to change profile", e);
showNotification(e.getMessage());
}
}
private void fillItems(ListSelect select) {
DataService bs = ServiceLocator.getDataService();
UserSession userSession = App.getInstance().getConnection().getSession();
final DataServiceRemote.CollectionLoadContext context = new DataServiceRemote.CollectionLoadContext(Subject.class);
context.setQueryString("select s from sec$Subject s where s.user.id = :userId").addParameter("userId", userSession.getUserId());
List<Subject> list = bs.loadList(context);
for (Subject subject : list) {
if (!subject.getId().equals(userSession.getSubjectId())) {
select.addItem(subject.getProfile().getName());
}
}
if (!select.getItemIds().isEmpty()) {
select.select(select.getItemIds().iterator().next());
}
}
}

View File

@ -45,7 +45,7 @@ public class Connection
}
public void login(String login, String password, String profileName) throws LoginException {
session = getLoginService().login(login, password, profileName, App.getInstance().getLocale());
session = getLoginService().login(login, password, App.getInstance().getLocale());
connected = true;
this.login = login;
this.password = password;
@ -58,7 +58,7 @@ public class Connection
}
public void loginActiveDirectory(String activeDirectoryUser, String profileName) throws LoginException {
session = getLoginService().loginActiveDirectory(activeDirectoryUser, profileName, App.getInstance().getLocale());
session = getLoginService().loginActiveDirectory(activeDirectoryUser, App.getInstance().getLocale());
connected = true;
this.login = activeDirectoryUser;
this.password = null;

View File

@ -13,11 +13,10 @@ package com.haulmont.cuba.web.app.ui.security.group.browse;
import com.haulmont.cuba.gui.components.AbstractWindow;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.Tree;
import com.haulmont.cuba.gui.data.Datasource;
public class SecurityGroupBrowser extends AbstractWindow
public class GroupBrowser extends AbstractWindow
{
public SecurityGroupBrowser(Window frame) {
public GroupBrowser(Window frame) {
super(frame);
}

View File

@ -0,0 +1,12 @@
<views>
<view entity="sec$Group" name="group-browse">
<property name="name"/>
<property name="parent"/>
</view>
<view entity="sec$User" name="group-browse">
<property name="name"/>
<property name="login"/>
<property name="activeDirectoryUser"/>
</view>
</views>

View File

@ -0,0 +1,43 @@
<window class="com.haulmont.cuba.web.app.ui.security.group.browse.GroupBrowser">
<metadataContext>
<deployViews name="/com/haulmont/cuba/web/app/ui/security/group/browse/group-browse.views.xml"/>
</metadataContext>
<dsContext>
<collectionDatasource
id="groups"
class="com.haulmont.cuba.security.entity.Group"
view="group-browse">
<query>
<![CDATA[select g from sec$Group g]]>
</query>
</collectionDatasource>
<collectionDatasource
id="users"
class="com.haulmont.cuba.security.entity.User"
view="group-browse">
<query>select u from sec$User u where u.group.id = :ds$groups</query>
</collectionDatasource>
</dsContext>
<layout>
<hbox id="tree-panel" expand="table">
<split orientation="horizontal">
<vbox>
<tree id="groups">
<treechildren datasource="groups" property="name" parent="parent"/>
</tree>
</vbox>
<table id="users">
<columns>
<column id="name" caption="Name"/>
<column id="login" caption="Login"/>
<column id="activeDirectoryUser" caption="ActiveDirectory User"/>
</columns>
<rows datasource="users"/>
</table>
</split>
</hbox>
</layout>
</window>

View File

@ -1,20 +0,0 @@
<views>
<view entity="sec$Group" name="group-browse">
<property name="name"/>
<property name="parent"/>
</view>
<view entity="sec$User" name="group-browse">
<property name="name"/>
</view>
<view entity="sec$Subject" name="group-browse">
<property name="defaultSubject"/>
<property name="user" view="group-browse"/>
<property name="profile" view="group-browse"/>
</view>
<view entity="sec$Profile" name="group-browse">
<property name="name"/>
</view>
</views>

View File

@ -1,57 +0,0 @@
<window class="com.haulmont.cuba.web.app.ui.security.group.browse.SecurityGroupBrowser">
<metadataContext>
<deployViews name="/com/haulmont/cuba/web/app/ui/security/group/browse/security-group-browse.views.xml"/>
</metadataContext>
<dsContext>
<collectionDatasource
id="groups"
class="com.haulmont.cuba.security.entity.Group"
view="group-browse">
<query>
<![CDATA[select g from sec$Group g]]>
</query>
</collectionDatasource>
<collectionDatasource
id="profiles"
class="com.haulmont.cuba.security.entity.Profile"
view="group-browse">
<query>select p from sec$Profile p where p.group.id = :ds$groups</query>
</collectionDatasource>
<collectionDatasource
id="subjects"
class="com.haulmont.cuba.security.entity.Subject"
view="group-browse">
<query>select s from sec$Subject s join fetch s.user where s.profile.id = :ds$profiles</query>
</collectionDatasource>
</dsContext>
<layout>
<hbox id="tree-panel" expand="table">
<split orientation="horizontal">
<vbox>
<tree id="groups">
<treechildren datasource="groups" property="name" parent="parent"/>
</tree>
</vbox>
<split orientation="vertical">
<table id="profiles">
<columns>
<column id="name" caption="Profile"/>
</columns>
<rows datasource="profiles"/>
</table>
<table id="subjects">
<columns>
<column id="user" caption="User" onClick="sec$User.edit"/>
<column id="defaultSubject" caption="Default"/>
</columns>
<rows datasource="subjects"/>
</table>
</split>
</split>
</hbox>
</layout>
</window>

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2009 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 14.02.2009 22:38:29
*
* $Id$
*/
package com.haulmont.cuba.web.app.ui.security.role.browse;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.security.entity.Role;
import java.util.Set;
public class RoleBrowser extends AbstractWindow
{
public RoleBrowser(IFrame frame) {
super(frame);
}
protected void init() {
final Table table = getComponent("roles");
table.addAction(
new AbstractAction("edit")
{
public String getCaption() {
return "Edit";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
final Set selected = table.getSelected();
if (selected.size() == 1) {
Role user = (Role) selected.iterator().next();
openEditor("sec$Role.edit", user, WindowManager.OpenType.THIS_TAB);
}
}
});
table.addAction(
new AbstractAction("refresh")
{
public String getCaption() {
return "Refresh";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
table.getDatasource().refresh();
}
});
}
}

View File

@ -0,0 +1,33 @@
<window
class="com.haulmont.cuba.web.app.ui.security.role.browse.RoleBrowser">
<metadataContext>
<view entity="sec$Role" name="role-browse">
<property name="name"/>
</view>
</metadataContext>
<dsContext>
<collectionDatasource
id="roles" class="com.haulmont.cuba.security.entity.Role" view="role-browse">
<query>
select r from sec$Role r
</query>
</collectionDatasource>
</dsContext>
<layout>
<vbox id="table-panel" expand="roles">
<hbox>
<button action="roles.edit"/>
<button action="roles.refresh"/>
</hbox>
<table id="roles" editable="false">
<columns>
<column id="name" caption="Name"/>
</columns>
<rows datasource="roles"/>
</table>
</vbox>
</layout>
</window>

View File

@ -13,12 +13,11 @@ import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.web.components.ComponentsHelper;
import com.haulmont.cuba.web.ui.GenericEditorWindow;
import java.util.Set;
public class SecurityUserBrowser extends AbstractLookup {
public SecurityUserBrowser(Window frame) {
public class UserBrowser extends AbstractLookup {
public UserBrowser(Window frame) {
super(frame);
}
@ -40,8 +39,7 @@ public class SecurityUserBrowser extends AbstractLookup {
if (selected.size() == 1) {
User user = (User) selected.iterator().next();
// openEditor(GenericEditorWindow.class, user, WindowManager.OpenType.THIS_TAB);
openEditor("/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.xml",
user, WindowManager.OpenType.THIS_TAB);
openEditor("sec$User.edit", user, WindowManager.OpenType.THIS_TAB);
}
}
});

View File

@ -1,35 +0,0 @@
<context
enableCommit="true"
>
<datasource
id="job"
entityClass=""
entityView=""
query="from History where driver=${driver} and date between ${fromDate} and ${tillDate}"
sqlQuery="from History where driver=${driver} and date between ${fromDate} and ${tillDate}"
queryBean="com.haulmont.cuba.app.history.HistoryService"
queryMethod="loadHistory(${driver}, ${fromDate}, ${tillDate})"
enableCommit="true"
commitBean=""
commitMethod="commit()"
>
<dependents>
<datasource id="contract" dependentBy="">
</datasource>
</dependents>
<nested>
<datasource id="stops" property="stops">
</datasource>
<datasource id="jobActors" property="jobActors">
</datasource>
</nested>
</datasource>
</context>

View File

@ -1,13 +0,0 @@
<views>
<view entity="sec$User" name="user-browse">
<property name="name"/>
<property name="login"/>
</view>
<view entity="sec$Subject" name="user-browse">
<property name="defaultSubject"/>
<property name="profile" view="user-browse"/>
</view>
<view entity="sec$Profile" name="user-browse">
<property name="name"/>
</view>
</views>

View File

@ -1,57 +0,0 @@
<window
class="com.haulmont.cuba.web.app.ui.security.user.browse.SecurityUserBrowser"
lookupComponent="users"
>
<metadataContext>
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.views.xml"/>
</metadataContext>
<dsContext>
<collectionDatasource
id="users"
class="com.haulmont.cuba.security.entity.User"
view="user-browse"
>
<query>
<![CDATA[select u from sec$User u where <#if component$filter.name?has_content>u.name like :component$filter.name<#else>1=1</#if>]]>
</query>
</collectionDatasource>
<collectionDatasource
id="subjects"
class="com.haulmont.cuba.security.entity.Subject"
view="user-browse"
>
<query>select s from sec$Subject s where s.user.id = :ds$users</query>
</collectionDatasource>
</dsContext>
<layout>
<vbox expand="table-panel">
<iframe id="filter" src="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse-filter.xml"/>
<hbox id="table-panel" expand="table">
<split orientation="horizontal">
<vbox expand="users">
<hbox>
<button action="users.edit"/>
</hbox>
<table id="users" editable="false">
<columns>
<column id="name" caption="Name"/>
</columns>
<rows datasource="users"/>
</table>
</vbox>
<vbox expand="subjects">
<table id="subjects">
<columns>
<column id="defaultSubject" caption="Default"/>
</columns>
<rows datasource="subjects"/>
</table>
</vbox>
</split>
</hbox>
</vbox>
</layout>
</window>

View File

@ -0,0 +1,7 @@
<views>
<view entity="sec$User" name="user-browse">
<property name="name"/>
<property name="login"/>
<property name="activeDirectoryUser"/>
</view>
</views>

View File

@ -0,0 +1,39 @@
<window
class="com.haulmont.cuba.web.app.ui.security.user.browse.UserBrowser"
lookupComponent="users"
>
<metadataContext>
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse.views.xml"/>
</metadataContext>
<dsContext>
<collectionDatasource
id="users"
class="com.haulmont.cuba.security.entity.User"
view="user-browse"
>
<query>
<![CDATA[select u from sec$User u where <#if component$filter.name?has_content>u.name like :component$filter.name<#else>1=1</#if>]]>
</query>
</collectionDatasource>
</dsContext>
<layout>
<vbox expand="table-panel">
<iframe id="filter" src="/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse-filter.xml"/>
<vbox id="table-panel" expand="users">
<hbox>
<button action="users.edit"/>
</hbox>
<table id="users" editable="false">
<columns>
<column id="name" caption="Name"/>
<column id="login" caption="Login"/>
<column id="activeDirectoryUser" caption="ActiveDirectory User"/>
</columns>
<rows datasource="users"/>
</table>
</vbox>
</vbox>
</layout>
</window>

View File

@ -15,8 +15,8 @@ import com.haulmont.cuba.security.entity.User;
import java.util.Collection;
public class SecurityUserEditor extends AbstractEditor {
public SecurityUserEditor(Window frame) {
public class UserEditor extends AbstractEditor {
public UserEditor(Window frame) {
super(frame);
}
@ -32,7 +32,7 @@ public class SecurityUserEditor extends AbstractEditor {
}
public void actionPerform(Component component) {
openLookup("/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.xml", new Lookup.Handler() {
openLookup("/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse.xml", new Lookup.Handler() {
public void handleLookup(Collection items) {
if (items.size() == 1) {
final User item = (User) items.iterator().next();

View File

@ -2,7 +2,7 @@
resourceBundle="com.haulmont.cuba.web.app.ui.security.user.edit.security-user-edit"
datasource="user"
caption="Edit User '${parameter$item.name}'"
class="com.haulmont.cuba.web.app.ui.security.user.edit.SecurityUserEditor"
class="com.haulmont.cuba.web.app.ui.security.user.edit.UserEditor"
>
<metadataContext>
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.views.xml"/>

View File

@ -9,9 +9,9 @@ application.caption=CUBA Application
#welcomeLabel=Hello from Cuba!
navBtn=Navigator
profileBtn=Change profile
logoutBtn=Logout
loggedInLabel=Logged in as %s (%s)
logoLabel=CUBA Application
loggedInLabel=Logged in as %s
viewLogBtn=View Log
closeBtn=Close