/
AssignmentProcessor.java
1406 lines (1231 loc) · 73.8 KB
/
AssignmentProcessor.java
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.model.impl.lens.projector;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.common.ActivationComputer;
import com.evolveum.midpoint.common.refinery.ResourceShadowDiscriminator;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision;
import com.evolveum.midpoint.model.common.expression.ItemDeltaItem;
import com.evolveum.midpoint.model.common.expression.ObjectDeltaObject;
import com.evolveum.midpoint.model.common.mapping.Mapping;
import com.evolveum.midpoint.model.common.mapping.MappingFactory;
import com.evolveum.midpoint.model.impl.controller.ModelUtils;
import com.evolveum.midpoint.model.impl.lens.AssignmentEvaluator;
import com.evolveum.midpoint.model.impl.lens.AssignmentPath;
import com.evolveum.midpoint.model.impl.lens.AssignmentPathSegment;
import com.evolveum.midpoint.model.impl.lens.Construction;
import com.evolveum.midpoint.model.impl.lens.ConstructionPack;
import com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment;
import com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.model.impl.lens.LensFocusContext;
import com.evolveum.midpoint.model.impl.lens.LensProjectionContext;
import com.evolveum.midpoint.model.impl.lens.LensUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.DeltaMapTriple;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PlusMinusZero;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
/**
* Assignment processor is recomputing user assignments. It recomputes all the assignements whether they are direct
* or indirect (roles).
*
* Processor does not do the complete recompute. Only the account "existence" is recomputed. I.e. the processor determines
* what accounts should be added, deleted or kept as they are. The result is marked in account context SynchronizationPolicyDecision.
* This step does not create any deltas. It recomputes the attributes to delta set triples but does not "refine" them to deltas yet.
* It cannot create deltas as other mapping may interfere, e.g. outbound mappings. These needs to be computed before we can
* create the final deltas (because there may be mapping exclusions, interference of weak mappings, etc.)
*
* The result of assignment processor are intermediary data in the context such as LensContext.evaluatedAssignmentTriple and
* LensProjectionContext.accountConstructionDeltaSetTriple.
*
* @author Radovan Semancik
*/
@Component
public class AssignmentProcessor {
@Autowired(required = true)
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;
@Autowired(required = true)
private ObjectResolver objectResolver;
@Autowired(required = true)
private PrismContext prismContext;
@Autowired(required = true)
private MappingFactory mappingFactory;
@Autowired(required = true)
private ProvisioningService provisioningService;
@Autowired(required = true)
private ActivationComputer activationComputer;
@Autowired(required = true)
private ObjectTemplateProcessor objectTemplateProcessor;
private static final Trace LOGGER = TraceManager.getTrace(AssignmentProcessor.class);
/**
* Processing all the assignments to determine which projections should be added, deleted or kept as they are.
* Generic method for all projection types (theoretically).
*/
public <O extends ObjectType> void processAssignmentsProjections(LensContext<O> context, XMLGregorianCalendar now,
Task task, OperationResult result) throws SchemaException,
ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
LensFocusContext<O> focusContext = context.getFocusContext();
if (focusContext == null) {
return;
}
if (!FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) {
// We can do this only for FocusType.
return;
}
// if (ModelExecuteOptions.isLimitPropagation(context.getOptions()) && SchemaConstants.CHANGE_CHANNEL_DISCOVERY.equals(QNameUtil.uriToQName(context.getChannel()))){
// //do not execute assignment if the execution was triggered by compensation mechanism and limitPropagation is set
// return;
// }
processAssignmentsProjectionsWithFocus((LensContext<? extends FocusType>)context, now, task, result);
}
/**
* Processing focus-projection assignments (including roles).
*/
private <F extends FocusType> void processAssignmentsProjectionsWithFocus(LensContext<F> context, XMLGregorianCalendar now,
Task task, OperationResult result) throws SchemaException,
ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
ObjectDelta<F> focusDelta = focusContext.getDelta();
if (focusDelta != null && focusDelta.isDelete()) {
processFocusDelete(context, result);
return;
}
// Normal processing. The enforcement policy requires that assigned accounts should be added, so we need to figure out
// which assignments were added. Do a complete recompute for all the enforcement modes. We can do that because this does
// not create deltas, it just creates the triples. So we can decide what to do later when we convert triples to deltas.
Collection<PrismContainerValue<AssignmentType>> assignmentsCurrent = new ArrayList<PrismContainerValue<AssignmentType>>();
if (focusContext.getObjectCurrent() != null) {
PrismContainer<AssignmentType> assignmentContainer = focusContext.getObjectCurrent().findContainer(FocusType.F_ASSIGNMENT);
if (assignmentContainer != null) {
assignmentsCurrent.addAll(assignmentContainer.getValues());
}
}
ContainerDelta<AssignmentType> assignmentDelta = getExecutionWaveAssignmentDelta(focusContext);
assignmentDelta.expand(focusContext.getObjectCurrent());
LOGGER.trace("Assignment delta:\n{}", assignmentDelta.debugDump());
Collection<PrismContainerValue<AssignmentType>> changedAssignments = assignmentDelta.getValues(AssignmentType.class);
// Changes assignments may be "light", i.e. they may contain just the identifier. Make sure that we always have
// the full assignment data.
Iterator<PrismContainerValue<AssignmentType>> iterator = changedAssignments.iterator();
while (iterator.hasNext()) {
PrismContainerValue<AssignmentType> changedAssignment = iterator.next();
if (changedAssignment.getItems().isEmpty()) {
if (changedAssignment.getId() != null) {
for (PrismContainerValue<AssignmentType> assignmentCurrent: assignmentsCurrent) {
if (changedAssignment.getId().equals(assignmentCurrent.getId())) {
iterator.remove();
changedAssignments.add(assignmentCurrent.clone());
}
}
}
}
}
// Initializing assignment evaluator. This will be used later to process all the assignments including the nested
// assignments (roles).
AssignmentEvaluator<F> assignmentEvaluator = new AssignmentEvaluator<>();
assignmentEvaluator.setRepository(repositoryService);
assignmentEvaluator.setFocusOdo(focusContext.getObjectDeltaObject());
assignmentEvaluator.setLensContext(context);
assignmentEvaluator.setChannel(context.getChannel());
assignmentEvaluator.setObjectResolver(objectResolver);
assignmentEvaluator.setPrismContext(prismContext);
assignmentEvaluator.setMappingFactory(mappingFactory);
assignmentEvaluator.setActivationComputer(activationComputer);
assignmentEvaluator.setNow(now);
assignmentEvaluator.setSystemConfiguration(context.getSystemConfiguration());
// We will be collecting the evaluated account constructions into these three maps.
// It forms a kind of delta set triple for the account constructions.
DeltaMapTriple<ResourceShadowDiscriminator, ConstructionPack> constructionMapTriple = new DeltaMapTriple<>();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Current assignments {}", SchemaDebugUtil.prettyPrint(assignmentsCurrent));
LOGGER.trace("Changed assignments {}", SchemaDebugUtil.prettyPrint(changedAssignments));
}
// ObjectType source = determineSource(focusContext);
ObjectType source = null;
if (focusContext.getObjectCurrent() != null) {
source = focusContext.getObjectCurrent().asObjectable();
} else if (focusContext.getObjectNew() != null){
source = focusContext.getObjectNew().asObjectable();
}
DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple = new DeltaSetTriple<>();
context.setEvaluatedAssignmentTriple((DeltaSetTriple)evaluatedAssignmentTriple);
// Iterate over all the assignments. I mean really all. This is a union of the existing and changed assignments
// therefore it contains all three types of assignments (plus, minus and zero). As it is an union each assignment
// will be processed only once. Inside the loop we determine whether it was added, deleted or remains unchanged.
// This is a first step of the processing. It takes all the account constructions regardless of the resource and
// account type (intent). Therefore several constructions for the same resource and intent may appear in the resulting
// sets. This is not good as we want only a single account for each resource/intent combination. But that will be
// sorted out later.
Collection<PrismContainerValue<AssignmentType>> allAssignments = mergeAssignments(assignmentsCurrent, changedAssignments);
for (PrismContainerValue<AssignmentType> assignmentCVal : allAssignments) {
AssignmentType assignmentType = assignmentCVal.asContainerable();
PrismContainerValue<AssignmentType> assignmentCValOld = assignmentCVal;
PrismContainerValue<AssignmentType> assignmentCValNew = assignmentCVal;
ItemDeltaItem<PrismContainerValue<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
boolean forceRecon = false;
// This really means whether the WHOLE assignment was changed (e.g. added/delted/replaced). It tells nothing
// about "micro-changes" inside assignment, these will be processed later.
boolean isAssignmentChanged = containsRealValue(changedAssignments, assignmentCVal);
String assignmentPlacementDesc;
if (isAssignmentChanged) {
// Whole assignment added or deleted
assignmentPlacementDesc = "delta for "+source;
} else {
assignmentPlacementDesc = source.toString();
Collection<? extends ItemDelta<?>> assignmentItemDeltas = getExecutionWaveAssignmentItemDeltas(focusContext, assignmentCVal.getId());
if (assignmentItemDeltas != null && !assignmentItemDeltas.isEmpty()) {
// Small changes inside assignment, but otherwise the assignment stays as it is (not added or deleted)
assignmentIdi.setSubItemDeltas(assignmentItemDeltas);
// The subItemDeltas above will handle some changes. But not other.
// E.g. a replace of the whole construction will not be handled properly.
// Therefore we force recon to sort it out.
forceRecon = true;
isAssignmentChanged = true;
PrismContainer<AssignmentType> assContNew = focusContext.getObjectNew().findContainer(FocusType.F_ASSIGNMENT);
assignmentCValNew = assContNew.getValue(assignmentCVal.getId());
}
}
assignmentIdi.recompute();
// The following code is using collectToAccountMap() to collect the account constructions to one of the three "delta"
// sets (zero, plus, minus). It is handling several situations that needs to be handled specially.
// It is also collecting assignments to evaluatedAssignmentTriple.
if (focusDelta != null && focusDelta.isDelete()) {
// USER DELETE
// If focus (user) is being deleted that all the assignments are to be gone. Including those that
// were not changed explicitly.
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing focus delete for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
if (assignmentDelta.isReplace()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing replace of all assignments for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
// ASSIGNMENT REPLACE
// Handling assignment replace delta. This needs to be handled specially as all the "old"
// assignments should be considered deleted - except those that are part of the new value set
// (remain after replace). As account delete and add are costly operations (and potentially dangerous)
// we optimize here are consider the assignments that were there before replace and still are there
// after it as unchanged.
boolean hadValue = containsRealValue(assignmentsCurrent, assignmentCVal);
boolean willHaveValue = assignmentDelta.isValueToReplace(assignmentCVal, true);
if (hadValue && willHaveValue) {
// No change
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else if (willHaveValue) {
// add
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else if (hadValue) {
// delete
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
throw new SystemException("Whoops. Unexpected things happen. Assignment is not old nor new (replace delta)");
}
} else {
// ADD/DELETE of entire assignment or small changes inside existing assignments
// This is the usual situation.
// Just sort assignments to sets: unchanged (zero), added (plus), removed (minus)
if (isAssignmentChanged) {
// There was some change
boolean isAdd = assignmentDelta.isValueToAdd(assignmentCVal, true);
boolean isDelete = assignmentDelta.isValueToDelete(assignmentCVal, true);
if (isAdd & !isDelete) {
// Entirely new assignment is added
if (containsRealValue(assignmentsCurrent, assignmentCVal)) {
// Phantom add: adding assignment that is already there
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, phantom add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
}
} else if (isDelete && !isAdd) {
// Existing assignment is removed
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, delete: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
// Small change inside an assignment
// The only thing that we need to worry about is assignment validity change. That is a cause
// of provisioning/deprovisioning of the projections. So check that explicitly. Other changes are
// not significant, i.e. reconciliation can handle them.
boolean isValidOld = LensUtil.isValid(assignmentCValOld.asContainerable(), now, activationComputer);
boolean isValid = LensUtil.isValid(assignmentCValNew.asContainerable(), now, activationComputer);
if (isValid == isValidOld) {
// No change in validity -> right to the zero set
// The change is not significant for assignment applicability. Recon will sort out the details.
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, minor change (add={}, delete={}, valid={}): {}",
new Object[]{isAdd, isDelete, isValid, SchemaDebugUtil.prettyPrint(assignmentCVal)});
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, true);
} else if (isValid) {
// Assignment became valid. We need to place it in plus set to initiate provisioning
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, assignment becomes valid (add={}, delete={}): {}",
new Object[]{isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal)});
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, true);
} else {
// Assignment became invalid. We need to place is in minus set to initiate deprovisioning
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, assignment becomes invalid (add={}, delete={}): {}",
new Object[]{isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal)});
}
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, true);
}
}
} else {
// No change in assignment
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing unchanged assignment {}", new Object[]{SchemaDebugUtil.prettyPrint(assignmentCVal)});
}
boolean isValid = LensUtil.isValid(assignmentType, now, activationComputer); // TODO unused: why? [med]
EvaluatedAssignment<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
continue;
}
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
}
}
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("evaluatedAssignmentTriple:\n{}", evaluatedAssignmentTriple.debugDump());
}
// PROCESSING POLICIES
// Checking for assignment exclusions. This means mostly role exclusions (SoD)
checkExclusions(context, evaluatedAssignmentTriple.getZeroSet(), evaluatedAssignmentTriple.getPlusSet());
checkExclusions(context, evaluatedAssignmentTriple.getPlusSet(), evaluatedAssignmentTriple.getPlusSet());
// PROCESSING FOCUS
Map<ItemPath,DeltaSetTriple<? extends ItemValueWithOrigin<? extends PrismValue>>> focusOutputTripleMap = new HashMap<>();
collectFocusTripleFromMappings(evaluatedAssignmentTriple.getPlusSet(), focusOutputTripleMap, PlusMinusZero.PLUS);
collectFocusTripleFromMappings(evaluatedAssignmentTriple.getMinusSet(), focusOutputTripleMap, PlusMinusZero.MINUS);
collectFocusTripleFromMappings(evaluatedAssignmentTriple.getZeroSet(), focusOutputTripleMap, PlusMinusZero.ZERO);
ObjectDeltaObject<F> focusOdo = focusContext.getObjectDeltaObject();
Collection<ItemDelta<? extends PrismValue>> focusDeltas = objectTemplateProcessor.computeItemDeltas(focusOutputTripleMap,
focusOdo, focusContext.getObjectDefinition(), "focus mappings in assignments of "+focusContext.getHumanReadableName());
LOGGER.trace("Computed focus deltas: {}", focusDeltas);
focusContext.applyProjectionWaveSecondaryDeltas(focusDeltas);
focusContext.recompute();
// PROCESSING PROJECTIONS
// Evaluate the constructions in assignements now. These were not evaluated in the first pass of AssignmentEvaluator
// because there may be interaction from focusMappings of some roles to outbound mappings of other roles.
// Now we have complete focus with all the focusMappings so we can evaluate the constructions
evaluateConstructions(context, evaluatedAssignmentTriple, task, result);
collectToConstructionMaps(context, evaluatedAssignmentTriple, constructionMapTriple, result);
if (LOGGER.isTraceEnabled()) {
// Dump the maps
LOGGER.trace("constructionMapTriple:\n{}", constructionMapTriple.debugDump());
}
// Now we are processing constructions from all the three sets once again. We will create projection contexts
// for them if not yet created. Now we will do the usual routing for converting the delta triples to deltas.
// I.e. zero means unchanged, plus means added, minus means deleted. That will be recorded in the SynchronizationPolicyDecision.
// We will also collect all the construction triples to projection context. These will be used later for computing
// actual attribute deltas (in consolidation processor).
Collection<ResourceShadowDiscriminator> allAccountTypes = constructionMapTriple.unionKeySets();
for (ResourceShadowDiscriminator rat : allAccountTypes) {
if (rat.getResourceOid() == null) {
throw new IllegalStateException("Resource OID null in ResourceAccountType during assignment processing");
}
if (rat.getIntent() == null) {
throw new IllegalStateException("Account type is null in ResourceAccountType during assignment processing");
}
boolean processOnlyExistingProjCxts = false;
if (ModelExecuteOptions.isLimitPropagation(context.getOptions())){
if (context.getTriggeredResourceOid() != null
&& !rat.getResourceOid().equals(context.getTriggeredResourceOid())) {
LOGGER.trace(
"Skipping processing construction for shadow identified by {} because of limitation to propagate changes only for resource {}",
rat, context.getTriggeredResourceOid());
continue;
}
if (SchemaConstants.CHANGE_CHANNEL_DISCOVERY.equals(QNameUtil.uriToQName(context.getChannel()))){
LOGGER.trace("Processing of shadow identified by {} will be skipped because of limitation for discovery channel."); // TODO is this message OK? [med]
processOnlyExistingProjCxts = true;
}
}
String desc = rat.toHumanReadableString();
// SITUATION: The projection is ASSIGNED
if (constructionMapTriple.getPlusMap().containsKey(rat)) {
ConstructionPack constructionPack = constructionMapTriple.getPlusMap().get(rat);
if (constructionPack.hasValidAssignment()) {
LensProjectionContext projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
projectionContext.setAssigned(true);
projectionContext.setLegalOld(false);
AssignmentPolicyEnforcementType assignmentPolicyEnforcement = projectionContext.getAssignmentPolicyEnforcementType();
if (assignmentPolicyEnforcement != AssignmentPolicyEnforcementType.NONE) {
LOGGER.trace("Projection {} legal: assigned (valid)", desc);
projectionContext.setLegal(true);
}
} else {
// Just ignore it, do not even create projection context
LOGGER.trace("Projection {} ignoring: assigned (invalid)", desc);
}
// SITUATION: The projection should exist (is valid), there is NO CHANGE in assignments
} else if (constructionMapTriple.getZeroMap().containsKey(rat) && constructionMapTriple.getZeroMap().get(rat).hasValidAssignment()) {
LensProjectionContext projectionContext = context.findProjectionContext(rat);
if (projectionContext == null) {
if (processOnlyExistingProjCxts){
continue;
}
// The projection should exist before the change but it does not
// This happens during reconciliation if there is an inconsistency.
// Pretend that the assignment was just added. That should do.
projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
}
LOGGER.trace("Projection {} legal: unchanged (valid)", desc);
projectionContext.setLegal(true);
projectionContext.setLegalOld(true);
projectionContext.setAssigned(true);
// SITUATION: The projection is both ASSIGNED and UNASSIGNED
} else if (constructionMapTriple.getPlusMap().containsKey(rat) && constructionMapTriple.getMinusMap().containsKey(rat)) {
// Account was removed and added in the same operation. This is the case if e.g. one role is
// removed and another is added and they include the same account.
// Keep original account state
ConstructionPack plusPack = constructionMapTriple.getPlusMap().get(rat);
ConstructionPack minusPack = constructionMapTriple.getMinusMap().get(rat);
if (plusPack.hasValidAssignment() && minusPack.hasValidAssignment()) {
LensProjectionContext projectionContext = context.findProjectionContext(rat);
if (projectionContext == null) {
if (processOnlyExistingProjCxts){
continue;
}
// The projection should exist before the change but it does not
// This happens during reconciliation if there is an inconsistency.
// Pretend that the assignment was just added. That should do.
projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
}
LOGGER.trace("Projection {} legal: both assigned and unassigned (valid)", desc);
projectionContext.setAssigned(true);
projectionContext.setLegal(true);
projectionContext.setLegalOld(true);
} else if (!plusPack.hasValidAssignment() && !minusPack.hasValidAssignment()) {
// Just ignore it, do not even create projection context
LOGGER.trace("Projection {} ignoring: both assigned and unassigned (invalid)", desc);
} else if (plusPack.hasValidAssignment() && !minusPack.hasValidAssignment()) {
// Assignment became valid. Same as if it was assigned.
LensProjectionContext projectionContext = context.findProjectionContext(rat);
if (projectionContext == null){
if (processOnlyExistingProjCxts){
continue;
}
projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
}
projectionContext.setAssigned(true);
projectionContext.setLegalOld(false);
AssignmentPolicyEnforcementType assignmentPolicyEnforcement = projectionContext.getAssignmentPolicyEnforcementType();
if (assignmentPolicyEnforcement != AssignmentPolicyEnforcementType.NONE) {
LOGGER.trace("Projection {} legal: both assigned and unassigned (invalid->valid)", desc);
projectionContext.setLegal(true);
}
} else if (!plusPack.hasValidAssignment() && minusPack.hasValidAssignment()) {
// Assignment became invalid. Same as if it was unassigned.
if (accountExists(context,rat)) {
LensProjectionContext projectionContext = context.findProjectionContext(rat);
if (projectionContext == null){
if (processOnlyExistingProjCxts){
continue;
}
projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
}
projectionContext.setAssigned(false);
projectionContext.setLegalOld(true);
AssignmentPolicyEnforcementType assignmentPolicyEnforcement = projectionContext.getAssignmentPolicyEnforcementType();
// TODO: check for MARK and LEGALIZE enforcement policies ....add delete laso for relative enforcemenet
if (assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.FULL
|| assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.RELATIVE) {
LOGGER.trace("Projection {} illegal: both assigned and unassigned (valid->invalid)", desc);
projectionContext.setLegal(false);
} else {
LOGGER.trace("Projection {} legal: both assigned and unassigned (valid->invalid), but allowed by policy ({})", desc, assignmentPolicyEnforcement);
projectionContext.setLegal(true);
}
} else {
LOGGER.trace("Projection {} nothing: both assigned and unassigned (valid->invalid) but not there", desc);
// We have to delete something that is not there. Nothing to do.
}
} else {
throw new IllegalStateException("Whoops!?!");
}
// SITUATION: The projection is UNASSIGNED
} else if (constructionMapTriple.getMinusMap().containsKey(rat)) {
if (accountExists(context,rat)) {
LensProjectionContext projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
projectionContext.setAssigned(false);
projectionContext.setLegalOld(true);
AssignmentPolicyEnforcementType assignmentPolicyEnforcement = projectionContext.getAssignmentPolicyEnforcementType();
// TODO: check for MARK and LEGALIZE enforcement policies ....add delete laso for relative enforcemenet
if (assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.FULL
|| assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.RELATIVE) {
LOGGER.trace("Projection {} illegal: unassigned", desc);
projectionContext.setLegal(false);
} else {
LOGGER.trace("Projection {} legal: unassigned, but allowed by policy ({})", desc, assignmentPolicyEnforcement);
projectionContext.setLegal(true);
}
} else {
LOGGER.trace("Projection {} nothing: unassigned but not there", desc);
// We have to delete something that is not there. Nothing to do.
}
// SITUATION: The projection should exist (invalid), there is NO CHANGE in assignments
} else if (constructionMapTriple.getZeroMap().containsKey(rat) && !constructionMapTriple.getZeroMap().get(rat).hasValidAssignment()) {
LensProjectionContext projectionContext = context.findProjectionContext(rat);
if (projectionContext == null) {
if (processOnlyExistingProjCxts){
continue;
}
// The projection should exist before the change but it does not
// This happens during reconciliation if there is an inconsistency.
// Pretend that the assignment was just added. That should do.
projectionContext = LensUtil.getOrCreateProjectionContext(context, rat);
}
LOGGER.trace("Projection {} illegal: unchanged (invalid)", desc);
projectionContext.setLegal(false);
projectionContext.setLegalOld(false);
projectionContext.setAssigned(false);
} else {
throw new IllegalStateException("Projection " + desc + " went looney");
}
PrismValueDeltaSetTriple<PrismPropertyValue<Construction>> accountDeltaSetTriple =
new PrismValueDeltaSetTriple<PrismPropertyValue<Construction>>(
getConstructions(constructionMapTriple.getZeroMap().get(rat), true),
getConstructions(constructionMapTriple.getPlusMap().get(rat), true),
getConstructions(constructionMapTriple.getMinusMap().get(rat), false));
LensProjectionContext accountContext = context.findProjectionContext(rat);
if (accountContext != null) {
// This can be null in a exotic case if we delete already deleted account
accountContext.setConstructionDeltaSetTriple(accountDeltaSetTriple);
if (isForceRecon(constructionMapTriple.getZeroMap().get(rat)) || isForceRecon(constructionMapTriple.getPlusMap().get(rat)) || isForceRecon(constructionMapTriple.getMinusMap().get(rat))) {
accountContext.setDoReconciliation(true);
}
}
}
removeIgnoredContexts(context);
finishLegalDecisions(context);
}
private <F extends ObjectType> ObjectType determineSource(LensFocusContext<F> focusContext)
throws SchemaException {
ObjectDelta delta = focusContext.getWaveDelta(focusContext.getLensContext().getExecutionWave());
if (delta != null && !delta.isEmpty()) {
return focusContext.getObjectNew().asObjectable();
}
if (focusContext.getObjectCurrent() != null) {
return focusContext.getObjectCurrent().asObjectable();
}
return focusContext.getObjectNew().asObjectable();
}
private <F extends FocusType> void collectToZero(DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple,
EvaluatedAssignment<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
evaluatedAssignmentTriple.addToZeroSet(evaluatedAssignment);
}
private <F extends FocusType> void collectToPlus(DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple,
EvaluatedAssignment<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
evaluatedAssignmentTriple.addToPlusSet(evaluatedAssignment);
}
private <F extends FocusType> void collectToMinus(DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple,
EvaluatedAssignment<F> evaluatedAssignment, boolean forceRecon) {
evaluatedAssignment.setForceRecon(forceRecon);
evaluatedAssignmentTriple.addToMinusSet(evaluatedAssignment);
}
private <F extends FocusType> void evaluateConstructions(LensContext<F> context,
DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
evaluateConstructions(context, evaluatedAssignmentTriple.getZeroSet(), task, result);
evaluateConstructions(context, evaluatedAssignmentTriple.getPlusSet(), task, result);
evaluateConstructions(context, evaluatedAssignmentTriple.getMinusSet(), task, result);
}
private <F extends FocusType> void evaluateConstructions(LensContext<F> context,
Collection<EvaluatedAssignment<F>> evaluatedAssignments, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
if (evaluatedAssignments == null) {
return;
}
ObjectDeltaObject<F> focusOdo = null;
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
focusOdo = focusContext.getObjectDeltaObject();
}
Iterator<EvaluatedAssignment<F>> iterator = evaluatedAssignments.iterator();
while (iterator.hasNext()) {
EvaluatedAssignment<F> evaluatedAssignment = iterator.next();
try {
evaluatedAssignment.evaluateConstructions(focusOdo, task, result);
} catch (ObjectNotFoundException ex){
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
iterator.remove();
if (!ModelExecuteOptions.isForce(context.getOptions())){
ModelUtils.recordFatalError(result, ex);
}
} catch (SchemaException ex){
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
ModelUtils.recordFatalError(result, ex);
String resourceOid = determineResource(evaluatedAssignment.getAssignmentType());
if (resourceOid == null) {
// This is a role assignment or something like that. Just throw the original exception for now.
throw ex;
}
ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid,
determineKind(evaluatedAssignment.getAssignmentType()), determineIntent(evaluatedAssignment.getAssignmentType()));
LensProjectionContext accCtx = context.findProjectionContext(rad);
if (accCtx != null) {
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
iterator.remove();
}
}
}
private <F extends FocusType> void collectToConstructionMaps(LensContext<F> context,
DeltaSetTriple<EvaluatedAssignment<F>> evaluatedAssignmentTriple,
DeltaMapTriple<ResourceShadowDiscriminator, ConstructionPack> constructionMapTriple,
OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
collectToConstructionMapFromEvaluatedAssignments(context, evaluatedAssignmentTriple.getZeroSet(), constructionMapTriple, PlusMinusZero.ZERO, result);
collectToConstructionMapFromEvaluatedAssignments(context, evaluatedAssignmentTriple.getPlusSet(), constructionMapTriple, PlusMinusZero.PLUS, result);
collectToConstructionMapFromEvaluatedAssignments(context, evaluatedAssignmentTriple.getMinusSet(), constructionMapTriple, PlusMinusZero.MINUS, result);
}
private <F extends FocusType> void collectToConstructionMapFromEvaluatedAssignments(LensContext<F> context,
Collection<EvaluatedAssignment<F>> evaluatedAssignments,
DeltaMapTriple<ResourceShadowDiscriminator, ConstructionPack> constructionMapTriple, PlusMinusZero mode,
OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
for (EvaluatedAssignment<F> evaluatedAssignment: evaluatedAssignments) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Collecting constructions from evaluated assignment:\n{}", evaluatedAssignment.debugDump());
}
DeltaSetTriple<Construction<F>> constructionTriple = evaluatedAssignment.getConstructions();
collectToConstructionMapFromEvaluatedConstructions(context, evaluatedAssignment, constructionTriple.getZeroSet(), constructionMapTriple, mode, PlusMinusZero.ZERO, result);
collectToConstructionMapFromEvaluatedConstructions(context, evaluatedAssignment, constructionTriple.getPlusSet(), constructionMapTriple, mode, PlusMinusZero.PLUS, result);
collectToConstructionMapFromEvaluatedConstructions(context, evaluatedAssignment, constructionTriple.getMinusSet(), constructionMapTriple, mode, PlusMinusZero.MINUS, result);
}
}
private <F extends FocusType> void collectToConstructionMapFromEvaluatedConstructions(LensContext<F> context,
EvaluatedAssignment<F> evaluatedAssignment,
Collection<Construction<F>> evaluatedConstructions,
DeltaMapTriple<ResourceShadowDiscriminator, ConstructionPack> constructionMapTriple,
PlusMinusZero mode1, PlusMinusZero mode2,
OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
for (Construction<F> construction : evaluatedConstructions) {
PlusMinusZero mode = PlusMinusZero.compute(mode1, mode2);
Map<ResourceShadowDiscriminator, ConstructionPack> constructionMap = constructionMapTriple.getMap(mode);
if (constructionMap == null) {
continue;
}
String resourceOid = construction.getResource(result).getOid();
String intent = construction.getIntent();
ShadowKindType kind = construction.getKind();
ResourceType resource = LensUtil.getResource(context, resourceOid, provisioningService, result);
intent = LensUtil.refineProjectionIntent(kind, intent, resource, prismContext);
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(resourceOid, kind, intent);
ConstructionPack constructionPack = null;
if (constructionMap.containsKey(rat)) {
constructionPack = constructionMap.get(rat);
} else {
constructionPack = new ConstructionPack();
constructionMap.put(rat, constructionPack);
}
constructionPack.add(new PrismPropertyValue<Construction>(construction));
if (evaluatedAssignment.isValid()) {
constructionPack.setHasValidAssignment(true);
}
if (evaluatedAssignment.isForceRecon()) {
constructionPack.setForceRecon(true);
}
}
}
private Collection<PrismContainerValue<AssignmentType>> mergeAssignments(
Collection<PrismContainerValue<AssignmentType>> currentAssignments,
Collection<PrismContainerValue<AssignmentType>> changedAssignments) {
Collection<PrismContainerValue<AssignmentType>> all = new ArrayList<>(currentAssignments.size() + changedAssignments.size());
all.addAll(currentAssignments);
for (PrismContainerValue<AssignmentType> changedAssignment: changedAssignments) {
boolean skip = false;
for (PrismContainerValue<AssignmentType> currentAssignment: currentAssignments) {
if (currentAssignment.match(changedAssignment)) {
skip = true;
break;
}
}
if (!skip) {
all.add(changedAssignment);
}
}
return all;
}
private <F extends FocusType> EvaluatedAssignment<F> evaluateAssignment(ItemDeltaItem<PrismContainerValue<AssignmentType>> assignmentIdi,
boolean evaluateOld, LensContext<F> context, ObjectType source, AssignmentEvaluator<F> assignmentEvaluator,
String assignmentPlacementDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
try{
// Evaluate assignment. This follows to the assignment targets, follows to the inducements,
// evaluates all the expressions, etc.
EvaluatedAssignment<F> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, evaluateOld, source, assignmentPlacementDesc, task, result);
context.rememberResources(evaluatedAssignment.getResources(result));
return evaluatedAssignment;
} catch (ObjectNotFoundException ex){
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(LensUtil.getAssignmentType(assignmentIdi, evaluateOld)));
}
if (ModelExecuteOptions.isForce(context.getOptions())){
return null;
}
ModelUtils.recordFatalError(result, ex);
return null;
} catch (SchemaException ex){
AssignmentType assignmentType = LensUtil.getAssignmentType(assignmentIdi, evaluateOld);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(assignmentType));
}
ModelUtils.recordFatalError(result, ex);
String resourceOid = determineResource(assignmentType);
if (resourceOid == null) {
// This is a role assignment or something like that. Just throw the original exception for now.
throw ex;
}
ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid,
determineKind(assignmentType), determineIntent(assignmentType));
LensProjectionContext accCtx = context.findProjectionContext(rad);
if (accCtx != null) {
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
return null;
}
}
/**
* Simply mark all projections as illegal - except those that are being unliked
*/
private <F extends FocusType> void processFocusDelete(LensContext<F> context, OperationResult result) {
for (LensProjectionContext projectionContext: context.getProjectionContexts()) {
if (projectionContext.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.UNLINK) {
// We do not want to affect unliked projections
continue;
}
projectionContext.setLegal(false);
projectionContext.setLegalOld(true);
}
}
private String determineResource(AssignmentType assignmentType) {
ConstructionType construction = assignmentType.getConstruction();
if (construction != null){
if (construction.getResource() != null){
return construction.getResource().getOid();
} else if (construction.getResourceRef() != null){
return construction.getResourceRef().getOid();
}
return null;
}
return null;
}
private String determineIntent(AssignmentType assignmentType) {
ConstructionType construction = assignmentType.getConstruction();
if (construction != null){
if (construction.getIntent() != null){
return construction.getIntent();
}
return "default";
}
throw new IllegalArgumentException("Construction not defined in the assigment.");
}
private ShadowKindType determineKind(AssignmentType assignmentType) {
ConstructionType construction = assignmentType.getConstruction();
if (construction != null){
if (construction.getKind() != null){
return construction.getKind();
}
return ShadowKindType.ACCOUNT;
}
throw new IllegalArgumentException("Construction not defined in the assigment.");
}
private Collection<PrismPropertyValue<Construction>> getConstructions(ConstructionPack accountConstructionPack, boolean validOnly) {
if (accountConstructionPack == null) {
return null;
}
if (validOnly && !accountConstructionPack.hasValidAssignment()) {
return null;
}
return accountConstructionPack.getConstructions();
}
private boolean isForceRecon(ConstructionPack accountConstructionPack) {
if (accountConstructionPack == null) {
return false;
}
return accountConstructionPack.isForceRecon();
}
/**
* Set 'legal' flag for the accounts that does not have it already
*/
private <F extends FocusType> void finishLegalDecisions(LensContext<F> context) throws PolicyViolationException, SchemaException {
for (LensProjectionContext projectionContext: context.getProjectionContexts()) {