-
Notifications
You must be signed in to change notification settings - Fork 188
/
AbstractAdLdapMultidomainTest.java
2405 lines (1868 loc) · 90.7 KB
/
AbstractAdLdapMultidomainTest.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) 2015-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.testing.conntest.ad.multidomain;
import static com.evolveum.midpoint.schema.util.task.ActivityStateUtil.getRootSyncTokenRealValueRequired;
import static com.evolveum.midpoint.test.util.MidPointTestConstants.PATH_CN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;
import static com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_CREDENTIALS_PASSWORD_VALUE;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;
import com.evolveum.midpoint.testing.conntest.AbstractLdapTest;
import com.evolveum.midpoint.testing.conntest.ad.AbstractAdLdapTest;
import com.evolveum.midpoint.testing.conntest.ad.AdTestMixin;
import org.apache.commons.lang3.StringUtils;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.testng.AssertJUnit;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrderDirection;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SearchResultMetadata;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalCounters;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.testing.conntest.UserLdapConnectionConfig;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
/**
* Active Directory multidomain test abstract superclass.
* This tests configuration of Active Directory forrest with two domains: parent domain and child domain.
* Whole forrest is configured as a single resource.
* <p>
* This is a "live and conservative" conntest.
* Which means that it runs on very realy and very live Active Directory forrest.
* The AD servers are NOT cleaned and reset after/before test.
* The test is carefully built not to destroy the environment.
* The test cleans up all the objects that it creates.
* In case that the test fails, there is a special cleanup procedure in test000Sanity.
*
* @author Radovan Semancik
*/
@Listeners({ com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor.class })
public abstract class AbstractAdLdapMultidomainTest extends AbstractAdLdapTest
implements AdTestMixin {
protected static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "ad-ldap-multidomain");
protected static final File ROLE_PIRATES_FILE = new File(TEST_DIR, "role-pirate.xml");
protected static final String ROLE_PIRATES_OID = "5dd034e8-41d2-11e5-a123-001e8c717e5b";
protected static final File ROLE_SUBMISSIVE_FILE = new File(TEST_DIR, "role-submissive.xml");
protected static final String ROLE_SUBMISSIVE_OID = "0c0c81b2-d0a1-11e5-b51e-0309a826745e";
protected static final File ROLE_META_ORG_FILE = new File(TEST_DIR, "role-meta-org.xml");
protected static final String ROLE_META_ORG_OID = "f2ad0ace-45d7-11e5-af54-001e8c717e5b";
protected static final File ROLE_META_ORG_GROUP_FILE = new File(TEST_DIR, "role-meta-org-group.xml");
protected static final String ROLE_META_ORG_GROUP_OID = "c5d3294a-0d8e-11e7-bd9d-ff848c2e7e3f";
protected static final String ACCOUNT_JACK_SAM_ACCOUNT_NAME = "jack";
protected static final String ACCOUNT_JACK_FULL_NAME = "Jack Sparrow";
protected static final String ACCOUNT_JACK_PASSWORD = "qwe.123";
protected static final String ACCOUNT_HT_UID = "ht";
protected static final String ACCOUNT_HT_CN = "Herman Toothrot";
protected static final String ACCOUNT_HT_GIVENNAME = "Herman";
protected static final String ACCOUNT_HT_SN = "Toothrot";
protected static final String ACCOUNT_HT_SN_MODIFIED = "Torquemeda Marley";
protected static final String ACCOUNT_HTM_UID = "htm";
protected static final String ACCOUNT_HTM_CN = "Horatio Torquemada Marley";
protected static final String USER_CPTBARBOSSA_FULL_NAME = "Captain Hector Barbossa";
private static final String GROUP_PIRATES_NAME = "pirates";
private static final String GROUP_MELEE_ISLAND_NAME = "Mêlée Island";
private static final String GROUP_MELEE_ISLAND_ALT_NAME = "Alternative Mêlée Island";
private static final String GROUP_MELEE_ISLAND_PIRATES_NAME = "Mêlée Island Pirates";
private static final String GROUP_MELEE_ISLAND_PIRATES_DESCRIPTION = "swashbuckle and loot";
private static final String ASSOCIATION_GROUP_NAME = "group";
private static final String NS_EXTENSION = "http://whatever.com/my";
private static final QName EXTENSION_SHOW_IN_ADVANCED_VIEW_ONLY_QNAME = new QName(NS_EXTENSION, "showInAdvancedViewOnly");
protected static final File USER_SUBMAN_FILE = new File(TEST_DIR, "user-subman.xml");
private static final String USER_SUBMAN_OID = "910ac45a-8bd6-11e6-9122-ef88d95095f0";
private static final String USER_SUBMAN_USERNAME = "subman";
private static final String USER_SUBMAN_GIVEN_NAME = "Sub";
private static final String USER_SUBMAN_FAMILY_NAME = "Man";
private static final String USER_SUBMAN_FULL_NAME = "Sub Man";
private static final String USER_SUBMAN_PASSWORD = "sub.123";
private static final String USER_SUBDOG_USERNAME = "subdog";
private static final String USER_SUBDOG_GIVEN_NAME = "Sub";
private static final String USER_SUBDOG_FAMILY_NAME = "Dog";
private static final String USER_SUBDOG_FULL_NAME = "Sub Dog";
protected static final File USER_SUBMARINE_FILE = new File(TEST_DIR, "user-submarine.xml");
private static final String USER_SUBMARINE_OID = "c4377f86-8be9-11e6-8ef5-c3c56ff64b09";
private static final String USER_SUBMARINE_USERNAME = "submarine";
private static final String USER_SUBMARINE_GIVEN_NAME = "Sub";
private static final String USER_SUBMARINE_FAMILY_NAME = "Marine";
private static final String USER_SUBMARINE_FULL_NAME = "Sub Marine";
private static final String INTENT_GROUP = "group";
private static final String INTENT_OU_TOP = "ou-top";
private static final String USER_EMPTYHEAD_NAME = "emptyhead";
private static final String PROXY_ADDRES_ADDR_UPCASE = "smpt:ADDR";
private static final String PROXY_ADDRES_ADDR_LOWCASE = "smpt:addr";
private static final String USER_GUYBRUSH_PASSWORD_123 = "wanna.be.a.123";
private static final String USER_GUYBRUSH_PASSWORD_333 = "wanna.be.a.333";
private static final String VERY_STRANGE_PARAMETER = "This iš a véry stándže p§räméteř!";
private static final String SHADOW_GHOST_OID = "0c244f74-0169-11eb-a13f-77a028a1ab97";
// protected static final File SHADOW_GHOST_FILE = new File(TEST_DIR, "shadow-ghost.xml");
private boolean allowDuplicateSearchResults = false;
protected String jackAccountOid;
protected String groupPiratesOid;
protected long jackLockoutTimestamp;
protected String accountBarbossaOid;
protected String orgMeleeIslandOid;
protected String groupMeleeIslandOid;
protected String ouMeleeIslandOid;
protected String roleMeleeIslandPiratesOid;
protected String groupMeleeIslandPiratesOid;
private String accountSubmanOid;
@Override
protected String getResourceOid() {
return "eced6d24-73e3-11e5-8457-93eff15a6b85";
}
@Override
protected File getBaseDir() {
return TEST_DIR;
}
@Override
protected String getSyncTaskOid() {
return "0f93d8d4-5fb4-11ea-8571-a3f090bf921f";
}
@Override
protected String getLdapBindPassword() {
return "qwe.123";
}
protected abstract String getLdapSubServerHost();
protected abstract String getLdapSubSuffix();
protected String getPeopleLdapSubSuffix() {
return "CN=Users," + getLdapSubSuffix();
}
protected String getLdapSubBindDn() {
return "CN=midpoint," + getPeopleLdapSubSuffix();
}
private QName getAssociationGroupQName() {
return new QName(MidPointConstants.NS_RI, ASSOCIATION_GROUP_NAME);
}
@Override
protected boolean allowDuplicateSearchResults() {
return allowDuplicateSearchResults;
}
protected String getOrgsLdapSuffix() {
return "OU=Org," + getLdapSuffix();
}
protected abstract String getAccountJackSid();
protected abstract File getShadowGhostFile();
private UserLdapConnectionConfig getSubLdapConnectionConfig() {
UserLdapConnectionConfig config = new UserLdapConnectionConfig();
config.setLdapHost(getLdapSubServerHost());
config.setLdapPort(getLdapServerPort());
config.setBindDn(getLdapSubBindDn());
config.setBindPassword(getLdapBindPassword());
config.setBaseContext(getLdapSubSuffix());
return config;
}
protected abstract File getReconciliationTaskFile();
protected abstract String getReconciliationTaskOid();
protected String getLdapConnectorClassName() {
return AD_CONNECTOR_TYPE;
}
protected abstract int getNumberOfAllAccounts();
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
binaryAttributeDetector.addBinaryAttribute(ATTRIBUTE_OBJECT_GUID_NAME);
binaryAttributeDetector.addBinaryAttribute(ATTRIBUTE_UNICODE_PWD_NAME);
// Users
repoAddObjectFromFile(USER_BARBOSSA_FILE, initResult);
repoAddObjectFromFile(USER_GUYBRUSH_FILE, initResult);
repoAddObjectFromFile(USER_SUBMAN_FILE, initResult);
repoAddObjectFromFile(USER_SUBMARINE_FILE, initResult);
// Roles
repoAddObjectFromFile(ROLE_END_USER_FILE, initResult);
repoAddObjectFromFile(ROLE_PIRATES_FILE, initResult);
repoAddObjectFromFile(ROLE_SUBMISSIVE_FILE, initResult);
repoAddObjectFromFile(ROLE_META_ORG_FILE, initResult);
repoAddObjectFromFile(ROLE_META_ORG_GROUP_FILE, initResult);
assignRole(USER_BARBOSSA_OID, ROLE_END_USER_OID);
}
@Test
public void test000Sanity() throws Exception {
Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = (String) p.get(key);
System.out.println("PROP: " + key + ": " + value);
}
assertLdapPassword(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME, ACCOUNT_JACK_PASSWORD);
cleanupDelete(toAccountDn(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME));
cleanupDelete(toAccountDn(USER_CPTBARBOSSA_USERNAME, USER_CPTBARBOSSA_FULL_NAME));
cleanupDelete(toAccountDn(USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME));
cleanupDelete(getSubLdapConnectionConfig(), toAccountSubDn(USER_SUBMAN_USERNAME, USER_SUBMAN_FULL_NAME));
cleanupDelete(getSubLdapConnectionConfig(), toAccountSubDn(USER_SUBDOG_USERNAME, USER_SUBDOG_FULL_NAME));
cleanupDelete(getSubLdapConnectionConfig(), toAccountSubDn(USER_SUBMARINE_USERNAME, USER_SUBMARINE_FULL_NAME));
cleanupDelete(toAccountDn(ACCOUNT_HT_UID, ACCOUNT_HT_CN));
cleanupDelete(toAccountDn(ACCOUNT_HTM_UID, ACCOUNT_HTM_CN));
cleanupDelete(toGroupDn(GROUP_MELEE_ISLAND_NAME));
cleanupDelete(toGroupDn(GROUP_MELEE_ISLAND_ALT_NAME));
cleanupDelete(toOrgGroupDn(GROUP_MELEE_ISLAND_PIRATES_NAME, GROUP_MELEE_ISLAND_NAME));
cleanupDelete(toOrgGroupDn(GROUP_MELEE_ISLAND_PIRATES_NAME, GROUP_MELEE_ISLAND_ALT_NAME));
cleanupDelete(toOrgDn(GROUP_MELEE_ISLAND_NAME));
cleanupDelete("ou=underMelee," + toOrgDn(GROUP_MELEE_ISLAND_ALT_NAME));
cleanupDelete(toOrgDn(GROUP_MELEE_ISLAND_ALT_NAME));
}
@Test
@Override
public void test020Schema() throws Exception {
// IntegrationTestTools.displayXml("Resource XML", resource);
accountDefinition = assertAdResourceSchema(resource, getAccountObjectClass());
assertAdRefinedSchema(resource, getAccountObjectClass());
if (hasExchange()) {
assertExchangeSchema(resource, getAccountObjectClass());
}
ResourceSchema resourceSchema = ResourceSchemaFactory.getRawSchema(resource);
int expectedDefinitions = 4;
if (hasExchange()) {
expectedDefinitions = 5;
}
assertEquals("Unexpected number of schema definitions (limited by generation constraints)", expectedDefinitions, resourceSchema.getDefinitions().size());
// Not checking the number of connector instances: the previous operation might have been "test partial configuration"
// that leaves no cached connector instances.
}
@Test
public void test100SearchJackBySamAccountName() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = createSamAccountNameQuery(ACCOUNT_JACK_SAM_ACCOUNT_NAME);
display("SamAccountName query:\n" + query.debugDump());
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
// WHEN
when();
SearchResultList<PrismObject<ShadowType>> shadows =
modelService.searchObjects(ShadowType.class, query, null, task, result);
// THEN
then();
assertSuccess(result);
assertEquals("Unexpected search result: " + shadows, 1, shadows.size());
PrismObject<ShadowType> shadow = shadows.get(0);
display("Shadow", shadow);
assertAccountShadow(shadow, toAccountDn(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME));
assertSid(shadow, getAccountJackSid());
assertObjectCategory(shadow, getObjectCategoryPerson());
jackAccountOid = shadow.getOid();
// assertConnectorOperationIncrement(2);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* MID-3730
*/
@Test
public void test101SearchJackByDn() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
String jackDn = toAccountDn(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME);
ObjectQuery query = createAccountShadowQueryByAttribute("dn", jackDn, resource);
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
// WHEN
when();
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);
// THEN
then();
assertSuccess(result);
assertEquals("Unexpected search result: " + shadows, 1, shadows.size());
PrismObject<ShadowType> shadow = shadows.get(0);
display("Shadow", shadow);
assertAccountShadow(shadow, jackDn);
assertSid(shadow, getAccountJackSid());
assertObjectCategory(shadow, getObjectCategoryPerson());
// assertConnectorOperationIncrement(2);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* Search for non-existent DN should return no results. It should NOT
* throw an error.
* <p>
* MID-3730
*/
@Test
public void test102SearchNotExistByDn() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
String dn = toAccountDn("idonoexist", "I am a Fiction");
ObjectQuery query = createAccountShadowQueryByAttribute("dn", dn, resource);
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
// WHEN
when();
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);
// THEN
then();
assertSuccess(result);
assertEquals("Unexpected search result: " + shadows, 0, shadows.size());
// assertConnectorOperationIncrement(2);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
assertLdapConnectorReasonableInstances();
}
@Test
public void test105SearchPiratesByCn() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getGroupObjectClass());
ObjectQueryUtil.filterAnd(query.getFilter(), createAttributeFilter("cn", GROUP_PIRATES_NAME), prismContext);
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
// WHEN
when();
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);
// THEN
then();
assertSuccess(result);
assertEquals("Unexpected search result: " + shadows, 1, shadows.size());
PrismObject<ShadowType> shadow = shadows.get(0);
display("Shadow", shadow);
groupPiratesOid = shadow.getOid();
assertObjectCategory(shadow, getObjectCategoryGroup());
// assertConnectorOperationIncrement(1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
@Test
public void test110GetJack() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
long startOfTestMsTimestamp = getWin32Filetime(System.currentTimeMillis());
// WHEN
when();
PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, jackAccountOid, null, task, result);
// THEN
then();
assertSuccess(result);
display("Shadow", shadow);
assertAccountShadow(shadow, toAccountDn(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME));
jackAccountOid = shadow.getOid();
IntegrationTestTools.assertAssociation(shadow, getAssociationGroupQName(), groupPiratesOid);
assertAttribute(shadow, "dn", "CN=Jack Sparrow," + getPeopleLdapSuffix());
assertAttribute(shadow, "cn", ACCOUNT_JACK_FULL_NAME);
assertAttribute(shadow, "sn", "Sparrow");
assertAttribute(shadow, "description", "The best pirate the world has ever seen");
assertAttribute(shadow, "sAMAccountName", ACCOUNT_JACK_SAM_ACCOUNT_NAME);
assertObjectCategory(shadow, getObjectCategoryPerson());
List<Long> lastLogonValues = ShadowUtil.getAttributeValues(shadow, new QName(getResourceNamespace(), "lastLogon"));
assertEquals("Wrong number of lastLong values: " + lastLogonValues, 1, lastLogonValues.size());
if (lastLogonValues.get(0) > startOfTestMsTimestamp) {
fail("Wrong lastLogon, expected it to be less than " + startOfTestMsTimestamp + ", but was " + lastLogonValues.get(0));
}
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
assertLdapConnectorReasonableInstances();
}
/**
* No paging. It should return all accounts.
*/
@Test
public void test150SearchAllAccounts() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
// WHEN
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query,
getNumberOfAllAccounts(), task, result);
if (isVagueTest()) {
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
} else {
// This seems to vary quite wildly from system to system. Maybe TODO investigate the reasons later?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 8,10);
}
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* This is in one block.
*/
@Test
public void test152SearchFirst2Accounts() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setMaxSize(2);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
@Test
public void test154SearchFirst5Accounts() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setMaxSize(5);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 5, task, result);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
@Test
public void test162SearchFirst2AccountsOffset0() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndKindIntent(getResourceOid(), ShadowKindType.ACCOUNT, "default");
ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setOffset(0);
paging.setMaxSize(2);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);
// increment = 2 because there are two searches:
// 1. one for baseContext (as defined for account/default)
// 2. one for objects
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* There is offset, so VLV should be used.
* No explicit sorting.
*/
@Test
public void test172Search2AccountsOffset1() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
ObjectPaging paging = prismContext.queryFactory().createPaging(1, 2);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* There is offset, so VLV should be used.
* No explicit sorting.
*/
@Test
public void test174SearchFirst5AccountsOffset2() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
ObjectPaging paging = prismContext.queryFactory().createPaging(2, 5);
query.setPaging(paging);
allowDuplicateSearchResults = true;
// WHEN
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 5, task, result);
// THEN
allowDuplicateSearchResults = false;
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = searchResultList.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
/**
* There is offset, so VLV should be used.
* Explicit sorting.
*/
@Test
public void test182Search2AccountsOffset1SortCn() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());
ObjectPaging paging = prismContext.queryFactory().createPaging(1, 2);
paging.setOrdering(PATH_CN, OrderDirection.ASCENDING);
query.setPaging(paging);
SearchResultList<PrismObject<ShadowType>> shadows = doSearch(query, 2, task, result);
assertAccountShadow(shadows.get(0), getExpected182FirstShadow());
// assertAccountShadow(shadows.get(0), "CN=Adolf Supperior,CN=Users,DC=ad,DC=evolveum,DC=com");
// assertAccountShadow(shadows.get(1), "CN=DiscoverySearchMailbox {D919BA05-46A6-415f-80AD-7E09334BB852},CN=Users,DC=ad,DC=evolveum,DC=com");
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}
assertLdapConnectorReasonableInstances();
}
protected String getExpected182FirstShadow() {
return "CN=Admin," + getPeopleLdapSuffix();
}
/**
* Try to get account that does not exist.
* The goal is to check that our error handling is at least a bit sane.
* We need to create a fake shadow for this, otherwise midPoint won't try the AD operation at all.
*/
@Test
public void test190GetGhost() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
importObjectFromFile(getShadowGhostFile());
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
long startOfTestMsTimestamp = getWin32Filetime(System.currentTimeMillis());
// WHEN
when();
modelService.getObject(ShadowType.class, SHADOW_GHOST_OID, null, task, result);
// THEN
then();
assertHandledError(result);
assertRepoShadow(SHADOW_GHOST_OID)
.assertDead();
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
assertLdapConnectorReasonableInstances();
}
@Test
public void test200AssignAccountBarbossa() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
long tsStart = System.currentTimeMillis();
// WHEN
when();
assignAccountToUser(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
// THEN
then();
assertSuccess(result);
long tsEnd = System.currentTimeMillis();
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "title", null);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
PrismObject<ShadowType> shadow = getShadowModel(shadowOid);
display("Shadow (model)", shadow);
accountBarbossaOid = shadow.getOid();
Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);
assertEquals("Wrong ICFS UID",
formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
accountBarbossaIcfUid);
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
assertAttribute(entry, ATTRIBUTE_OBJECT_CATEGORY_NAME, getObjectCategoryPerson());
// MID-4624
ResourceAttribute<XMLGregorianCalendar> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimeStamp"));
assertNotNull("No createTimestamp in " + shadow, createTimestampAttribute);
XMLGregorianCalendar createTimestamp = createTimestampAttribute.getRealValue();
long createTimestampMillis = XmlTypeConverter.toMillis(createTimestamp);
// LDAP server may be on a different host. Allow for some clock offset.
TestUtil.assertBetween("Wrong createTimestamp in " + shadow, roundTsDown(tsStart) - 120000, roundTsUp(tsEnd) + 120000, createTimestampMillis);
assertObjectCategory(shadow, getObjectCategoryPerson());
// assertLdapConnectorInstances(2);
}
@Test
public void test210ModifyAccountBarbossaTitle() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, ATTRIBUTE_TITLE_NAME);
ResourceAttributeDefinition<?> attrDef = accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
delta.addModification(attrDelta);
// WHEN
when();
executeChanges(delta, null, task, result);
// THEN
then();
assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, ATTRIBUTE_TITLE_NAME, "Captain");
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
assertAttribute(entry, ATTRIBUTE_OBJECT_CATEGORY_NAME, getObjectCategoryPerson());
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
// assertLdapConnectorReasonableInstances();
}
@Test
public void test212ModifyAccountBarbossaShowInAdvancedViewOnlyTrue() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, "showInAdvancedViewOnly");
ResourceAttributeDefinition<?> attrDef = accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<Boolean> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, Boolean.TRUE);
delta.addModification(attrDelta);
// WHEN
when();
executeChanges(delta, null, task, result);
// THEN
then();
assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "showInAdvancedViewOnly", "TRUE");
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
assertAttribute(entry, ATTRIBUTE_OBJECT_CATEGORY_NAME, getObjectCategoryPerson());
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
assertLdapConnectorReasonableInstances();
}
/**
* Modify USER, test boolean value mapping.
*/
@Test
public void test213ModifyUserBarbossaShowInAdvancedViewOnlyFalse() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, "showInAdvancedViewOnly");
ResourceAttributeDefinition<?> attrDef = accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<Boolean> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, Boolean.TRUE);
delta.addModification(attrDelta);
// WHEN
when();
modifyUserReplace(USER_BARBOSSA_OID, ItemPath.create(UserType.F_EXTENSION, EXTENSION_SHOW_IN_ADVANCED_VIEW_ONLY_QNAME),
task, result, Boolean.FALSE);
// THEN
then();
assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "showInAdvancedViewOnly", "FALSE");
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
assertAttribute(entry, ATTRIBUTE_OBJECT_CATEGORY_NAME, getObjectCategoryPerson());
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
assertLdapConnectorReasonableInstances();
}
/**
* Just normal modification of proxyAddress, directly on the account.
* As proxyAddress is multivalue, this is ADD and not REPLACE. This is what GUI would do.
* No previous value for proxyAddress is set in the AD account.
* MID-5330
*/
@Test
public void test214ModifyAccountBarbossaProxyAddressesSimple() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, ATTRIBUTE_PROXY_ADDRESSES_NAME);
ResourceAttributeDefinition<?> attrDef = accountDefinition.findAttributeDefinition(attrQName);
assertNotNull("No definition for attribute " + attrQName, attrDef);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationAddProperty(
ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, PROXY_ADDRES_ADDR_UPCASE);
delta.addModification(attrDelta);
// WHEN
when();
executeChanges(delta, null, task, result);
// THEN
then();
assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, ATTRIBUTE_PROXY_ADDRESSES_NAME, PROXY_ADDRES_ADDR_UPCASE);
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
assertAttribute(entry, ATTRIBUTE_OBJECT_CATEGORY_NAME, getObjectCategoryPerson());
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
// assertLdapConnectorInstances(2);
}
/**
* MID-4385
*/
@Test
public void test216ModifyAccountBarbossaUserParameters() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, ATTRIBUTE_USER_PARAMETERS_NAME);
ResourceAttributeDefinition<?> attrDef = accountDefinition.findAttributeDefinition(attrQName);
assertNotNull("No definition for attribute " + attrQName, attrDef);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, VERY_STRANGE_PARAMETER);
delta.addModification(attrDelta);
// WHEN
when();
executeChanges(delta, null, task, result);
// THEN
then();
assertSuccess(result);