private final static Logger LOGGER = Logger.getLogger(DemoDataGenerator.class.getName());
public void createUsers(ProcessEngine engine) {
final IdentityService identityService = engine.getIdentityService();
if(identityService.isReadOnly()) {
LOGGER.info("Identity service provider is Read Only, not creating any demo users.");
return;
}
User singleResult = identityService.createUserQuery().userId("demo").singleResult();
if (singleResult != null) {
return;
}
LOGGER.info("Generating demo data for invoice showcase");
User user = identityService.newUser("demo");
user.setFirstName("Demo");
user.setLastName("Demo");
user.setPassword("demo");
user.setEmail("demo@camunda.org");
identityService.saveUser(user);
User user2 = identityService.newUser("john");
user2.setFirstName("John");
user2.setLastName("Doe");
user2.setPassword("john");
user2.setEmail("john@camunda.org");
identityService.saveUser(user2);
User user3 = identityService.newUser("mary");
user3.setFirstName("Mary");
user3.setLastName("Anne");
user3.setPassword("mary");
user3.setEmail("mary@camunda.org");
identityService.saveUser(user3);
User user4 = identityService.newUser("peter");
user4.setFirstName("Peter");
user4.setLastName("Meter");
user4.setPassword("peter");
user4.setEmail("peter@camunda.org");
identityService.saveUser(user4);
Group salesGroup = identityService.newGroup("sales");
salesGroup.setName("Sales");
salesGroup.setType("WORKFLOW");
identityService.saveGroup(salesGroup);
Group accountingGroup = identityService.newGroup("accounting");
accountingGroup.setName("Accounting");
accountingGroup.setType("WORKFLOW");
identityService.saveGroup(accountingGroup);
Group managementGroup = identityService.newGroup("management");
managementGroup.setName("Management");
managementGroup.setType("WORKFLOW");
identityService.saveGroup(managementGroup);
final AuthorizationService authorizationService = engine.getAuthorizationService();
// create group
if(identityService.createGroupQuery().groupId(Groups.CAMUNDA_ADMIN).count() == 0) {
Group camundaAdminGroup = identityService.newGroup(Groups.CAMUNDA_ADMIN);
camundaAdminGroup.setName("camunda BPM Administrators");
camundaAdminGroup.setType(Groups.GROUP_TYPE_SYSTEM);
identityService.saveGroup(camundaAdminGroup);
}
// create ADMIN authorizations on all built-in resources
for (Resource resource : Resources.values()) {
if(authorizationService.createAuthorizationQuery().groupIdIn(Groups.CAMUNDA_ADMIN).resourceType(resource).resourceId(ANY).count() == 0) {
AuthorizationEntity userAdminAuth = new AuthorizationEntity(AUTH_TYPE_GRANT);
userAdminAuth.setGroupId(Groups.CAMUNDA_ADMIN);
userAdminAuth.setResource(resource);
userAdminAuth.setResourceId(ANY);
userAdminAuth.addPermission(ALL);
authorizationService.saveAuthorization(userAdminAuth);
}
}
identityService.createMembership("demo", "sales");
identityService.createMembership("demo", "accounting");
identityService.createMembership("demo", "management");
identityService.createMembership("demo", "camunda-admin");
identityService.createMembership("john", "sales");
identityService.createMembership("mary", "accounting");
identityService.createMembership("peter", "management");
// authorize groups for tasklist only:
Authorization salesTasklistAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);