13 Replies Latest reply on Jul 1, 2009 11:05 AM by Nils Preusker

    Indentityservice- Jbpm4

    Shekhar Vemuri Newbie

      How would we 'register' a custom implementation of the identity service within jbpm4?

      So if I needed to use it to implement a different kind of auth provider, instead of a db backed one?

      Thanks,

        • 1. Re: Indentityservice- Jbpm4
          Ronald van Kuijk Master

          Best is to start with the source, since these parts are not documented yet. If you do, would be nice if you could e.g blog about it

          • 2. Re: Indentityservice - Jbpm4
            Nils Preusker Newbie

            Hi all,

            I've tried to register a custom IdentitySessionImpl the way it is described in chapter 9 of the user guide (implementing org.jbpm.session.IdentitySession - which has been moved to org.jbpm.pvm.internal.identity.spi.IdentitySession - and configuring it in the trasnaction-context of the jBPM configuration as <object class="your.package.YourIdentitySession" />). However it looks as though the configuration is ignored and the internal implementation of the identity session (org.jbpm.pvm.internal.identity.impl.IdentitySessionImpl) is always used. A quick look at the source code suggests that the IdentitySessionBinding contains a hard-coded reference to org.jbpm.pvm.internal.identity.impl.IdentitySessionImpl, which explains this behavior. Now I've heard that some restructuring of the identity component is on its way, so my question is whether there is a way to get this to work at the moment. (I'm working with the jBPM4 trunk at revision 5066.)

            Cheers, Nils

            • 3. Re: Indentityservice- Jbpm4
              Ronald van Kuijk Master

              By changing the source? So the hardcoded reference is not there anymore? (I've not had a look at the source for this part so I'm just suggesting).

              If you want to help and make it fully plugable (which is not targeted at the 4.0 release) please discuss things in the dev forum.

              • 4. Re: Indentityservice- Jbpm4
                Shekhar Vemuri Newbie

                http://www.jboss.org/index.html?module=bb&op=viewtopic&t=157513

                Please refer to the above post. I posted some instructions on there too.

                I have it setup the way it is recommended in the user guide and it does work.

                You might just want to start small and modify the config within the jbpm examples folder.
                The distro comes with an examples folder that has a lot of junit testcases that one can run. This is a great place to start experimenting. Make changes to the jbpm.cfg.xml there, add whatever classes you want to add in the test folders, and see how things work and then port it to your code base.

                In fact I also have the same approach work with custom activities.

                Let us know if you have further problems,

                • 5. Re: Indentityservice- Jbpm4
                  Nils Preusker Newbie

                  Hi shekharv, thanks for the hint. However, I've seen your post before and tried the configuration that you mentioned there, but it doesn't seem to work with the current trunk version of jBPM4. I just realized, though, that there might be a better way to achieve what I'm trying. I'm integrating jBPM with an application that has its own User implementation. Now I want jBPM to use the same user table that my application is using. My initial idea was to implement my own IdentitySession and cast the users that I retrieve into org.jbpm.api.identity.User objects. But now I'm thinking that it would probably be better to just tell jBPM how to access the user table of my application by modifying the hibernate mapping of org.jbpm.api.identity.User. Maybe someone can give me a hint whether I'm heading into the right direction and (if you're feeling very generous:) give me some hints which files to edit to get the user mapping tweaked to my needs. Thanks in advance!

                  Nils

                  • 6. Re: Indentityservice- Jbpm4
                    Shekhar Vemuri Newbie

                    I was working against CR1 code. I do not have a build of current trunk to comment on whether or not it works,
                    Did you try against CR1?

                    Is there a particular reason to go against trunk code directly? Something you cannot wait to use till it is officially out :) ?.

                    I will let you know if I see anything,

                    Regarding the solution that you were trying out, it is not something that would not work, but it is not something I would do.

                    It still ties in your application domain a little too close to that of the jbpm domain. Ideally you would want them to be separated out and joined together only in a more versatile 'service' or 'application' layer.

                    It would just be too tough to change anything about the users going down the line, which at some point or the other, always happens.

                    • 7. Re: Indentityservice- Jbpm4
                      Ronald van Kuijk Master

                       

                      "shekharv" wrote:

                      Regarding the solution that you were trying out, it is not something that would not work, but it is not something I would do.

                      It still ties in your application domain a little too close to that of the jbpm domain. Ideally you would want them to be separated out and joined together only in a more versatile 'service' or 'application' layer.

                      It would just be too tough to change anything about the users going down the line, which at some point or the other, always happens.


                      I fully agree...

                      • 8. Re: Indentityservice- Jbpm4
                        Nils Preusker Newbie

                        Hi guys, thanks for your feedback! Regarding the idea of modifying the hibernate mappings of the jBPM UserImpl, I did get it to work, but I agree with your point that it ties the two application domains too close together.

                        The reason I'm working with the trunk is that I'm using some spring integration code that was only added after the CR1 release. This also means that it will be rather difficult to test with the CR1 version, since the rest of my jBPM code won't work anymore. Whats more, according to the svn logs, there haven't been any significant changes to IdentitySessionBinding.java since the CR1 release (I'm assuming this class is responsible for wiring the classes from the configuration, please correct me if I'm wrong).

                        "kukeltje" wrote:
                        If you want to help and make it fully plugable (which is not targeted at the 4.0 release) please discuss things in the dev forum.

                        I'd be happy to contribute, but to be honest, I'm a bit confused now. Shekharv's post suggest that the plugable configuration is already working, whereas the above quote indicates that it isn't even intended to be part of the 4.0 release. Maybe someone can shed some light on this.

                        Thanks! Nils

                        • 9. Re: Indentityservice- Jbpm4
                          Ronald van Kuijk Master

                          Sorry for the confusion. With 'fully pluggable' I meant 100% stable and documented api, testcases, example etc. Afaik, this is not (yet) the case and therefore it is not targeted at 4.0. This does not mean however that things will change drastically, on the contrary, most is quite ok.

                          If you have a small testcase, I'd be more than happy to give it a try and do some puzzling on my side.

                          • 10. Re: Indentityservice- Jbpm4
                            Nils Preusker Newbie

                             

                            "tom.baeyens@jboss.com" wrote:
                            here's pointers on how to plug your own identity service

                            in jbpm.cfg.xml, remove the line

                            <import resource="jbpm.identity.cfg.xml" />


                            and add

                            <transaction-context>
                             <object class="your.package.YourIdentitySessionImpl" />
                             </transaction-context>
                            


                            YourIdentitySessionImpl should implement org.jbpm.pvm.internal.identity.spi.IdentitySession

                            Making this identity pluggable is not our first target, but it was taken into the design. Let us know how it goes. I'll add these notes to the developers guide. And update them with your feedback.


                            This post in the jBPM developers forum (http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4239322) pointed me to what I was doing wrong... After removing the import of jbpm.identity.cfg.xml it all works fine now. Thanks for your help!

                            Nils

                            • 11. Re: Indentityservice- Jbpm4
                              Ronald van Kuijk Master

                              Huh? Seriously.... Then I must have done something wrong myself, since I did do this and it did not work for me. So I thought I might have the same problem as you.

                              Back to debugging....

                              • 12. Re: Indentityservice- Jbpm4
                                Nils Preusker Newbie

                                Here is my current (working) jbpm.cfg.xml:

                                <?xml version="1.0" encoding="UTF-8"?>
                                
                                <jbpm-configuration>
                                 <import resource="jbpm.jpdl.cfg.xml" />
                                 <!--<import resource="jbpm.identity.cfg.xml" /> -->
                                 <process-engine-context>
                                 <repository-service />
                                 <repository-cache />
                                 <execution-service />
                                 <history-service />
                                 <management-service />
                                 <identity-service />
                                 <task-service />
                                 <script-manager default-expression-language="juel"
                                 default-script-language="juel"
                                 read-contexts="execution, environment, process-engine, spring"
                                 write-context="">
                                 <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
                                 </script-manager>
                                 <authentication />
                                 <id-generator />
                                 <types resource="jbpm.variable.types.xml" />
                                 <address-resolver />
                                 <business-calendar>
                                 <monday hours="9:00-12:00 and 12:30-17:00"/>
                                 <tuesday hours="9:00-12:00 and 12:30-17:00"/>
                                 <wednesday hours="9:00-12:00 and 12:30-17:00"/>
                                 <thursday hours="9:00-12:00 and 12:30-17:00"/>
                                 <friday hours="9:00-12:00 and 12:30-17:00"/>
                                 <holiday period="01/07/2008 - 31/08/2008"/>
                                 </business-calendar>
                                 <mail-template name='task-notification'>
                                 <to users="${task.assignee}"/>
                                 <subject>${task.name}</subject>
                                 <text><![CDATA[Hi ${task.assignee},
                                Task "${task.name}" has been assigned to you.
                                ${task.description}
                                
                                Sent by JBoss jBPM
                                ]]></text>
                                 </mail-template>
                                 <mail-template name='task-reminder'>
                                 <to users="${task.assignee}"/>
                                 <subject>${task.name}</subject>
                                 <text><![CDATA[Hey ${task.assignee},
                                Do not forget about task "${task.name}".
                                ${task.description}
                                
                                Sent by JBoss jBPM
                                ]]></text>
                                 </mail-template>
                                 <command-service>
                                 <retry-interceptor />
                                 <environment-interceptor />
                                 <spring-transaction-interceptor current="false" />
                                 </command-service>
                                 </process-engine-context>
                                
                                 <transaction-context>
                                 <object class="mypackage.IdentitySessionImpl" />
                                 <repository-session />
                                 <db-session />
                                 <message-session />
                                 <timer-session />
                                 <history-session />
                                 <mail-session>
                                 <mail-server>
                                 <session-properties resource="jbpm.mail.properties" />
                                 </mail-server>
                                 </mail-session>
                                 <hibernate-session current="true"/>
                                
                                 </transaction-context>
                                </jbpm-configuration>


                                Except of course the "mypackage" part... I'm working with spring (using org.jbpm.pvm.internal.cfg.SpringConfiguration) and against the jBPM trunk, currently at revision 5153. Hope this helps!

                                Nils

                                • 13. Re: Indentityservice- Jbpm4
                                  Nils Preusker Newbie

                                  By the way, for spring users it might be interesting to know that you can also reference spring beans instead of a class reference in jBPM's transaction context. If you have a bean configured in your application context like this:

                                  <bean id="identitySession" class="mypackage.IdentitySessionImpl">
                                   <property name="myUserDAO" ref="myUserDAO"/>
                                  </bean>


                                  You can reference it in your jBPM configuration's transaction-context (jbpm.cfg.xml) like this:
                                  <transaction-context>
                                   <env class="identitySession" />
                                   ...
                                  </transaction-context>