-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorkflow-Importer.xml
675 lines (566 loc) · 21.6 KB
/
Workflow-Importer.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Workflow PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Workflow explicitTransitions="true" name="Importer" type="">
<Variable name="result" output="true"/>
<Variable name="transient" initializer="true"/>
<Variable input="true" name="resource"/>
<Variable input="true" name="operation"/>
<Variable name="payload" type="java.lang.Object" output="true"/>
<Step icon="Start" name="Start" posX="67" posY="354">
<Script>
<Source><![CDATA[
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer");
serilog.debug("operation="+operation);
]]></Source>
</Script>
<Transition to="Import">
<Script>
<Source><![CDATA[return "Import".equals(operation);]]></Source>
</Script>
</Transition>
<Transition to="Get Object Types">
<Script>
<Source><![CDATA[return "getObjectTypes".equals(operation);]]></Source>
</Script>
</Transition>
<Transition to="Get Objects" when=""getObjects".equals(operation);"/>
<Transition to="Get Latest Objects" when=""getLatestObjects".equals(operation);"/>
<Transition to="Get Object" when=""getObject".equals(operation);"/>
<Transition to="Get Jar Size" when=""jarSize".equals(operation);"/>
<Transition to="Get Jar Data" when=""jarData".equals(operation);"/>
<Transition to="Get Task List" when=""getTaskList".equals(operation);"/>
<Transition to="Run Task" when=""runTask".equals(operation);"/>
<Transition to="Terminate Task" when=""terminateTask".equals(operation);"/>
<Transition to="Get Task Result" when=""getTaskResult".equals(operation);"/>
<Transition to="Invalid operation"/>
</Step>
<Step icon="Provision" name="Import" posX="352" posY="121" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.server.Importer;
import sailpoint.tools.GeneralException;
import sailpoint.web.system.ImportBean.ImportMonitor;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer");
serilog.debug("--");
String fileData = workflow.get("resource");
serilog.debug("fileData="+fileData);
ImportMonitor _monitor = new ImportMonitor();
Importer importer = new Importer(context, _monitor);
serilog.debug("got importer");
try {
importer.importXml(fileData);
context.commitTransaction();
workflow.put("result", "success");
} catch (Exception ex) {
serilog.error("Exception :"+ex);
workflow.put("result", "failure");
if (ex instanceof GeneralException) {
GeneralException ge = (GeneralException) ex;
return ge.getMessageInstance();
} else {
return ex.getLocalizedMessage();
}
}
return "";
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Object Types" posX="354" posY="194" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.object.ClassLists;
List l = new ArrayList();
for (Class clazz: ClassLists.MajorClasses) {
l.add(clazz.getSimpleName());
}
// Add this in, its a special type of Identity
l.add("Workgroup");
Collections.sort(l);
workflow.put("result", "success");
return l;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Invalid operation" posX="354" posY="44" resultVariable="payload">
<Script>
<Source><![CDATA[
workflow.put("result", "failure");
return "Invalid Operation";
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Stop" name="Stop" posX="509" posY="351"/>
<Step icon="Default" name="Get Objects" posX="355" posY="272" resultVariable="payload">
<Script>
<Source><![CDATA[
// objectType is a 'simple' class name (no package)
// look it up in ClassList
import sailpoint.object.ClassLists;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
// Expect: java.lang.String objectType
// Expect: java.lang.String objectName
Class theClass=null;
boolean isWorkgroup=false;
if("Workgroup".equals(objectType)) {
objectType="Identity";
isWorkgroup=true;
}
for (Class clazz: ClassLists.MajorClasses) {
if(clazz.getSimpleName().equals(objectType) ){
theClass=clazz;
break;
}
}
if(theClass==null) {
workflow.put("result", "failure");
return "Could not find object type '"+objectType+"'";
}
QueryOptions qo=new QueryOptions();
if (isWorkgroup) {
qo.addFilter(Filter.eq("workgroup", Boolean.TRUE));
}
String searchField="name";
if ("TaskSchedule".equals(objectType)) {
searchField="id";
}
Iterator iter=context.search(theClass, qo, searchField);
List objects=new ArrayList();
while(iter.hasNext()) {
Object[] obj=iter.next();
objects.add(obj[0]);
}
workflow.put("result", "success");
return objects;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Task List" posX="355" posY="272" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.object.TaskDefinition;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.GetTaskList");
List tasks=context.getObjects(TaskDefinition.class);
serilog.debug("got "+tasks.size());
List objects=new ArrayList();
for (TaskDefinition td: tasks) {
if(!td.isHidden() && !td.isTemplate() ){
objects.add(td.getName());
}
}
workflow.put("result", "success");
serilog.debug("returning "+objects.size()+" tasks");
return objects;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Run Task" posX="355" posY="272" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.object.TaskDefinition;
import sailpoint.api.TaskManager;
import sailpoint.object.TaskSchedule;
import sailpoint.object.TaskResult;
// Expect: java.lang.String taskName
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.RunTask");
serilog.debug("Run Task: "+taskName);
TaskManager tm = new TaskManager(context);
Map args=new HashMap();
TaskDefinition td=context.getObjectByName(TaskDefinition.class, taskName);
if(td==null) {
workflow.put("result", "failure");
return "Task '"+taskName+"' not found";
}
TaskSchedule ts=tm.run(td, args);
TaskResult tr=null;
while (tr==null) {
tr=ts.getLatestResult();
serilog.debug("task result="+tr);
}
workflow.put("result", "success");
return tr.getId();
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Terminate Task" posX="355" posY="272" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.api.TaskManager;
import sailpoint.object.TaskResult;
// Expect: java.lang.String taskName
// Expect: java.lang.String taskId
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.TerminateTask");
serilog.debug("Terminate Task: "+taskId);
TaskResult tr=context.getObjectById(TaskResult.class, taskId);
if(tr==null) {
workflow.put("result", "failure");
return "taskId "+taskId+" not found";
}
TaskManager tm=new TaskManager(context);
tm.terminate(tr);
workflow.put("result", "success");
return tr.getId();
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Task Result" posX="355" posY="272" resultVariable="payload">
<Script>
<Source><![CDATA[
import sailpoint.object.Attributes;
import sailpoint.object.TaskResult;
import sailpoint.tools.Internationalizer;
import sailpoint.tools.Message;
// Expect: java.lang.String taskId
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.GetTaskResult");
serilog.debug("Get Task Result: "+taskId);
if(taskId==null) {
workflow.put("result", "failure");
return "Must specify taskId";
}
TaskResult tr=context.getObjectById(TaskResult.class, taskId);
if(tr==null) {
workflow.put("result", "failure");
return "taskId "+taskId+" not found";
}
Map result=new HashMap();
result.put("name", tr.getName());
result.put("description", tr.getDefinition().getDescription().trim());
if (tr.getCompletionStatus()==null) {
result.put("status", "pending..");
} else {
String statusKey=tr.getCompletionStatus().getMessageKey();
result.put("status", Internationalizer.getMessage(statusKey, Locale.ENGLISH));
}
result.put("progress", tr.getProgress());
result.put("started", tr.getLaunched().toString());
if(tr.getCompleted()!=null) {
result.put("completed", tr.getCompleted().toString());
}
List errors=tr.getMessages();
if (errors!=null) {
List flatErrors=new ArrayList();
for (Message message: errors) {
flatErrors.add(message.getLocalizedMessage());
}
result.put("errors", flatErrors);
}
Attributes attrs=tr.getAttributes();
if (attrs!=null) {
Map flatAttrs=new HashMap();
for (String key: attrs.getKeys()) {
flatAttrs.put(key, attrs.getString(key));
}
result.put("attributes", flatAttrs);
}
workflow.put("result", "success");
return result;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Object" posX="353" posY="350" resultVariable="payload">
<Script>
<Source><![CDATA[
// objectType is a 'simple' class name (no package)
// look it up in ClassList
import sailpoint.object.ClassLists;
import sailpoint.object.SailPointObject;
// Expect: java.lang.String objectType
// Expect: java.lang.String objectName
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.getObject");
serilog.debug("objectType="+objectType);
serilog.debug("objectName="+objectName);
Class theClass=null;
if ("Workgroup".equals(objectType)) {
objectType="Identity";
}
for (Class clazz: ClassLists.MajorClasses) {
if(clazz.getSimpleName().equals(objectType) ){
theClass=clazz;
break;
}
}
if(theClass==null) {
workflow.put("result", "failure");
return "Could not find object type '"+objectType+"'";
}
SailPointObject obj=context.getObjectByName(theClass, objectName);
if(obj==null) {
workflow.put("result", "failure");
return "Could not find "+objectType+" '"+objectName+"'";
}
serilog.debug("obj="+obj);
workflow.put("result", "success");
return obj.toXml();
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Jar Size" posX="356" posY="434" resultVariable="payload">
<Script>
<Source><![CDATA[
// jarName is the name of a jar in WEB-INF/lib
// return a JSON string of the binary
import java.io.File;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.codec.binary.Base64;
import sailpoint.object.ClassLists;
import sailpoint.object.SailPointObject;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.jarSize");
serilog.debug("jar="+jar);
if(jar==null||jar==void) {
workflow.put("result", "failure");
return("No JAR Specified");
}
URL url=this.getClass().getResource("/../lib/"+jar);
serilog.debug("url="+url);
if(url==null) {
workflow.put("result", "failure");
return("JAR '"+jar+"' not found");
}
serilog.debug("got URL");
File file=new File(url.toURI());
workflow.put("result", "success");
String ret=Long.toString(file.length());
serilog.debug("returning "+ret);
return ret
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Jar Data" posX="356" posY="515" resultVariable="payload">
<Script>
<Source><![CDATA[
// jarName is the name of a jar in WEB-INF/lib
// return a JSON string of the binary
import java.io.File;
import java.io.InputStream;
import org.apache.commons.codec.binary.Base64;
import sailpoint.object.ClassLists;
import sailpoint.object.SailPointObject;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.Importer.getJarData");
serilog.trace("jar="+jar);
serilog.trace("start="+start);
serilog.trace("length="+length);
iStart=Integer.parseInt(start);
iLength=Integer.parseInt(length);
if(jar==null||jar==void) {
workflow.put("result", "failure");
return("No JAR Specified");
}
URL url=this.getClass().getResource("/../lib/"+jar);
serilog.trace("url="+url);
if(url==null) {
workflow.put("result", "failure");
return("JAR '"+jar+"' not found");
}
File file=new File(url.toURI());
RandomAccessFile raFile=new RandomAccessFile(file, "r");
serilog.debug("skipping "+iStart+" bytes");
raFile.skipBytes(iStart);
byte[] buffer=new byte[iLength];
int bytesRead=raFile.read(buffer, 0, iLength);
serilog.trace("read "+bytesRead+" bytes");
if(bytesRead<iLength) {
serilog.debug("eof: found "+bytesRead+" bytes, not "+iLength);
byte[] buf=new byte[bytesRead];
System.arraycopy(buffer, 0, buf, 0, bytesRead);
buffer=buf;
}
String out=Base64.encodeBase64String(buffer);
workflow.put("result", "success");
serilog.trace("returning "+out);
return out;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
<Step icon="Default" name="Get Latest Objects" posX="360" posY="599" resultVariable="payload">
<Script>
<Source><![CDATA[
import java.text.*;
import sailpoint.object.*;
// Expect: java.lang.String classes
// classes is a CSV list of the selected classes in the UI
// Declare a logger class for us to isolate these messages during aggregation.
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.iiqda.importer.getLatestObjects");
// log.setLevel(Level.DEBUG);
// The maximuim number of objects to return back to the querying item.
int maxObjectsToReturn = 100;
// We return back a sorted array list of objects that were recently modified.
// Format of each CSV entry, with exampels below a header line:
// objectType, objectName, modifiedDate
// Application, AD-CorpDomain, 2014-09-17 14:35:15
// Rule, AD-Correlation, 2014-09-16 14:34:46
// etc.
// This workflow passes this list back to the caller.
ArrayList recentlyModifiedCSVStrings = new ArrayList();
// We decalre a TreeSet to store the recently modified records. This allows
// us to keep track of the "maxObjectsToReturn" most recently modified objects.
TreeSet objStrTreeSet = new TreeSet();
// Certain classes do not contain modified dates, which is yucky.
// Mainually maintain a list of classes here that we know do not have
// modified dates. We skip these classes from the import/export list.
// Some are missing the 'name' property as well, those get added here too.
ArrayList skipClasses = new ArrayList();
skipClasses.add("ApplicationActivity");
skipClasses.add("ApplicationScorecard");
skipClasses.add("AuditEvent");
skipClasses.add("AuthenticationQuestion");
skipClasses.add("BatchRequest");
skipClasses.add("DatabaseVersion");
skipClasses.add("GroupIndex");
skipClasses.add("Identity"); // We don't want to export each Id.
skipClasses.add("IdentityEntitlement");
skipClasses.add("IdentityHistoryItem");
skipClasses.add("IdentitySnapshot"); // We don't export Identity Snapshots.
skipClasses.add("JasperTemplate");
skipClasses.add("JasperResult");
skipClasses.add("ManagedAttribute");
skipClasses.add("MitigationExpiration");
skipClasses.add("PolicyViolation"); // We don't export Policy Violations.
skipClasses.add("Profile");
skipClasses.add("ProcessLog");
skipClasses.add("ProvisioningRequest");
skipClasses.add("QuickLinkOptions");
skipClasses.add("ResourceEvent");
skipClasses.add("RoleChangeEvent");
skipClasses.add("RoleIndex");
skipClasses.add("RoleMetadata");
skipClasses.add("RoleScorecard");
skipClasses.add("Scorecard");
skipClasses.add("Server"); // Skip the Server objects.
skipClasses.add("SyslogEvent");
skipClasses.add("TargetAssociation");
skipClasses.add("TaskSchedule"); // Included for invalid query options.
skipClasses.add("TaskResult"); // We don't export TaskResult.
skipClasses.add("UIPreferences");
List majClasses = new ArrayList();
if (classes==null) {
// Ask sailpoint.object.ClassLists for what major classes are defined.
for (Class clazz: ClassLists.MajorClasses) {
String simpleName = clazz.getSimpleName();
if ( !skipClasses.contains(simpleName) ) {
majClasses.add(clazz.getSimpleName());
}
}
majClasses.add("Workgroup");
} else {
String[] strClasses=classes.split(",");
majClasses=Arrays.asList(strClasses);
}
Collections.sort(majClasses);
// We now have a list of all the major configurable IdentityIQ classes.
// Next we need to projection query pull back name, created, modified time
// for each item.
// Use a projection query to initially pull back only the columns we need.
ArrayList resultColumns = new ArrayList();
resultColumns.add("id");
resultColumns.add("name");
resultColumns.add("created");
resultColumns.add("modified");
QueryOptions qo = new QueryOptions();
qo.setResultLimit(maxObjectsToReturn);
ArrayList orderings = new ArrayList();
orderings.add( new QueryOptions.Ordering( "modified", false ) );
orderings.add( new QueryOptions.Ordering( "created", false ) );
qo.setOrderings(orderings);
for (String className : majClasses) {
boolean isWorkgroup=false;
String fullClassName = "sailpoint.object." + className;
if("Workgroup".equals(className)) {
isWorkgroup=true;
}
serilog.debug("Examining class: " + fullClassName);
Iterator it=null;
if (isWorkgroup) {
QueryOptions wgQo=new QueryOptions(qo);
wgQo.addFilter(Filter.eq("workgroup", Boolean.TRUE));
it = context.search(Identity.class, wgQo, resultColumns);
} else {
Class clazz = Class.forName(fullClassName);
if (null == clazz) {
serilog.error("could not load class forName: " + fullClassName);
continue;
}
it = context.search(clazz, qo, resultColumns);
}
while (it.hasNext()) {
Object [] result = it.next();
String id = (String) result[0];
String name = (String) result[1];
Date createdDate = (java.util.Date) result[2];
Date modifiedDate = (java.util.Date) result[3];
// If no modified date substituting
if (null == createdDate) {
createdDate = new Date();
}
// If no modified date substituting
if (null == modifiedDate) {
modifiedDate = createdDate;
}
String created = createdDate.toString();
String modified = modifiedDate.toString();
// Create a date string sortable by string operations.
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String createdSortable = formatter.format(createdDate);
String modifiedSortable = formatter.format(modifiedDate);
// We buld a sortable delimited string, with the modified date first so
// that the date primarily controls the sorting. The format of the string:
// modifiedDate,className,objectName,objectId
// Once we have the sortable string we put that in a TreeSet so that
// we can monitor the size of the tree set and only keep the N most
// recently created/modified objects in the tree.
String sortableString =
modifiedSortable + "," + className + "," + name + "," + id;
serilog.debug("object:" + sortableString);
// serilog.debug("Class: " + className + " id:" + id + " modified:" + modifiedSortable + " name:" + name);
serilog.debug("objStrTreeSet.size(): " + objStrTreeSet.size());
if (objStrTreeSet.size() < maxObjectsToReturn) {
// We have not added the max objects to the tree set, add this one.
objStrTreeSet.add(sortableString);
} else {
// The tree set has the full number of objects. If this new
// object's modified date is older than the oldest in the tree set
// then do not add it. Otherwise, add it to the tree set
// and then remove the lowest modified date from the tree set.
String leastRecentlyModified = objStrTreeSet.first();
if ( 0 > sortableString.compareTo(leastRecentlyModified) ) {
serilog.debug("older than oldest: skipping");
// The current objects modified date is earlier than the oldest
// in the tree set. Do not add the current object to the tree set.
} else {
serilog.debug("newer than oldest: adding to list");
// The current object is more recently modified than at least one
// object in the tree set. Add the current object to the tree set
// and remove the lowest object in the tree set.
objStrTreeSet.add(sortableString);
objStrTreeSet.remove(leastRecentlyModified);
}
}
}
}
// At this point we have a populated TreeSet of objStrTreeSet size. This
// has the objStrTreeSet most recently modified objects in the IdentityIQ
// system. Convert that to an ArrayList of strings and return that to
// the caller for passing back to Eclipse or other external tooling.
while ( 0 != objStrTreeSet.size() ) {
String mostRecentlyModified = objStrTreeSet.last();
recentlyModifiedCSVStrings.add(mostRecentlyModified);
objStrTreeSet.remove(mostRecentlyModified);
}
workflow.put("result", "success");
return recentlyModifiedCSVStrings;
]]></Source>
</Script>
<Transition to="Stop"/>
</Step>
</Workflow>