cancel
Showing results for 
Search instead for 
Did you mean: 

Use own User/Group-tables

antje
Champ in-the-making
Champ in-the-making
Is there a possibility to use our own user/role-tables and check the tasklist against those tables instead the activiti-tables?

Best regards
Antje
20 REPLIES 20

falko_menge
Champ in-the-making
Champ in-the-making
For storing users and groups in some external system, you can exchange the IdentitySession by an own implementation, e.g.:

ProcessEngineConfiguration processEngineConfiguration = new ProcessEngineConfiguration();
Map<Class< ? >, SessionFactory> sessionFactories = processEngineConfiguration.getSessionFactories();
sessionFactories.put(IdentitySession.class, new MyIdentitySessionFactory());
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
with:

public class MyIdentitySessionFactory implements SessionFactory {

  public Session openSession() {
    return new MyIdentitySession();
  }

}
If you are using Spring, you may want to extend the ProcessEngineFactoryBean to do this configuration for you.

antje
Champ in-the-making
Champ in-the-making
We are using Spring, but the ProcessEngineFactoryBean only has an IdentityService, no IdentitySession. What`s the difference between those classes and (how) do they work together?
How can I give a IdentitySession into the configuration with spring?

jbarrez
Star Contributor
Star Contributor
As Falko stated, you will need to extend the ProcessEngineFactoryBean and use the code Falko posten. The fact that the processEngineFactoryBean doesnt support it, is a bug.

falko_menge
Champ in-the-making
Champ in-the-making

Is this link still available? I am trying to have a look at the post you linked in connection to this story.

akakunin
Champ in-the-making
Champ in-the-making
Thanks Falko! Your code sample works exactly like it should work!

hlux
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to achieve the same thing.
I'm using activiti 5.4.

My approach was to add a CustomIdentitySessionFactory to the SpringProcessEngineConfiguration

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
    <property name="dbCycleUsed" value="true" />
    <property name="customSessionFactories">
    <list>
      <bean class="de.hlux.activiti.custom.spring.CustomIdentitySessionFactory"></bean>
    </list>
    </property>
  </bean>


public class CustomIdentitySessionFactory implements SessionFactory {

public Session openSession() {
  return (Session) new CustomIdentitySession();
}

public Class<?> getSessionType() {
  return IdentitySession.class;
}

}

This works so far.
The thing I'd like some help with is to find the best way to inject the second datasource.

ProcessConfigurationImpl uses the following code to create a SqlSessionFactory

protected void initSqlSessionFactory() {
    if (sqlSessionFactory==null) {
      InputStream inputStream = null;
      try {
        inputStream = ReflectUtil.getResourceAsStream("org/activiti/db/ibatis/activiti.ibatis.mem.conf.xml");

        // update the jdbc parameters to the configured ones…
        Environment environment = new Environment("default", transactionFactory, dataSource);
        Reader reader = new InputStreamReader(inputStream);
        XMLConfigBuilder parser = new XMLConfigBuilder(reader);
        Configuration configuration = parser.getConfiguration();
        configuration.setEnvironment(environment);
        configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR, new IbatisVariableTypeHandler());
        configuration = parser.parse();

        sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

      } catch (Exception e) {
        throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
      } finally {
        IoUtil.closeSilently(inputStream);
      }
    }
  }

That is used within the DbSqlSessionFactory

      dbSqlSessionFactory = new DbSqlSessionFactory();
      dbSqlSessionFactory.setDatabaseType(databaseType);
      dbSqlSessionFactory.setIdGenerator(idGenerator);
      dbSqlSessionFactory.setSqlSessionFactory(sqlSessionFactory);
      dbSqlSessionFactory.setDbIdentityUsed(isDbIdentityUsed);
      dbSqlSessionFactory.setDbHistoryUsed(isDbHistoryUsed);
      dbSqlSessionFactory.setDbCycleUsed(isDbCycleUsed);
      addSessionFactory(dbSqlSessionFactory);

At the moment I think, that my CustomIdentitySession should make use of a DbSqlSessionFactory,
but that of course needs to have the datasource where the users and groups are stored.

I'm not familiar enough with the design patterns used and would like to hear you opinion on my approach.
Maybe I'm completely wrong here.


greetings
hlux

mondhs
Champ in-the-making
Champ in-the-making
Hlux,

Thanks for the sample it was good starting point to integrate internal user management service to Acitviti.

I used same idea that CustomUserEntityManagerFactory factory creates CustomUserEntityManager. CustomUserEntityManager is wrapper for CustomUserDao. To represent implementaiton is really required long post. So I pushed sample project to github:https://github.com/mondhs/activiti-CustomUserManagement. Most important classes:
* org.activiti.custom.spring.CustomUserEntityManager
* org.activiti.custom.spring.CustomUserEntityManagerFactory
* org.activiti.custom.security.UserDao

Also I wanted that it would be used same user as it is already logged in using custom login form. In order to do that I needed implement:
* org.activiti.custom.explorer.ui.login.CustomDefaultLoginHandler that adapts org.activiti.custom.security.CurrentUserService results

spring configuration could be found in src/main/resources/META-INF/spring/custom-user-management-beans.xml

Similar topics:
* Exchange IdentityService (or other services) http://forums.activiti.org/en/viewtopic.php?f=4&t=427
* Use own User/Group-tables: http://forums.activiti.org/en/viewtopic.php?f=3&t=345
* How to Use own User Maangement instead of Activiti provided http://forums.activiti.org/en/viewtopic.php?f=6&t=6155

jbarrez
Star Contributor
Star Contributor
Thanks for taking the time to posts this. Really valuable!
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.