-
Notifications
You must be signed in to change notification settings - Fork 188
/
ShadowManager.java
1249 lines (1084 loc) · 57.1 KB
/
ShadowManager.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-2016 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.provisioning.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.provisioning.util.ProvisioningUtil;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachingPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachingStategyType;
import org.jfree.util.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition;
import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.match.MatchingRule;
import com.evolveum.midpoint.prism.match.MatchingRuleRegistry;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrFilter;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.prism.query.Visitor;
import com.evolveum.midpoint.provisioning.api.ResourceOperationDescription;
import com.evolveum.midpoint.provisioning.ucf.api.Change;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SearchResultMetadata;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
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.FailedOperationTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationDirectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
/**
* Responsibilities:
* Communicate with the repo
* Store results in the repo shadows
* Clean up shadow inconsistencies in repo
*
* Limitations:
* Do NOT communicate with the resource
* means: do NOT do anything with the connector
*
* @author Katarina Valalikova
* @author Radovan Semancik
*
*/
@Component
public class ShadowManager {
@Autowired(required = true)
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;
@Autowired(required = true)
private Clock clock;
@Autowired(required = true)
private PrismContext prismContext;
@Autowired(required = true)
private TaskManager taskManager;
@Autowired(required = true)
private MatchingRuleRegistry matchingRuleRegistry;
private static final Trace LOGGER = TraceManager.getTrace(ShadowManager.class);
public void deleteConflictedShadowFromRepo(PrismObject<ShadowType> shadow, OperationResult parentResult){
try{
repositoryService.deleteObject(shadow.getCompileTimeClass(), shadow.getOid(), parentResult);
} catch (Exception ex){
throw new SystemException(ex.getMessage(), ex);
}
}
public ResourceOperationDescription createResourceFailureDescription(
PrismObject<ShadowType> conflictedShadow, ResourceType resource, OperationResult parentResult){
ResourceOperationDescription failureDesc = new ResourceOperationDescription();
failureDesc.setCurrentShadow(conflictedShadow);
ObjectDelta<ShadowType> objectDelta = null;
if (FailedOperationTypeType.ADD == conflictedShadow.asObjectable().getFailedOperationType()) {
objectDelta = ObjectDelta.createAddDelta(conflictedShadow);
}
failureDesc.setObjectDelta(objectDelta);
failureDesc.setResource(resource.asPrismObject());
failureDesc.setResult(parentResult);
failureDesc.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_DISCOVERY.getLocalPart());
return failureDesc;
}
/**
* Locates the appropriate Shadow in repository that corresponds to the
* provided resource object.
*
* DEAD flag is cleared - in memory as well as in repository.
*
* @param parentResult
*
* @return current shadow object that corresponds to provided
* resource object or null if the object does not exist
*/
public PrismObject<ShadowType> lookupShadowInRepository(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow,
OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
ObjectQuery query = createSearchShadowQuery(ctx, resourceShadow, prismContext,
parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching for shadow using filter:\n{}",
query.debugDump());
}
// PagingType paging = new PagingType();
// TODO: check for errors
List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
MiscSchemaUtil.reduceSearchResult(results);
LOGGER.trace("lookupShadow found {} objects", results.size());
if (results.size() == 0) {
return null;
}
if (results.size() > 1) {
for (PrismObject<ShadowType> result : results) {
LOGGER.trace("Search result:\n{}", result.debugDump());
}
LOGGER.error("More than one shadow found for " + resourceShadow);
// TODO: Better error handling later
throw new IllegalStateException("More than one shadow found for " + resourceShadow);
}
PrismObject<ShadowType> shadow = results.get(0);
checkConsistency(shadow);
if (Boolean.TRUE.equals(shadow.asObjectable().isDead())) {
LOGGER.debug("Repository shadow {} is marked as dead - resetting the flag", ObjectTypeUtil.toShortString(shadow));
shadow.asObjectable().setDead(false);
List<ItemDelta<?, ?>> deltas = DeltaBuilder.deltaFor(ShadowType.class, prismContext).item(ShadowType.F_DEAD).replace().asItemDeltas();
try {
repositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, parentResult);
} catch (ObjectAlreadyExistsException e) {
throw new SystemException("Unexpected exception when resetting 'dead' flag: " + e.getMessage(), e);
}
}
return shadow;
}
public PrismObject<ShadowType> lookupShadowInRepository(ProvisioningContext ctx, ResourceAttributeContainer identifierContainer,
OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
ObjectQuery query = createSearchShadowQuery(ctx, identifierContainer.getValue().getItems(), false, prismContext,
parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching for shadow using filter (repo):\n{}",
query.debugDump());
}
// PagingType paging = new PagingType();
// TODO: check for errors
List<PrismObject<ShadowType>> results;
results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
MiscSchemaUtil.reduceSearchResult(results);
LOGGER.trace("lookupShadow found {} objects", results.size());
if (results.size() == 0) {
return null;
}
if (results.size() > 1) {
LOGGER.error("More than one shadow found in repository for " + identifierContainer);
if (LOGGER.isDebugEnabled()) {
for (PrismObject<ShadowType> result : results) {
LOGGER.debug("Conflicting shadow (repo):\n{}", result.debugDump());
}
}
// TODO: Better error handling later
throw new IllegalStateException("More than one shadows found in repository for " + identifierContainer);
}
PrismObject<ShadowType> shadow = results.get(0);
checkConsistency(shadow);
return shadow;
}
public PrismObject<ShadowType> lookupConflictingShadowBySecondaryIdentifiers(
ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(resourceShadow);
List<PrismObject<ShadowType>> results = lookupShadowsBySecondaryIdentifiers(ctx, secondaryIdentifiers, parentResult);
if (results == null || results.size() == 0) {
return null;
}
List<PrismObject<ShadowType>> conflictingShadows = new ArrayList<PrismObject<ShadowType>>();
for (PrismObject<ShadowType> shadow: results){
ShadowType repoShadowType = shadow.asObjectable();
if (shadow != null) {
if (repoShadowType.getFailedOperationType() == null){
LOGGER.trace("Found shadow is ok, returning null");
continue;
}
if (repoShadowType.getFailedOperationType() != null && FailedOperationTypeType.ADD != repoShadowType.getFailedOperationType()){
continue;
}
conflictingShadows.add(shadow);
}
}
if (conflictingShadows.isEmpty()){
return null;
}
if (conflictingShadows.size() > 1) {
for (PrismObject<ShadowType> result : conflictingShadows) {
LOGGER.trace("Search result:\n{}", result.debugDump());
}
LOGGER.error("More than one shadow found for " + secondaryIdentifiers);
if (LOGGER.isDebugEnabled()) {
for (PrismObject<ShadowType> conflictingShadow: conflictingShadows) {
LOGGER.debug("Conflicting shadow:\n{}", conflictingShadow.debugDump());
}
}
// TODO: Better error handling later
throw new IllegalStateException("More than one shadows found for " + secondaryIdentifiers);
}
PrismObject<ShadowType> shadow = conflictingShadows.get(0);
checkConsistency(shadow);
return shadow;
}
public PrismObject<ShadowType> lookupShadowBySecondaryIdentifiers(
ProvisioningContext ctx, Collection<ResourceAttribute<?>> secondaryIdentifiers, OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
List<PrismObject<ShadowType>> shadows = lookupShadowsBySecondaryIdentifiers(ctx, secondaryIdentifiers, parentResult);
if (shadows == null || shadows.isEmpty()) {
return null;
}
if (shadows.size() > 1) {
LOGGER.error("Too many shadows ({}) for secondary identifiers {}: ", shadows.size(), secondaryIdentifiers,
shadows);
throw new ConfigurationException("Too many shadows ("+shadows.size()+") for secondary identifiers "+secondaryIdentifiers);
}
return shadows.get(0);
}
private List<PrismObject<ShadowType>> lookupShadowsBySecondaryIdentifiers(
ProvisioningContext ctx, Collection<ResourceAttribute<?>> secondaryIdentifiers, OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
if (secondaryIdentifiers.size() < 1){
LOGGER.trace("Shadow does not contain secondary identifier. Skipping lookup shadows according to name.");
return null;
}
List<EqualFilter> secondaryEquals = new ArrayList<>();
for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
// There may be identifiers that come from associations and they will have parent set to association/identifiers
// For the search to succeed we need all attribute to have "attributes" parent path.
secondaryIdentifier = ShadowUtil.fixAttributePath(secondaryIdentifier);
secondaryEquals.add(createAttributeEqualFilter(ctx, secondaryIdentifier));
}
ObjectFilter secondaryIdentifierFilter = null;
if (secondaryEquals.size() > 1){
secondaryIdentifierFilter = OrFilter.createOr((List) secondaryEquals);
} else {
secondaryIdentifierFilter = secondaryEquals.iterator().next();
}
AndFilter filter = AndFilter.createAnd(
RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class, ctx.getResource()), secondaryIdentifierFilter);
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching for shadow using filter on secondary identifier:\n{}",
query.debugDump());
}
// TODO: check for errors
List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
MiscSchemaUtil.reduceSearchResult(results);
LOGGER.trace("lookupShadow found {} objects", results.size());
if (LOGGER.isTraceEnabled() && results.size() == 1) {
LOGGER.trace("lookupShadow found\n{}", results.get(0).debugDump(1));
}
return results;
}
private void checkConsistency(PrismObject<ShadowType> shadow) {
ProvisioningUtil.checkShadowActivationConsistency(shadow);
}
private <T> EqualFilter<T> createAttributeEqualFilter(ProvisioningContext ctx,
ResourceAttribute<T> secondaryIdentifier) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
return EqualFilter.createEqual(secondaryIdentifier.getPath(), secondaryIdentifier.getDefinition(),
null, getNormalizedValue(secondaryIdentifier, ctx.getObjectClassDefinition()));
}
private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException {
RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName());
QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName();
MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName());
List<PrismPropertyValue<T>> normalized = new ArrayList<>();
for (PrismPropertyValue<T> origPValue : attr.getValues()){
if (matchingRule != null) {
T normalizedValue = matchingRule.normalize(origPValue.getValue());
PrismPropertyValue<T> normalizedPValue = origPValue.clone();
normalizedPValue.setValue(normalizedValue);
normalized.add(normalizedPValue);
} else {
normalized.add(origPValue);
}
}
return normalized;
}
public PrismObject<ShadowType> addRepositoryShadow(ProvisioningContext ctx,
PrismObject<ShadowType> resourceShadow, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ObjectAlreadyExistsException {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding new shadow from resource object: {}", resourceShadow.debugDump());
}
PrismObject<ShadowType> repoShadow = createRepositoryShadow(ctx, resourceShadow);
ConstraintsChecker.onShadowAddOperation(repoShadow.asObjectable());
String oid = repositoryService.addObject(repoShadow, null, parentResult);
repoShadow.setOid(oid);
LOGGER.debug("Added new shadow (from resource object): {}", repoShadow);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Added new shadow (from resource object):\n{}", repoShadow.debugDump());
}
return repoShadow;
}
// beware, may return null if an shadow that was to be marked as DEAD, was deleted in the meantime
public PrismObject<ShadowType> findOrAddShadowFromChange(ProvisioningContext ctx, Change<ShadowType> change,
OperationResult parentResult) throws SchemaException, CommunicationException,
ConfigurationException, SecurityViolationException, ObjectNotFoundException {
// Try to locate existing shadow in the repository
List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(ctx, change, parentResult);
if (accountList.size() > 1) {
String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
LOGGER.error(message);
parentResult.recordFatalError(message);
throw new IllegalArgumentException(message);
}
PrismObject<ShadowType> newShadow = null;
if (accountList.isEmpty()) {
// account was not found in the repository, create it now
if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
newShadow = createNewAccountFromChange(ctx, change, parentResult);
try {
ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
String oid = repositoryService.addObject(newShadow, null, parentResult);
newShadow.setOid(oid);
if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
change.getObjectDelta().setOid(oid);
}
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow)
+ " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
}
LOGGER.debug("Added new shadow (from change): {}", newShadow);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Added new shadow (from change):\n{}", newShadow.debugDump());
}
}
} else {
// Account was found in repository
newShadow = accountList.get(0);
if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
Collection<? extends ItemDelta> deadDeltas = PropertyDelta
.createModificationReplacePropertyCollection(ShadowType.F_DEAD,
newShadow.getDefinition(), true);
try {
ConstraintsChecker.onShadowModifyOperation(deadDeltas);
repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas,
parentResult);
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError(
"Can't add " + SchemaDebugUtil.prettyPrint(newShadow)
+ " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
} catch (ObjectNotFoundException e) {
parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow)
+ " was probably deleted from the repository in the meantime. Exception: "
+ e.getMessage(), e);
return null;
}
}
}
return newShadow;
}
public PrismObject<ShadowType> findOrAddShadowFromChangeGlobalContext(ProvisioningContext globalCtx, Change<ShadowType> change,
OperationResult parentResult) throws SchemaException, CommunicationException,
ConfigurationException, SecurityViolationException, ObjectNotFoundException {
// Try to locate existing shadow in the repository
List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(globalCtx, change, parentResult);
if (accountList.size() > 1) {
String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
LOGGER.error(message);
parentResult.recordFatalError(message);
throw new IllegalArgumentException(message);
}
PrismObject<ShadowType> newShadow = null;
if (accountList.isEmpty()) {
// account was not found in the repository, create it now
if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
newShadow = createNewAccountFromChange(globalCtx, change, parentResult);
try {
ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
String oid = repositoryService.addObject(newShadow, null, parentResult);
newShadow.setOid(oid);
if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
change.getObjectDelta().setOid(oid);
}
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow)
+ " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
}
LOGGER.debug("Added new shadow (from global change): {}", newShadow);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Added new shadow (from global change):\n{}", newShadow.debugDump());
}
}
} else {
// Account was found in repository
newShadow = accountList.get(0);
if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
Collection<? extends ItemDelta> deadDeltas = PropertyDelta
.createModificationReplacePropertyCollection(ShadowType.F_DEAD,
newShadow.getDefinition(), true);
try {
ConstraintsChecker.onShadowModifyOperation(deadDeltas);
repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas,
parentResult);
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError(
"Can't add " + SchemaDebugUtil.prettyPrint(newShadow)
+ " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
} catch (ObjectNotFoundException e) {
parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow)
+ " was probably deleted from the repository in the meantime. Exception: "
+ e.getMessage(), e);
return null;
}
}
}
return newShadow;
}
private PrismObject<ShadowType> createNewAccountFromChange(ProvisioningContext ctx, Change<ShadowType> change,
OperationResult parentResult) throws SchemaException,
CommunicationException, ConfigurationException,
SecurityViolationException, ObjectNotFoundException {
PrismObject<ShadowType> shadow = change.getCurrentShadow();
if (shadow == null){
//try to look in the delta, if there exists some account to be added
if (change.getObjectDelta() != null && change.getObjectDelta().isAdd()){
shadow = (PrismObject<ShadowType>) change.getObjectDelta().getObjectToAdd();
}
}
if (shadow == null){
throw new IllegalStateException("Could not create shadow from change description. Neither current shadow, nor delta containing shadow exits.");
}
try {
shadow = createRepositoryShadow(ctx, shadow);
} catch (SchemaException ex) {
parentResult.recordFatalError("Can't create shadow from identifiers: "
+ change.getIdentifiers());
throw new SchemaException("Can't create shadow from identifiers: "
+ change.getIdentifiers());
}
parentResult.recordSuccess();
return shadow;
}
private List<PrismObject<ShadowType>> searchShadowByIdenifiers(ProvisioningContext ctx, Change<ShadowType> change, OperationResult parentResult)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
Collection<ResourceAttribute<?>> identifiers = change.getIdentifiers();
ObjectQuery query = createSearchShadowQuery(ctx, identifiers, true, prismContext, parentResult);
List<PrismObject<ShadowType>> accountList = null;
try {
accountList = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
} catch (SchemaException ex) {
parentResult.recordFatalError(
"Failed to search shadow according to the identifiers: " + identifiers + ". Reason: "
+ ex.getMessage(), ex);
throw new SchemaException("Failed to search shadow according to the identifiers: "
+ identifiers + ". Reason: " + ex.getMessage(), ex);
}
MiscSchemaUtil.reduceSearchResult(accountList);
return accountList;
}
private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, Collection<ResourceAttribute<?>> identifiers, boolean primaryIdentifiersOnly,
PrismContext prismContext, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
List<ObjectFilter> conditions = new ArrayList<ObjectFilter>();
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
for (PrismProperty<?> identifier : identifiers) {
RefinedAttributeDefinition rAttrDef;
PrismPropertyValue<?> identifierValue = identifier.getValue();
if (objectClassDefinition == null) {
// If there is no specific object class definition then the identifier definition
// must be the same in all object classes and that means that we can use
// definition from any of them.
RefinedObjectClassDefinition anyDefinition = ctx.getRefinedSchema().getRefinedDefinitions().iterator().next();
rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName());
if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) {
continue;
}
} else {
if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) {
continue;
}
rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
}
String normalizedIdentifierValue = (String) getNormalizedAttributeValue(identifierValue, rAttrDef);
//new ItemPath(ShadowType.F_ATTRIBUTES)
PrismPropertyDefinition<String> def = (PrismPropertyDefinition<String>) identifier.getDefinition();
EqualFilter<String> filter = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, def.getName()),
def, new PrismPropertyValue<String>(normalizedIdentifierValue));
conditions.add(filter);
}
if (conditions.size() < 1) {
throw new SchemaException("Identifier not specified. Cannot create search query by identifier.");
}
RefFilter resourceRefFilter = RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class, ctx.getResource());
conditions.add(resourceRefFilter);
if (objectClassDefinition != null) {
EqualFilter<QName> objectClassFilter = EqualFilter.createEqual(ShadowType.F_OBJECT_CLASS, ShadowType.class,
prismContext, objectClassDefinition.getTypeName());
conditions.add(objectClassFilter);
}
ObjectFilter filter = null;
if (conditions.size() > 1) {
filter = AndFilter.createAnd(conditions);
} else {
filter = conditions.get(0);
}
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
return query;
}
private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow,
PrismContext prismContext, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException {
ResourceAttributeContainer attributesContainer = ShadowUtil
.getAttributesContainer(resourceShadow);
PrismProperty identifier = attributesContainer.getPrimaryIdentifier();
Collection<PrismPropertyValue<Object>> idValues = identifier.getValues();
// Only one value is supported for an identifier
if (idValues.size() > 1) {
// TODO: This should probably be switched to checked exception later
throw new IllegalArgumentException("More than one identifier value is not supported");
}
if (idValues.size() < 1) {
// TODO: This should probably be switched to checked exception later
throw new IllegalArgumentException("The identifier has no value");
}
// We have all the data, we can construct the filter now
ObjectFilter filter = null;
try {
// TODO TODO TODO TODO: set matching rule instead of null
PrismPropertyDefinition def = identifier.getDefinition();
filter = AndFilter.createAnd(
EqualFilter.createEqual(new ItemPath(ShadowType.F_OBJECT_CLASS), resourceShadow.findProperty(ShadowType.F_OBJECT_CLASS)),
RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class, ctx.getResource()),
EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, def.getName()), def, getNormalizedValue(identifier, ctx.getObjectClassDefinition())));
} catch (SchemaException e) {
throw new SchemaException("Schema error while creating search filter: " + e.getMessage(), e);
}
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
return query;
}
public SearchResultMetadata searchObjectsIterativeRepository(
ProvisioningContext ctx, ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options,
com.evolveum.midpoint.schema.ResultHandler<ShadowType> repoHandler, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
ObjectQuery repoQuery = query.clone();
processQueryMatchingRules(repoQuery, ctx.getObjectClassDefinition());
return repositoryService.searchObjectsIterative(ShadowType.class, repoQuery, repoHandler, options, false, parentResult); // TODO think about strictSequential flag
}
/**
* Visit the query and normalize values (or set matching rules) as needed
*/
private void processQueryMatchingRules(ObjectQuery repoQuery, final RefinedObjectClassDefinition objectClassDef) {
ObjectFilter filter = repoQuery.getFilter();
Visitor visitor = new Visitor() {
@Override
public void visit(ObjectFilter filter) {
try {
processQueryMatchingRuleFilter(filter, objectClassDef);
} catch (SchemaException e) {
throw new SystemException(e);
}
}
};
filter.accept(visitor);
}
private <T> void processQueryMatchingRuleFilter(ObjectFilter filter, RefinedObjectClassDefinition objectClassDef) throws SchemaException {
if (!(filter instanceof EqualFilter)) {
return;
}
EqualFilter<T> eqFilter = (EqualFilter)filter;
ItemPath parentPath = eqFilter.getParentPath();
if (parentPath == null || !parentPath.equivalent(SchemaConstants.PATH_ATTRIBUTES)) {
return;
}
QName attrName = eqFilter.getElementName();
RefinedAttributeDefinition rAttrDef = objectClassDef.findAttributeDefinition(attrName);
if (rAttrDef == null) {
throw new SchemaException("Unknown attribute "+attrName+" in filter "+filter);
}
QName matchingRuleQName = rAttrDef.getMatchingRuleQName();
if (matchingRuleQName == null) {
return;
}
MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName());
if (matchingRule == null) {
// TODO: warning?
return;
}
List<PrismValue> newValues = new ArrayList<PrismValue>();
for (PrismPropertyValue<T> ppval: eqFilter.getValues()) {
T normalizedRealValue = matchingRule.normalize(ppval.getValue());
PrismPropertyValue<T> newPPval = ppval.clone();
newPPval.setValue(normalizedRealValue);
newValues.add(newPPval);
}
eqFilter.getValues().clear();
eqFilter.getValues().addAll((Collection) newValues);
LOGGER.trace("Replacing values for attribute {} in search filter with normalized values because there is a matching rule, normalized values: {}",
attrName, newValues);
if (eqFilter.getMatchingRule() == null) {
eqFilter.setMatchingRule(matchingRuleQName);
LOGGER.trace("Setting matching rule to {}", matchingRuleQName);
}
}
/**
* Create a copy of a shadow that is suitable for repository storage.
*/
public PrismObject<ShadowType> createRepositoryShadow(ProvisioningContext ctx, PrismObject<ShadowType> shadow)
throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
PrismObject<ShadowType> repoShadow = shadow.clone();
ShadowType repoShadowType = repoShadow.asObjectable();
ResourceAttributeContainer repoAttributesContainer = ShadowUtil
.getAttributesContainer(repoShadow);
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
if (cachingStrategy == CachingStategyType.NONE) {
// Clean all repoShadow attributes and add only those that should be
// there
repoAttributesContainer.clear();
Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers();
for (PrismProperty<?> p : primaryIdentifiers) {
repoAttributesContainer.add(p.clone());
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = attributesContainer.getSecondaryIdentifiers();
for (PrismProperty<?> p : secondaryIdentifiers) {
repoAttributesContainer.add(p.clone());
}
// Also add all the attributes that act as association identifiers.
// We will need them when the shadow is deleted (to remove the shadow from entitlements).
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
for (RefinedAssociationDefinition associationDef: objectClassDefinition.getAssociations()) {
if (associationDef.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
QName valueAttributeName = associationDef.getResourceObjectAssociationType().getValueAttribute();
if (repoAttributesContainer.findAttribute(valueAttributeName) == null) {
ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName);
if (valueAttribute != null) {
repoAttributesContainer.add(valueAttribute.clone());
}
}
}
}
repoShadowType.setCachingMetadata(null);
ProvisioningUtil.cleanupShadowActivation(repoShadowType);
} else if (cachingStrategy == CachingStategyType.PASSIVE) {
// Do not need to clear anything. Just store all attributes and add metadata.
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
repoShadowType.setCachingMetadata(cachingMetadata);
} else {
throw new ConfigurationException("Unknown caching strategy "+cachingStrategy);
}
setKindIfNecessary(repoShadowType, ctx.getObjectClassDefinition());
// setIntentIfNecessary(repoShadowType, objectClassDefinition);
// We don't want to store credentials in the repo
repoShadowType.setCredentials(null);
// additional check if the shadow doesn't contain resource, if yes,
// convert to the resource reference.
if (repoShadowType.getResource() != null) {
repoShadowType.setResource(null);
repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
}
// if shadow does not contain resource or resource reference, create it
// now
if (repoShadowType.getResourceRef() == null) {
repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
}
if (repoShadowType.getName() == null) {
repoShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(shadow)));
}
if (repoShadowType.getObjectClass() == null) {
repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
}
if (repoShadowType.isProtectedObject() != null){
repoShadowType.setProtectedObject(null);
}
normalizeAttributes(repoShadow, ctx.getObjectClassDefinition());
return repoShadow;
}
@SuppressWarnings("unchecked")
public Collection<ItemDelta> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow,
Collection<? extends ItemDelta> aprioriDeltas, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException {
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, resourceShadow.getOid(), null, result);
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
Collection<ItemDelta> repoShadowChanges = new ArrayList<ItemDelta>();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (RefinedAttributeDefinition attrDef: objectClassDefinition.getAttributeDefinitions()) {
if (ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrDef.getName(), cachingStrategy)) {
ResourceAttribute<Object> resourceAttr = ShadowUtil.getAttribute(resourceShadow, attrDef.getName());
PrismProperty<Object> repoAttr = repoShadow.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
PropertyDelta attrDelta;
if (repoAttr == null && repoAttr == null) {
continue;
}
if (repoAttr == null) {
attrDelta = attrDef.createEmptyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()));
attrDelta.setValuesToReplace(PrismValue.cloneCollection(resourceAttr.getValues()));
} else {
attrDelta = repoAttr.diff(resourceAttr);
// LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", repoAttr==null?null:repoAttr.debugDump(1), resourceAttr==null?null:resourceAttr.debugDump(1), attrDelta==null?null:attrDelta.debugDump(1));
}
if (attrDelta != null && !attrDelta.isEmpty()) {
normalizeDelta(attrDelta, attrDef);
repoShadowChanges.add(attrDelta);
}
}
}
// TODO: reflect activation updates on cached shadow
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Updating repo shadow {}:\n{}", resourceShadow.getOid(), DebugUtil.debugDump(repoShadowChanges));
}
try {
repositoryService.modifyObject(ShadowType.class, resourceShadow.getOid(), repoShadowChanges, result);
} catch (ObjectAlreadyExistsException e) {
// We are not renaming the object here. This should not happen.
throw new SystemException(e.getMessage(), e);
}
return repoShadowChanges;
}
/**
* Updates repository shadow based on shadow from resource. Handles rename cases,
* change of auxiliary object classes, etc.
* @returns repository shadow as it should look like after the update
*/
@SuppressWarnings("unchecked")
public PrismObject<ShadowType> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> currentResourceShadow,
PrismObject<ShadowType> oldRepoShadow, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, CommunicationException {
RefinedObjectClassDefinition ocDef = ctx.computeCompositeObjectClassDefinition(currentResourceShadow);
ObjectDelta<ShadowType> shadowDelta = oldRepoShadow.createModifyDelta();
PrismContainer<Containerable> currentResourceAttributesContainer = currentResourceShadow.findContainer(ShadowType.F_ATTRIBUTES);
PrismContainer<Containerable> oldRepoAttributesContainer = oldRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (Item<?, ?> currentResourceItem: currentResourceAttributesContainer.getValue().getItems()) {
if (currentResourceItem instanceof PrismProperty<?>) {
PrismProperty<?> currentResourceAttrProperty = (PrismProperty<?>)currentResourceItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(currentResourceAttrProperty.getElementName());
if (ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy)) {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributesContainer.findProperty(currentResourceAttrProperty.getElementName());
if (oldRepoAttributeProperty == null ) {
PropertyDelta<?> attrAddDelta = currentResourceAttrProperty.createDelta();
for (PrismPropertyValue pval: currentResourceAttrProperty.getValues()) {
Object normalizedRealValue;
if (matchingRule == null) {
normalizedRealValue = pval.getValue();
} else {
normalizedRealValue = matchingRule.normalize(pval.getValue());
}
attrAddDelta.addValueToAdd(new PrismPropertyValue(normalizedRealValue));
LOGGER.trace("CURRENT ATTR:\n{}\nATTR DELTA:\n{}", currentResourceAttrProperty.debugDump(1), attrAddDelta.debugDump(1));
}
shadowDelta.addModification(attrAddDelta);
} else {
if (attrDef.isSingleValue()) {
Object currentResourceRealValue = currentResourceAttrProperty.getRealValue();
Object currentResourceNormalizedRealValue;
if (matchingRule == null) {
currentResourceNormalizedRealValue = currentResourceRealValue;
} else {
currentResourceNormalizedRealValue = matchingRule.normalize(currentResourceRealValue);
}
if (!currentResourceNormalizedRealValue.equals(oldRepoAttributeProperty.getRealValue())) {
LOGGER.trace("CURRENT ATTR:\n{}\ncurrentResourceNormalizedRealValue: {}", currentResourceAttrProperty.debugDump(1), currentResourceNormalizedRealValue);
shadowDelta.addModificationReplaceProperty(currentResourceAttrProperty.getPath(), currentResourceNormalizedRealValue);
}
} else {
PrismProperty<Object> normalizedCurrentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrProperty.clone();
if (matchingRule != null) {
for (PrismPropertyValue pval: normalizedCurrentResourceAttrProperty.getValues()) {
Object normalizedRealValue = matchingRule.normalize(pval.getValue());
pval.setValue(normalizedRealValue);
}
}
PropertyDelta<Object> attrDiff = oldRepoAttributeProperty.diff(normalizedCurrentResourceAttrProperty);
LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}",
oldRepoAttributeProperty==null?null:oldRepoAttributeProperty.debugDump(1),
normalizedCurrentResourceAttrProperty==null?null:normalizedCurrentResourceAttrProperty.debugDump(1),
attrDiff==null?null:attrDiff.debugDump(1));
if (attrDiff != null && !attrDiff.isEmpty()) {
attrDiff.setParentPath(new ItemPath(ShadowType.F_ATTRIBUTES));
shadowDelta.addModification(attrDiff);
}
}
}
}
}
}
for (Item<?, ?> oldRepoItem: oldRepoAttributesContainer.getValue().getItems()) {
if (oldRepoItem instanceof PrismProperty<?>) {
PrismProperty<?> oldRepoAttrProperty = (PrismProperty<?>)oldRepoItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
PrismProperty<Object> currentAttribute = currentResourceAttributesContainer.findProperty(oldRepoAttrProperty.getElementName());
if (attrDef == null || !ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy) ||
currentAttribute == null) {
// No definition for this property it should not be there or no current value: remove it from the shadow
PropertyDelta<?> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete((Collection)PrismPropertyValue.cloneCollection(oldRepoAttrProperty.getValues()));
shadowDelta.addModification(oldRepoAttrPropDelta);
}
}
}
PolyString currentShadowName = ShadowUtil.determineShadowName(currentResourceShadow);
PolyString oldRepoShadowName = oldRepoShadow.getName();
if (!currentShadowName.equalsOriginalValue(oldRepoShadowName)) {
PropertyDelta<?> shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME,
oldRepoShadow.getDefinition(),currentShadowName);