2 title =
> 'Steps to create a new custom workflow'
4 <h1>Steps to create a new custom workflow
</h1>
5 <h3>by David Hetzl
</h3>
8 The new workflow will be called
"example_wf_request" throughout this document.
9 For creating customized workflows this text has to be substituted with
10 whatever name is chosen for the actual workflow.
14 Files that need to be created:
16 <li><a href=
"#eins">workflow_def_example_wf_request.xml
</a>
17 <li><a href=
"#zwei">workflow_activity_example_wf_request.xml
</a>
18 <li><a href=
"#drei">workflow_validator_example_wf_request.xml
</a>
23 Files that need to be changed:
25 <li><a href=
"#vier">workflow.xml
</a>
26 <li><a href=
"#fuenf">workflow_condition.xml
</a> (only if conditions are used)
27 <li><a href=
"#sechs">notification.xml
</a> (only if notification is required)
33 <h2><a name=
"eins">1) File 'workflow_def_example_wf_request.xml'
</a></h2>
36 This file specifies the different states which are valid for the corresponding workflow.
37 For each state zero to many activities (= actions) can be stated, which will define the valid state transitions. These are explained in detail in the next section.
41 States can be declared as autorun, meaning that the stated action should be run automatically once the
42 workflow switches to this state. If more than one workflow activity is specified a condition must be used to decide
43 which of the actions must be executed.
49 <state
name=
"<b>APPROVED</b>" autorun=
"yes">
50 <description
>I18N_OPENXPKI_WF_STATE_EXTERNAL_CERTIFICATE_TRUST_REQUEST_APPROVAL
</description
>
51 <action
name=
"<b>create_database_entry</b>"
52 resulting_state=
"<b>ENTRY_CREATED</b>">
53 <condition
name=
"<b>secure_email_set</b>"/
>
56 <action
name=
"<b>finish_transaction</b>"
57 resulting_state=
"<b>SUCCESS</b>">
58 <condition
name=
"<b>!secure_email_set</b>"/
>
65 This example specifies the state
"<i>APPROVED</i>". Once the workflow reaches this state it automatically executes the action
66 "<i>create_database_entry</i>" or
"<i>finish_transaction</i>", depending on the current value of the evaluated condition
67 "<i>secure_email_set</i>". The resulting state also differs based on this evaluation (
"<i>ENTRY_CREATED</i>" or
"<i>SUCCESS</i>"). Note that '!' can be used to invert the result of a condition.
71 <b>Activities (=actions)
</b> mentioned in this file are specified as following:
75 <action
name=
"<b>finish_transaction</b>"
76 resulting_state=
"<b>SUCCESS</b>">
77 <condition
name=
"<b>!secure_email_set</b>"/
>
82 For a detailed explanation about 'Activities' please refer to the section
<a href=
"#zwei">File 'workflow_activity_example_wf_request.xml'
</a>.
86 <b>Conditions
</b> are specifed as follows:
90 <condition
name=
"<b>secure_email_set</b>"/
>
94 Please refer to section
<a href=
"#fuenf">File 'workflow_condition.xml'
</a> for a detailed explanation on conditions.
98 <h2><a name=
"zwei">2) File 'workflow_activity_example_wf_request.xml'
</a></h2>
101 This file goes into more detail regarding activities (which are called
"actions" in the Workflow.pm definitions). Activities are Perl modules which should return
1 after succesfull completion.
102 Any kind of operations can be performed here, but typically this involves workflow manipulations or even database transactions. E.g.
103 adding a certificate file which was uploaded through the OpenXPKI web interface to the certificate database.
104 The module must have an execute() method, which will be executed during runtime. All activities inherit from the
"Activity" module
105 ('use base qw( OpenXPKI::Server::Workflow::Activity );').
106 Parameters for activities can be passed in the 'action' tag of the XMl definition file.
110 Every action of this custom workflow must be specified in this file and all fields (variables that are saved in the workflow) have to be stated which are changed
111 or created during this activity's execution. Failure to do so will result in an exception when trying to access a field name which has not
112 been specified. Also all validators which have to be evaluated during this activity are named here.
113 The actual Perl module/class that is called when executing the action is part of the action tag, as can be seen in the next example:
117 <action
name=
"import_data"
118 class=
"<b>Workflow::Action::Null</b>">
120 <field
name=
"cert_data"/
> <!-- X
.509-Certificate in PEM --
>
121 <field
name=
"company"/
> <!-- Name of the external company --
>
122 <field
name=
"comment"/
> <!-- Comments from creator --
>
124 <!-- Checks if the RT ticket ID is existing--
>
125 <validator
name=
"TicketExists">
128 <!-- Checks if CRL is accessible, when specified --
>
129 <validator
name=
"CRLaccessible">
136 This action will invoke the module
<i>workflow::Action:Null
</i>, which just does nothing but can be used when there is no need to do anything
"special". It is called from the HTML::Mason code which just saves the mentioned fields into the workflow if no validators
137 fail. It has two validators which will both be evaluated and the action will only complete successfully if both return the value
1.
141 Another example for an action tag which includes a parameter follows:
145 <action
name=
"process_crr"
146 class=
"OpenXPKI::Server::Workflow::Activity::Tools::Export"
147 <b>use_destination
</b>=
"0">
152 This action parameters can be queried from within the Perl module like this:
158 my $dest = $self-
>param('
<b>use_destination
</b>');
162 A special kind of action uses the notification module. This can be called when there is the need to interact with the request tracking system. An example can be seen below:
166 <action
name=
"close_removal_ticket"
167 class=
"<b>OpenXPKI::Server::Workflow::Activity::Tools::Notification</b>"
168 message=
"<b>ect_removal_close</b>">
173 It invokes the special
"<i>Notification</i>" module which reads the
<a href=
"#sechs">notification.xml
</a> file to see which interactions are linked with the parameter that is passed in the message tag (
"<i>ect_removal_close</i>") and executes them.
174 Currently there is the option to open new tickets, close existing ones, create a new comment in a ticket and create a correspondence (which sends out an email to the requestor of the ticket). When this module is used all messages have to be specified accordingly in the
<a href=
"#sechs"><i>notification.xml
</i></a> file.
178 The validators are specified in this file like the following example:
182 <validator
name=
"CRLaccessible"
187 Please refer to the next section for a detailed explanation of validators.
191 <h2><a name=
"drei">3) File 'workflow_validator_example_wf_request.xml'
</a></h2>
194 This file describes the validators which have been named in the file of the last section.
195 Validators must evaluate to true (=
1) or else the corresponding activity will not be executed. They inherit from the base class
196 'Workflow::Validator' ('use base qw( Workflow::Validator );') and all processing is done in the validate() method.
197 If the validation fails it should return a descriptive exception of what went wrong.
198 Also paramater names can be specified, whose values can be derived from within the Perl module. This is useful for setting config items without the need to change the Perl source code and recompile it.
199 The following example specifies the validator
"<i>ValidApprovalSignature</i>":
204 <validator
name=
"<b>ValidApprovalSignature</b>"
205 class=
"OpenXPKI::Server::Workflow::Validator::ApprovalSignature">
206 <!-- if you set the following parameter to
1, you can enforce
207 signatures on all CSR approvals --
>
208 <param
name=
"<b>signature_required</b>" value=
"0"/
>
213 The validator parameter
"<i>signature_required</i>" can be accessed from within a Perl module in the _init() method with the following syntax example:
218 my ( $self, $params ) = @_;
219 if (exists $params-
>{'
<b>signature_required
</b>'}) {
220 $self-
>signature_required($params-
>{'signature_required'});
228 <h2><a name=
"vier">4) File 'workflow.xml'
</a></h2>
231 This file lists all 'worflows', 'activities', 'validators' and 'conditions' below the corresponding sections. For our example we would need to add the following three lines:
235 <xi:include
xmlns:xi=
"http://www.w3.org/2001/XInclude" href=
"workflow_def_example_wf_request.xml"/
>
236 <xi:include
xmlns:xi=
"http://www.w3.org/2001/XInclude" href=
"workflow_activity_example_wf_request.xml"/
>
237 <xi:include
xmlns:xi=
"http://www.w3.org/2001/XInclude" href=
"workflow_validator_example_wf_request.xml"/
>
241 Alternatively, if an all-in-one style deployment is used, you will need
242 to include these files at the corresponding place in your
<i>config.xml
</i>.
243 If you want to check in the changes, you will need to edit the template
244 files in
<i>trunk/deployment/etc/templates/default
</i>, which specify both options.
249 <h2><a name=
"fuenf">5) File 'workflow_condition.xml'
</a></h2>
252 This file specifies all conditions which can be used for the state transition evaluation mentioned in the '
<i>workflow_def_example_wf_request
</i>'
253 section. Conditions are Perl modules which inherit from the base class 'Workflow::Condition' ('use base qw( Workflow::Condition );').
254 After evaluation they either return
1 (=condition is true) or an exception (=condition is false). The condition check is done by calling
255 its
<i>evaluate()
</i> method, so this is where the implementation should go.
259 The '
<i>condition
</i>' tag includes a logical name and a binding to a Perl module, which is evaluated. The condition used in our former
260 example is defined as follows:
264 <condition
name=
"secure_email_set" class=
"OpenXPKI::Server::Workflow::Condition::SecureEmailSet">
265 <param
name=
"<b>RDN_filter</b>" value=
"CN,O"/
>
270 The condition parameter, used in this example, can be accessed from within the Perl module in the
<i>_init()
</i> method like follows:
274 __PACKAGE__-
>mk_accessors( '
<b>RDN_filter
</b>' );
277 my ( $self, $params ) = @_;
278 if (exists $params-
>{
<b>RDN_filter
</b>}) {
279 $self-
>RDN_filter($params-
>{RDN_filter});
286 Note: The mk_accessors method is used to also allow the parameter to be called from outside of the _init() method using '$self-
>RDN_filter()'.
291 ACL conditions for authorization are stated similiar, with the keyword '
<i>ACL
</i>' in front of the name.
296 <condition
name=
"<b>ACL</b>::reject_crr" class=
"OpenXPKI::Server::Workflow::Condition::<b>ACL</b>">
297 <param
name=
"activity" value=
"reject_crr"/
>
303 <h2><a name=
"sechs">6) File 'notification.xml'
</a></h2>
306 This file specifies all
"messsages" and the corresponsing actions that should be executed when this message is passed as parameter. As already mentioned there are four possible transactions that can be performed. The following section lists all of them together with an examplary usage:
310 <li><h4>Create new ticket
</h4>
312 <action
type=
"<b>open</b>">
313 <requestor
>[% creator %]
</requestor
>
314 <queue
>External CA Trust Request
</queue
>
315 <subject
>Implementation Request for [% company %]
</subject
>
319 <li><h4>Close a ticket
</h4>
321 <action
type=
"<b>close</b>"/>
324 <li><h4>Create a comment
</h4>
326 <action
type=
"<b>comment</b>">
327 <template
file=
"/etc/openxpki/instances/trustcenter1/notification/en/ect_request_comment.txt" lang=
"en_EN"/
>
331 <li><h4>Correspond (write Email to requestor)
</h4>
333 <action
type=
"<b>correspond</b>">
334 <template
file=
"/etc/openxpki/instances/trustcenter1/notification/en/ect_approved_correspond.txt" lang=
"en_EN"/
>