-
Notifications
You must be signed in to change notification settings - Fork 188
/
AbstractPasswordTest.java
1672 lines (1299 loc) · 69.3 KB
/
AbstractPasswordTest.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-2017 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.intest.password;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static org.testng.AssertJUnit.*;
import java.io.File;
import java.util.Collection;
import javax.xml.datatype.XMLGregorianCalendar;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.SchemaViolationException;
import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.PolicyViolationException;
/**
* @author semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class AbstractPasswordTest extends AbstractInitializedModelIntegrationTest {
protected static final String USER_PASSWORD_1_CLEAR = "d3adM3nT3llN0Tal3s";
protected static final String USER_PASSWORD_2_CLEAR = "bl4ckP3arl";
protected static final String USER_PASSWORD_3_CLEAR = "wh3r3sTheRum?";
protected static final String USER_PASSWORD_4_CLEAR = "sh1v3rM3T1mb3rs";
protected static final String USER_PASSWORD_5_CLEAR = "s3tSa1al";
protected static final String USER_PASSWORD_A_CLEAR = "A"; // too short
protected static final String USER_PASSWORD_JACK_CLEAR = "12jAcK34"; // contains username
protected static final String USER_PASSWORD_SPARROW_CLEAR = "saRRow123"; // contains familyName
protected static final String USER_PASSWORD_VALID_1 = "abcd123";
protected static final String USER_PASSWORD_VALID_2 = "abcd223";
protected static final String USER_PASSWORD_VALID_3 = "abcd323";
protected static final String USER_PASSWORD_VALID_4 = "abcd423";
public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "password");
protected static final File RESOURCE_DUMMY_UGLY_FILE = new File(TEST_DIR, "resource-dummy-ugly.xml");
protected static final String RESOURCE_DUMMY_UGLY_OID = "10000000-0000-0000-0000-000000344104";
protected static final String RESOURCE_DUMMY_UGLY_NAME = "ugly";
protected static final File PASSWORD_POLICY_UGLY_FILE = new File(TEST_DIR, "password-policy-ugly.xml");
protected static final String PASSWORD_POLICY_UGLY_OID = "cfb3fa9e-027a-11e7-8e2c-dbebaacaf4ee";
protected static final File SECURITY_POLICY_DEFAULT_STORAGE_HASHING_FILE = new File(TEST_DIR, "security-policy-default-storage-hashing.xml");
protected static final String SECURITY_POLICY_DEFAULT_STORAGE_HASHING_OID = "0ea3b93c-0425-11e7-bbc1-73566dc53d59";
protected static final File SECURITY_POLICY_PASSWORD_STORAGE_NONE_FILE = new File(TEST_DIR, "security-policy-password-storage-none.xml");
protected static final String SECURITY_POLICY_PASSWORD_STORAGE_NONE_OID = "2997a20a-0423-11e7-af65-a7ab7d19442c";
protected static final String USER_JACK_EMPLOYEE_NUMBER_NEW_BAD = "No1";
protected static final String USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD = "pir321";
protected String accountJackOid;
protected String accountJackRedOid;
protected String accountJackUglyOid;
protected String accountJackYellowOid;
protected XMLGregorianCalendar lastPasswordChangeStart;
protected XMLGregorianCalendar lastPasswordChangeEnd;
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
importObjectFromFile(PASSWORD_POLICY_UGLY_FILE);
importObjectFromFile(SECURITY_POLICY_DEFAULT_STORAGE_HASHING_FILE);
importObjectFromFile(SECURITY_POLICY_PASSWORD_STORAGE_NONE_FILE);
setGlobalSecurityPolicy(getSecurityPolicyOid(), initResult);
initDummyResourcePirate(RESOURCE_DUMMY_UGLY_NAME, RESOURCE_DUMMY_UGLY_FILE, RESOURCE_DUMMY_UGLY_OID, initTask, initResult);
login(USER_ADMINISTRATOR_USERNAME);
}
protected abstract String getSecurityPolicyOid();
@Test
public void test010AddPasswordPolicy() throws Exception {
final String TEST_NAME = "test010AddPasswordPolicy";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
// WHEN
PrismObject<ObjectType> passwordPolicy = addObject(PASSWORD_POLICY_GLOBAL_FILE, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
assertEquals("Wrong OID after add", PASSWORD_POLICY_GLOBAL_OID, passwordPolicy.getOid());
// Check object
PrismObject<ValuePolicyType> valuePolicy = repositoryService.getObject(ValuePolicyType.class, PASSWORD_POLICY_GLOBAL_OID, null, result);
// TODO: more asserts
}
@Test
public void test050CheckJackPassword() throws Exception {
final String TEST_NAME = "test050CheckJackPassword";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN, WHEN
// this happens during test initialization when user-jack.xml is added
// THEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
// Password still encrypted. We haven't changed it yet.
assertUserPassword(userJack, USER_JACK_PASSWORD, CredentialsStorageTypeType.ENCRYPTION);
}
@Test
public void test051ModifyUserJackPassword() throws Exception {
final String TEST_NAME = "test051ModifyUserJackPassword";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
XMLGregorianCalendar startCal = clock.currentTimeXMLGregorianCalendar();
// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserChangePassword(USER_JACK_OID, USER_PASSWORD_1_CLEAR, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
XMLGregorianCalendar endCal = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
assertUserPassword(userJack, USER_PASSWORD_1_CLEAR);
assertPasswordMetadata(userJack, false, startCal, endCal);
// Password policy is not active yet. No history should be kept.
assertPasswordHistoryEntries(userJack);
}
@Test
public void test060CheckJackPasswordModelInteraction() throws Exception {
final String TEST_NAME = "test060CheckJackPasswordModelInteraction";
TestUtil.displayTestTile(this, TEST_NAME);
if (getPasswordStorageType() == CredentialsStorageTypeType.NONE) {
// Nothing to check in this case
return;
}
// GIVEN
Task task = createTask(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN, THEN
ProtectedStringType userPasswordPsGood = new ProtectedStringType();
userPasswordPsGood.setClearValue(USER_PASSWORD_1_CLEAR);
assertTrue("Good password check failed",
modelInteractionService.checkPassword(USER_JACK_OID, userPasswordPsGood, task, result));
ProtectedStringType userPasswordPsBad = new ProtectedStringType();
userPasswordPsBad.setClearValue("this is not a password");
assertFalse("Bad password check failed",
modelInteractionService.checkPassword(USER_JACK_OID, userPasswordPsBad, task, result));
ProtectedStringType userPasswordPsEmpty = new ProtectedStringType();
assertFalse("Empty password check failed",
modelInteractionService.checkPassword(USER_JACK_OID, userPasswordPsEmpty, task, result));
assertFalse("Null password check failed",
modelInteractionService.checkPassword(USER_JACK_OID, null, task, result));
}
@Test
public void test070AddUserHerman() throws Exception {
final String TEST_NAME = "test070AddUserHerman";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
XMLGregorianCalendar startCal = clock.currentTimeXMLGregorianCalendar();
// WHEN
TestUtil.displayWhen(TEST_NAME);
addObject(USER_HERMAN_FILE, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
XMLGregorianCalendar endCal = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userAfter = getUser(USER_HERMAN_OID);
display("User after", userAfter);
assertUser(userAfter, USER_HERMAN_OID, USER_HERMAN_USERNAME,
USER_HERMAN_FULL_NAME, USER_HERMAN_GIVEN_NAME, USER_HERMAN_FAMILY_NAME);
assertUserPassword(userAfter, USER_HERMAN_PASSWORD);
assertPasswordMetadata(userAfter, true, startCal, endCal);
// Password policy is not active yet. No history should be kept.
assertPasswordHistoryEntries(userAfter);
}
@Test
public void test100ModifyUserJackAssignAccount() throws Exception {
final String TEST_NAME = "test100ModifyUserJackAssignAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// WHEN
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
accountJackOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
assertShadowLifecycle(accountShadow, false);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
assertShadowLifecycle(accountModel, false);
// Check account in dummy resource
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertDummyPasswordConditional(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
}
/**
* This time user has assigned account. Account password should be changed as well.
*/
@Test
public void test110ModifyUserJackPassword() throws Exception {
final String TEST_NAME = "test110ModifyUserJackPassword";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
lastPasswordChangeStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
modifyUserChangePassword(USER_JACK_OID, USER_PASSWORD_2_CLEAR, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
lastPasswordChangeEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
assertUserPassword(userJack, USER_PASSWORD_2_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_2_CLEAR);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Modify account password. User's password should be unchanged
*/
@Test
public void test111ModifyAccountJackPassword() throws Exception {
final String TEST_NAME = "test111ModifyAccountJackPassword";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// WHEN
modifyAccountChangePassword(accountJackOid, USER_PASSWORD_3_CLEAR, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
// User should still have old password
assertUserPassword(userJack, USER_PASSWORD_2_CLEAR);
// Account has new password
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_3_CLEAR);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Modify both user and account password. As password outbound mapping is weak the user should have its own password
* and account should have its own password.
*/
@Test
public void test112ModifyJackPasswordUserAndAccount() throws Exception {
final String TEST_NAME = "test112ModifyJackPasswordUserAndAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
ProtectedStringType userPasswordPs4 = new ProtectedStringType();
userPasswordPs4.setClearValue(USER_PASSWORD_4_CLEAR);
ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_JACK_OID, PASSWORD_VALUE_PATH, userPasswordPs4);
ProtectedStringType userPasswordPs5 = new ProtectedStringType();
userPasswordPs5.setClearValue(USER_PASSWORD_5_CLEAR);
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountJackOid, getDummyResourceObject(),
PASSWORD_VALUE_PATH, userPasswordPs5);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta, userDelta);
lastPasswordChangeStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
lastPasswordChangeEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
// User should still have old password
assertUserPassword(userJack, USER_PASSWORD_4_CLEAR);
// Account has new password
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_5_CLEAR);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Add red and ugly dummy resource to the mix. This would be fun.
*/
@Test
public void test120ModifyUserJackAssignAccountDummyRedAndUgly() throws Exception {
final String TEST_NAME = "test120ModifyUserJackAssignAccountDummyRedAndUgly";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// WHEN
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_RED_OID, null, task, result);
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_UGLY_OID, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
assertLinks(userJack, 3);
accountJackRedOid = getLinkRefOid(userJack, RESOURCE_DUMMY_RED_OID);
accountJackUglyOid = getLinkRefOid(userJack, RESOURCE_DUMMY_UGLY_OID);
// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertDummyPasswordConditional(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_4_CLEAR);
assertDummyAccount(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, null, true);
assertDummyPasswordConditional(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER);
// User and default dummy account should have unchanged passwords
assertUserPassword(userJack, USER_PASSWORD_4_CLEAR);
assertDummyPassword("jack", USER_PASSWORD_5_CLEAR);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Modify both user and account password. Red dummy has a strong password mapping. User change should override account
* change.
*/
@Test
public void test121ModifyJackPasswordUserAndAccountRed() throws Exception {
final String TEST_NAME = "test121ModifyJackPasswordUserAndAccountRed";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
ProtectedStringType userPasswordPs1 = new ProtectedStringType();
userPasswordPs1.setClearValue(USER_PASSWORD_1_CLEAR);
ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_JACK_OID, PASSWORD_VALUE_PATH, userPasswordPs1);
ProtectedStringType userPasswordPs2 = new ProtectedStringType();
userPasswordPs2.setClearValue(USER_PASSWORD_2_CLEAR);
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountJackRedOid, getDummyResourceObject(),
PASSWORD_VALUE_PATH, userPasswordPs2);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta);
lastPasswordChangeStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
lastPasswordChangeEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, USER_JACK_FULL_NAME);
// User should still have old password
assertUserPassword(userJack, USER_PASSWORD_1_CLEAR);
// Red account has the same account as user
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// ... and default account has also the same password as user now. There was no other change on default dummy instance
// so even the weak mapping took place.
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// this one is not changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER);
assertLinks(userJack, 3);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Jack employee number is mapped to ugly resource password.
* Change employee number to something that does NOT comply with ugly resource password policy.
* MID-3769
*/
@Test
public void test125ModifyJackEmployeeNumberBad() throws Exception {
final String TEST_NAME = "test125ModifyJackEmployeeNumberBad";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
try {
// WHEN
modifyUserReplace(USER_JACK_OID, UserType.F_EMPLOYEE_NUMBER, task, result,
USER_JACK_EMPLOYEE_NUMBER_NEW_BAD);
assertNotReached();
} catch (PolicyViolationException e) {
// this is expected
display("Expected exception", e);
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertUserPassword(userJack, USER_PASSWORD_1_CLEAR);
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// ugly password should be changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER);
assertLinks(userJack, 3);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Jack employee number is mapped to ugly resource password.
* Change employee number to something that does comply with ugly resource password policy.
* MID-3769
*/
@Test
public void test128ModifyJackEmployeeNumberGood() throws Exception {
final String TEST_NAME = "test128ModifyJackEmployeeNumberGood";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
modifyUserReplace(USER_JACK_OID, UserType.F_EMPLOYEE_NUMBER, task, result,
USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertUserPassword(userJack, USER_PASSWORD_1_CLEAR);
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// ugly password should be changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD);
assertLinks(userJack, 3);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
}
/**
* Yellow resource has minimum password length constraint. But this time the password is OK.
*/
@Test
public void test130ModifyUserJackAssignAccountDummyYellow() throws Exception {
final String TEST_NAME = "test130ModifyUserJackAssignAccountDummyYellow";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// WHEN
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_YELLOW_OID, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertLinks(userJack, 4);
accountJackYellowOid = getLinkRefOid(userJack, RESOURCE_DUMMY_YELLOW_OID);
// Check account in dummy resource (yellow)
assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPasswordConditional(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// Check account in dummy resource (red)
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// User and default dummy account should have unchanged passwords
assertUserPassword(userJack, USER_PASSWORD_1_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// this one is not changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD);
assertPasswordMetadata(userJack, false, lastPasswordChangeStart, lastPasswordChangeEnd);
assertPasswordHistoryEntries(userJack);
}
/**
* Yellow resource has minimum password length constraint. Change password to something shorter.
* MID-3033, MID-2134
*/
@Test
public void test132ModifyUserJackPasswordA() throws Exception {
final String TEST_NAME = "test132ModifyUserJackPasswordA";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
lastPasswordChangeStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
modifyUserChangePassword(USER_JACK_OID, USER_PASSWORD_A_CLEAR, task, result);
// THEN
result.computeStatus();
TestUtil.assertPartialError(result);
lastPasswordChangeEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertLinks(userJack, 4);
accountJackYellowOid = getLinkRefOid(userJack, RESOURCE_DUMMY_YELLOW_OID);
// Check account in dummy resource (yellow): password is too short for this, original password should remain there
assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPasswordConditional(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// Check account in dummy resource (red)
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_A_CLEAR);
// User and default dummy account should have unchanged passwords
assertUserPassword(userJack, USER_PASSWORD_A_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_A_CLEAR);
// this one is not changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD);
assertPasswordHistoryEntries(userJack);
}
@Test
public void test200ApplyPasswordPolicy() throws Exception {
final String TEST_NAME = "test200ApplyPasswordPolicy";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
PrismReferenceValue passPolicyRef = new PrismReferenceValue(PASSWORD_POLICY_GLOBAL_OID, ValuePolicyType.COMPLEX_TYPE);
// WHEN
modifyObjectReplaceReference(SecurityPolicyType.class, getSecurityPolicyOid(),
new ItemPath(SecurityPolicyType.F_CREDENTIALS, CredentialsPolicyType.F_PASSWORD, PasswordCredentialsPolicyType.F_PASSWORD_POLICY_REF),
task, result, passPolicyRef);
modifyObjectReplaceProperty(SecurityPolicyType.class, getSecurityPolicyOid(),
new ItemPath(SecurityPolicyType.F_CREDENTIALS, CredentialsPolicyType.F_PASSWORD, PasswordCredentialsPolicyType.F_HISTORY_LENGTH),
task, result, 3);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
}
/**
* Reconcile user after password policy change. Nothing should be changed in the user.
* Password history should still be empty. We haven't changed the password yet.
* MID-3567
*/
@Test
public void test202ReconcileUserJack() throws Exception {
final String TEST_NAME = "test202ReconcileUserJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User before", userBefore);
assertLinks(userBefore, 4);
// WHEN
reconcileUser(USER_JACK_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertLinks(userAfter, 4);
accountJackYellowOid = getLinkRefOid(userAfter, RESOURCE_DUMMY_YELLOW_OID);
// Check account in dummy resource (yellow): password is too short for this, original password should remain there
assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPasswordConditional(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_1_CLEAR);
// Check account in dummy resource (red)
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyPassword(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_A_CLEAR);
// User and default dummy account should have unchanged passwords
assertUserPassword(userAfter, USER_PASSWORD_A_CLEAR);
assertDummyPassword(ACCOUNT_JACK_DUMMY_USERNAME, USER_PASSWORD_A_CLEAR);
// this one is not changed
assertDummyPassword(RESOURCE_DUMMY_UGLY_NAME, ACCOUNT_JACK_DUMMY_USERNAME, USER_JACK_EMPLOYEE_NUMBER_NEW_GOOD);
assertPasswordHistoryEntries(userAfter);
}
/**
* Change to password that complies with password policy.
*/
@Test
public void test210ModifyUserJackPasswordGood() throws Exception {
doTestModifyUserJackPasswordSuccessWithHistory("test210ModifyUserJackPasswordGood",
USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Reconcile user. Nothing should be changed.
* MID-3567
*/
@Test
public void test212ReconcileUserJack() throws Exception {
final String TEST_NAME = "test212ReconcileUserJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
reconcileUser(USER_JACK_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
assertJackPasswordsWithHistory(USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Recompute user. Nothing should be changed.
* MID-3567
*/
@Test
public void test214RecomputeUserJack() throws Exception {
final String TEST_NAME = "test214RecomputeUserJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
recomputeUser(USER_JACK_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
assertJackPasswordsWithHistory(USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Change to password that violates the password policy (but is still OK for yellow resource).
*/
@Test
public void test220ModifyUserJackPasswordBadA() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test220ModifyUserJackPasswordBadA",
USER_PASSWORD_1_CLEAR, USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Change to password that violates the password policy (but is still OK for yellow resource).
* Use a different delta (container delta instead of property delta).
* MID-2857
*/
@Test
public void test222ModifyUserJackPasswordBadContainer() throws Exception {
final String TEST_NAME = "test222ModifyUserJackPasswordBadContainer";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractPasswordTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
ProtectedStringType userPasswordPs = new ProtectedStringType();
userPasswordPs.setClearValue(USER_PASSWORD_1_CLEAR);
PasswordType passwordType = new PasswordType();
passwordType.setValue(userPasswordPs);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, USER_JACK_OID,
new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD),
prismContext, passwordType);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
display("Exected exception", e);
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
assertJackPasswordsWithHistory(USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Change to password that violates the password policy (contains username)
* MID-1657
*/
@Test
public void test224ModifyUserJackPasswordBadJack() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test224ModifyUserJackPasswordBadJack",
USER_PASSWORD_JACK_CLEAR, USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Change to password that violates the password policy (contains family name)
* MID-1657
*/
@Test
public void test226ModifyUserJackPasswordBadSparrow() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test226ModifyUserJackPasswordBadSparrow",
USER_PASSWORD_SPARROW_CLEAR, USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
/**
* Change to password that complies with password policy. Again. See that
* the change is applied correctly and that it is included in the history.
*/
@Test
public void test230ModifyUserJackPasswordGoodAgain() throws Exception {
doTestModifyUserJackPasswordSuccessWithHistory("test230ModifyUserJackPasswordGoodAgain",
USER_PASSWORD_VALID_2, USER_PASSWORD_A_CLEAR, USER_PASSWORD_VALID_1);
}
/**
* Change to password that is good but it is the same as current password.
*/
@Test
public void test235ModifyUserJackPasswordGoodSameAsCurrent() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test235ModifyUserJackPasswordGoodSameAsCurrent",
USER_PASSWORD_VALID_2, USER_PASSWORD_VALID_2, USER_PASSWORD_A_CLEAR, USER_PASSWORD_VALID_1);
}
/**
* Change to password that is good but it is already in the history.
*/
@Test
public void test236ModifyUserJackPasswordGoodInHistory() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test236ModifyUserJackPasswordGoodInHistory",
USER_PASSWORD_VALID_1, USER_PASSWORD_VALID_2, USER_PASSWORD_A_CLEAR, USER_PASSWORD_VALID_1);
}
/**
* Change to password that is bad and it is already in the history.
*/
@Test
public void test237ModifyUserJackPasswordBadInHistory() throws Exception {
doTestModifyUserJackPasswordFailureWithHistory("test237ModifyUserJackPasswordBadInHistory",
USER_PASSWORD_A_CLEAR, USER_PASSWORD_VALID_2, USER_PASSWORD_A_CLEAR, USER_PASSWORD_VALID_1);
}
/**
* Change to password that complies with password policy. Again.
* This time there are enough passwords in the history. So the history should
* be truncated.
*/
@Test
public void test240ModifyUserJackPasswordGoodAgainOverHistory() throws Exception {
doTestModifyUserJackPasswordSuccessWithHistory("test240ModifyUserJackPasswordGoodAgainOverHistory",
USER_PASSWORD_VALID_3, USER_PASSWORD_VALID_1, USER_PASSWORD_VALID_2);
}
/**
* Change to password that complies with password policy. Again.
* This time there are enough passwords in the history. So the history should
* be truncated.
*/
@Test
public void test241ModifyUserJackPasswordGoodAgainOverHistoryAgain() throws Exception {
doTestModifyUserJackPasswordSuccessWithHistory("test241ModifyUserJackPasswordGoodAgainOverHistoryAgain",
USER_PASSWORD_VALID_4, USER_PASSWORD_VALID_2, USER_PASSWORD_VALID_3);
}
/**
* Reuse old password. Now the password should be out of the history, so
* the system should allow its reuse.
*/
@Test
public void test248ModifyUserJackPasswordGoodReuse() throws Exception {
doTestModifyUserJackPasswordSuccessWithHistory("test248ModifyUserJackPasswordGoodReuse",
USER_PASSWORD_VALID_1, USER_PASSWORD_VALID_3, USER_PASSWORD_VALID_4);
}
private void doTestModifyUserJackPasswordSuccessWithHistory(final String TEST_NAME,
String newPassword, String... expectedPasswordHistory) throws Exception {
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
lastPasswordChangeStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
modifyUserChangePassword(USER_JACK_OID, newPassword, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
lastPasswordChangeEnd = clock.currentTimeXMLGregorianCalendar();
assertJackPasswordsWithHistory(newPassword, expectedPasswordHistory);
}
private void doTestModifyUserJackPasswordFailureWithHistory(final String TEST_NAME,
String newPassword, String oldPassword, String... expectedPasswordHistory) throws Exception {
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
try {
// WHEN
modifyUserChangePassword(USER_JACK_OID, newPassword, task, result);
AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
display("Exected exception", e);
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);