This question about doing own custom user and group table is very popular with Activiti. So I am proud the be the first guy in 2016 to ask this question again!What I have done so far is extend ProcessEngineFactoryBean
public class ProcessEngineFactoryBeanX extends ProcessEngineFactoryBean {
@Autowired
UserDao userDao;
@Autowired
GroupDao groupDao;
public ProcessEngineFactoryBeanX() {
super();
}
@Override
public ProcessEngine getObject() throws Exception {
ProcessEngine processEngineObject = super.getObject();
Map<Class<?>, SessionFactory> sF =((ProcessEngineConfigurationImpl)
processEngineObject.getProcessEngineConfiguration()).getSessionFactories();
//There should be error thrown here if sF is null
CustomUserEntityManagerFactory userEntityManagerFactory = new CustomUserEntityManagerFactory(
userDao);
CustomGroupEntityManagerFactory groupEntityManagerFactory = new CustomGroupEntityManagerFactory(
groupDao);
if (!sF.containsKey(CustomUserEntityManager.class)) {
sF.put(CustomUserEntityManager.class,
userEntityManagerFactory);
}
if (!sF.containsKey(CustomGroupEntityManager.class)) {
sF.put(CustomGroupEntityManager.class,
groupEntityManagerFactory);
}
return processEngineObject;
}
And then inject the above as configuration beans bellow
@Configuration
public class ProcessEngineConfig {
@Autowired
ProcessEngineConfigurationImpl processEngineConfiguration;
@Primary
@Bean
public ProcessEngineFactoryBean processEngineFactoryBean(){
ProcessEngineFactoryBean bean = new ProcessEngineFactoryBeanX();
bean.setProcessEngineConfiguration(processEngineConfiguration);
return bean;
}
}
I am pretty confident that the above works. And my custom manager and factory is now injectedHowever when I test with bellow code, user and group is still created in act_id_user and act_id_group table.
@Bean
InitializingBean usersAndGroupsInitializer(
final IdentityService identityService) {
final Logger log = LoggerFactory.getLogger(this.getClass());
return new InitializingBean() {
public void afterPropertiesSet() throws Exception {
Group group = identityService.newGroup("user");
group.setName("users");
group.setType("security-role");
identityService.saveGroup(group);
User admin = identityService.newUser("rootadmin");
admin.setPassword("admin");
identityService.saveUser(admin);
}
};
}
What should then be my conclusion? Can I conclude that - my customized identity service using own user and group table is not working?OR- whatever my customization, IdentityService will always create user and group in act_id_user and act_id_group table?