-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestSecurityAdvanced.java
3344 lines (2628 loc) · 146 KB
/
TestSecurityAdvanced.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-2018 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.security;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.model.api.RoleSelectionSpecification;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
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.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.TypeFilter;
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.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.security.enforcer.api.AuthorizationParameters;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.PolicyViolationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionPolicyConstraintType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyExceptionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
/**
* @author semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestSecurityAdvanced extends AbstractSecurityTest {
private static final String AUTHORIZATION_ACTION_WORKITEMS = "http://midpoint.evolveum.com/xml/ns/public/security/authorization-ui-3#myWorkItems";
private static final String BIG_BADA_BOOM = "bigBadaBoom";
private static final String HUGE_BADA_BOOM = "hugeBadaBoom";
private static final String FIRST_RULE = "firstRule";
protected static final File RESOURCE_DUMMY_VAULT_FILE = new File(TEST_DIR, "resource-dummy-vault.xml");
protected static final String RESOURCE_DUMMY_VAULT_OID = "84a420cc-2904-11e8-862b-0fc0d7ab7174";
protected static final String RESOURCE_DUMMY_VAULT_NAME = "vault";
protected static final File ROLE_VAULT_DWELLER_FILE = new File(TEST_DIR, "role-vault-dweller.xml");
protected static final String ROLE_VAULT_DWELLER_OID = "8d8471f4-2906-11e8-9078-4f2b205aa01d";
protected static final File ROLE_READ_ROLE_MEMBERS_FILE = new File(TEST_DIR, "role-read-role-members.xml");
protected static final String ROLE_READ_ROLE_MEMBERS_OID = "40df00e8-3efc-11e7-8d18-7b955ccb96a1";
protected static final File ROLE_READ_ROLE_MEMBERS_WRONG_FILE = new File(TEST_DIR, "role-read-role-members-wrong.xml");
protected static final String ROLE_READ_ROLE_MEMBERS_WRONG_OID = "8418e248-3efc-11e7-a546-931a90cb8ee3";
protected static final File ROLE_READ_ROLE_MEMBERS_NONE_FILE = new File(TEST_DIR, "role-read-role-members-none.xml");
protected static final String ROLE_READ_ROLE_MEMBERS_NONE_OID = "9e93dfb2-3eff-11e7-b56b-1b0e35f837fc";
protected static final File ROLE_LIMITED_ROLE_ADMINISTRATOR_FILE = new File(TEST_DIR, "role-limited-role-administrator.xml");
protected static final String ROLE_LIMITED_ROLE_ADMINISTRATOR_OID = "ce67b472-e5a6-11e7-98c3-174355334559";
protected static final File ROLE_LIMITED_READ_ROLE_ADMINISTRATOR_FILE = new File(TEST_DIR, "role-limited-read-role-administrator.xml");
protected static final String ROLE_LIMITED_READ_ROLE_ADMINISTRATOR_OID = "b9fcce10-050d-11e8-b668-eb75ab96577d";
protected static final File ROLE_EXCLUSION_PIRATE_FILE = new File(TEST_DIR, "role-exclusion-pirate.xml");
protected static final String ROLE_EXCLUSION_PIRATE_OID = "cf60ec66-e5a8-11e7-a997-ab32b7ec5fdb";
protected static final File ROLE_MAXASSIGNEES_10_FILE = new File(TEST_DIR, "role-maxassignees-10.xml");
protected static final String ROLE_MAXASSIGNEES_10_OID = "09dadf60-f6f1-11e7-8223-a72f04f867e7";
protected static final File ROLE_MODIFY_POLICY_EXCEPTION_FILE = new File(TEST_DIR, "role-modify-policy-exception.xml");
protected static final String ROLE_MODIFY_POLICY_EXCEPTION_OID = "09e9acde-f787-11e7-987c-13212be79c7d";
protected static final File ROLE_MODIFY_POLICY_EXCEPTION_SITUATION_FILE = new File(TEST_DIR, "role-modify-policy-exception-situation.xml");
protected static final String ROLE_MODIFY_POLICY_EXCEPTION_SITUATION_OID = "45bee61c-f79f-11e7-a2a7-27ade881c9e0";
protected static final File ROLE_MODIFY_DESCRIPTION_FILE = new File(TEST_DIR, "role-modify-description.xml");
protected static final String ROLE_MODIFY_DESCRIPTION_OID = "1a0616e4-f79a-11e7-80c9-d77b403e1a81";
protected static final File ROLE_PROP_EXCEPT_ASSIGNMENT_FILE = new File(TEST_DIR, "role-prop-except-assignment.xml");
protected static final String ROLE_PROP_EXCEPT_ASSIGNMENT_OID = "bc0f3bfe-029f-11e8-995d-273b6606fd79";
protected static final File ROLE_PROP_EXCEPT_ADMINISTRATIVE_STATUS_FILE = new File(TEST_DIR, "role-prop-except-administrative-status.xml");
protected static final String ROLE_PROP_EXCEPT_ADMINISTRATIVE_STATUS_OID = "cc549256-02a5-11e8-994e-43c307e2a819";
protected static final File ROLE_PROP_SUBTYPE_FILE = new File(TEST_DIR, "role-prop-subtype.xml");
protected static final String ROLE_PROP_SUBTYPE_OID = "0a841bcc-c255-11e8-bd03-d72f34cdd7f8";
protected static final File ROLE_PROP_SUBTYPE_ESCAPE_FILE = new File(TEST_DIR, "role-prop-subtype-escape.xml");
protected static final String ROLE_PROP_SUBTYPE_ESCAPE_OID = "bdf18bb2-c314-11e8-8e99-1709836f1462";
protected static final File ROLE_ASSIGN_ORG_FILE = new File(TEST_DIR, "role-assign-org.xml");
protected static final String ROLE_ASSIGN_ORG_OID = "be96f834-2dbb-11e8-b29d-7f5de07e7995";
protected static final File ROLE_READ_ORG_EXEC_FILE = new File(TEST_DIR, "role-read-org-exec.xml");
protected static final String ROLE_READ_ORG_EXEC_OID = "1ac39d34-e675-11e8-a1ec-37748272d526";
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
initDummyResourcePirate(RESOURCE_DUMMY_VAULT_NAME,
RESOURCE_DUMMY_VAULT_FILE, RESOURCE_DUMMY_VAULT_OID, initTask, initResult);
repoAddObjectFromFile(ROLE_VAULT_DWELLER_FILE, initResult);
repoAddObjectFromFile(ROLE_LIMITED_ROLE_ADMINISTRATOR_FILE, initResult);
repoAddObjectFromFile(ROLE_LIMITED_READ_ROLE_ADMINISTRATOR_FILE, initResult);
repoAddObjectFromFile(ROLE_MAXASSIGNEES_10_FILE, initResult);
repoAddObjectFromFile(ROLE_MODIFY_POLICY_EXCEPTION_FILE, initResult);
repoAddObjectFromFile(ROLE_MODIFY_POLICY_EXCEPTION_SITUATION_FILE, initResult);
repoAddObjectFromFile(ROLE_MODIFY_DESCRIPTION_FILE, initResult);
repoAddObjectFromFile(ROLE_PROP_EXCEPT_ASSIGNMENT_FILE, initResult);
repoAddObjectFromFile(ROLE_PROP_EXCEPT_ADMINISTRATIVE_STATUS_FILE, initResult);
repoAddObjectFromFile(ROLE_PROP_SUBTYPE_FILE, initResult);
repoAddObjectFromFile(ROLE_PROP_SUBTYPE_ESCAPE_FILE, initResult);
repoAddObjectFromFile(ROLE_ASSIGN_ORG_FILE, initResult);
repoAddObjectFromFile(ROLE_END_USER_WITH_PRIVACY_FILE, initResult);
repoAddObjectFromFile(ROLE_READ_ROLE_MEMBERS_FILE, initResult);
repoAddObjectFromFile(ROLE_READ_ROLE_MEMBERS_WRONG_FILE, initResult);
repoAddObjectFromFile(ROLE_READ_ROLE_MEMBERS_NONE_FILE, initResult);
repoAddObjectFromFile(ROLE_READ_ORG_EXEC_FILE, initResult);
setDefaultObjectTemplate(UserType.COMPLEX_TYPE, USER_TEMPLATE_SECURITY_OID, initResult);
}
protected static final int NUMBER_OF_IMPORTED_ROLES = 17;
protected int getNumberOfRoles() {
return super.getNumberOfRoles() + NUMBER_OF_IMPORTED_ROLES;
}
/**
* Stay logged in as administrator. Make sure that our assumptions about
* the users and roles are correct.
*/
@Test
public void test000Sanity() throws Exception {
final String TEST_NAME = "test000Sanity";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
// WHEN
displayWhen(TEST_NAME);
assertSearch(UserType.class, null, NUMBER_OF_ALL_USERS);
assertSearch(RoleType.class, null, getNumberOfRoles());
assertReadAllow(NUMBER_OF_ALL_USERS);
assertReadAllowRaw(NUMBER_OF_ALL_USERS);
assertAddAllow();
assertAddAllowRaw();
assertModifyAllow();
assertDeleteAllow();
assertGlobalStateUntouched();
}
/**
* Simple end-user password change. But clear Jack's credentials before
* the change. Make sure all password metadata is set correctly.
* This also sets the stage for following persona tests.
*
* MID-4830
*/
@Test
public void test080AutzJackEndUserPassword() throws Exception {
final String TEST_NAME = "test080AutzJackEndUserPassword";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_END_USER_OID);
clearUserPassword(USER_JACK_OID);
PrismObject<UserType> user = getUser(USER_JACK_OID);
display("User with cleared password", user);
assertAssignments(user, 1);
assertLinks(user, 0);
assertUserNoPassword(user);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
displayWhen(TEST_NAME);
assertAllow("set jack's password",
(task, result) -> modifyUserSetPassword(USER_JACK_OID, "nbusr123", task, result) );
// THEN
displayThen(TEST_NAME);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
user = getUser(USER_JACK_OID);
display("user after password change", user);
PasswordType passwordType = assertUserPassword(user, "nbusr123");
MetadataType metadata = passwordType.getMetadata();
assertNotNull("No password metadata", metadata);
assertMetadata("password metadata", metadata, true, false, startTs, endTs, USER_JACK_OID, SchemaConstants.CHANNEL_GUI_USER_URI);
assertGlobalStateUntouched();
}
@Test
public void test100AutzJackPersonaManagement() throws Exception {
final String TEST_NAME = "test100AutzJackPersonaManagement";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_PERSONA_MANAGEMENT_OID);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertGetAllow(UserType.class, USER_JACK_OID);
assertGetDeny(UserType.class, USER_GUYBRUSH_OID);
assertGetDeny(UserType.class, USER_LECHUCK_OID);
assertGetDeny(UserType.class, USER_CHARLES_OID);
assertSearch(UserType.class, null, 1);
assertSearch(ObjectType.class, null, 1);
assertSearch(OrgType.class, null, 0);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertGlobalStateUntouched();
}
@Test
public void test102AutzLechuckPersonaManagement() throws Exception {
final String TEST_NAME = "test102AutzLechuckPersonaManagement";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_LECHUCK_OID, 1);
assignRole(USER_LECHUCK_OID, ROLE_PERSONA_MANAGEMENT_OID);
login(USER_LECHUCK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertGetDeny(UserType.class, USER_JACK_OID);
assertGetDeny(UserType.class, USER_GUYBRUSH_OID);
assertGetAllow(UserType.class, USER_LECHUCK_OID);
display("HEREHERE");
assertGetAllow(UserType.class, USER_CHARLES_OID);
// TODO: MID-3899
// assertSearch(UserType.class, null, 2);
// assertSearch(ObjectType.class, null, 2);
assertSearch(OrgType.class, null, 0);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertGlobalStateUntouched();
}
/**
* MID-4830
*/
@Test
public void test110AutzJackPersonaAdmin() throws Exception {
final String TEST_NAME = "test110AutzJackAddPersonaAdmin";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_PERSONA_MANAGEMENT_OID);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertAllow("assign application role 1 to jack",
(task,result) -> assignRole(USER_JACK_OID, ROLE_PERSONA_ADMIN_OID, task, result));
PrismObject<UserType> userJack = assertGetAllow(UserType.class, USER_JACK_OID);
display("User jack after persona assign", userJack);
assertGetDeny(UserType.class, USER_GUYBRUSH_OID);
assertGetDeny(UserType.class, USER_LECHUCK_OID);
assertGetDeny(UserType.class, USER_CHARLES_OID);
assertPersonaLinks(userJack, 1);
String personaJackOid = userJack.asObjectable().getPersonaRef().get(0).getOid();
PrismObject<UserType> personaJack = assertGetAllow(UserType.class, personaJackOid);
display("Persona jack", personaJack);
assertEquals("Wrong jack persona givenName before change", USER_JACK_GIVEN_NAME, personaJack.asObjectable().getGivenName().getOrig());
// TODO: MID-3899
// assertSearch(UserType.class, null, 2);
// assertSearch(ObjectType.class, null, 2);
assertSearch(OrgType.class, null, 0);
assertAllow("modify jack givenName",
(task,result) -> modifyUserReplace(USER_JACK_OID, UserType.F_GIVEN_NAME, task, result,
createPolyString(USER_JACK_GIVEN_NAME_NEW)));
userJack = assertGetAllow(UserType.class, USER_JACK_OID);
assertEquals("Wrong jack givenName after change", USER_JACK_GIVEN_NAME_NEW, userJack.asObjectable().getGivenName().getOrig());
personaJack = assertGetAllow(UserType.class, personaJackOid);
assertEquals("Wrong jack persona givenName after change", USER_JACK_GIVEN_NAME_NEW, personaJack.asObjectable().getGivenName().getOrig());
assertAllow("unassign application role 1 to jack",
(task,result) -> unassignRole(USER_JACK_OID, ROLE_PERSONA_ADMIN_OID, task, result));
userJack = assertGetAllow(UserType.class, USER_JACK_OID);
assertPersonaLinks(userJack, 0);
assertNoObject(UserType.class, personaJackOid);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertGlobalStateUntouched();
}
@Test
public void test120AutzJackDelagator() throws Exception {
final String TEST_NAME = "test120AutzJackDelagator";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_DELEGATOR_OID);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertReadAllow(NUMBER_OF_ALL_USERS);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
assertAssignedRole(userJack, ROLE_DELEGATOR_OID);
PrismObject<UserType> userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
assertDeny("assign business role to jack",
(task, result) -> {
assignRole(USER_JACK_OID, ROLE_BUSINESS_1_OID, task, result);
});
userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
// Wrong direction. It should NOT work.
assertDeny("delegate from Barbossa to Jack",
(task, result) -> {
assignDeputy(USER_JACK_OID, USER_BARBOSSA_OID, task, result);
});
// Good direction
assertAllow("delegate to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, task, result);
});
userJack = getUser(USER_JACK_OID);
display("Jack delegator", userJack);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
assertAssignments(userBarbossa, 1);
assertAssignedDeputy(userBarbossa, USER_JACK_OID);
assertDeputySearchDelegatorRef(USER_JACK_OID, USER_BARBOSSA_OID);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID);
// Non-delegate. We should be able to read just the name. Not the assignments.
PrismObject<UserType> userRum = getUser(userRumRogersOid);
display("User Rum Rogers", userRum);
assertNoAssignments(userRum);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadAllow(NUMBER_OF_ALL_USERS);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Jack");
assertAllow("undelegate from Barbossa",
(task, result) -> {
unassignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, task, result);
});
userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
assertGlobalStateUntouched();
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertDeny("delegate to Jack",
(task, result) -> {
assignDeputy(USER_JACK_OID, USER_BARBOSSA_OID, task, result);
});
assertDeny("delegate from Jack to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, task, result);
});
assertGlobalStateUntouched();
}
/**
* Assign a deputy, but this time with validFrom and validTo set to the future.
* The delegator role does NOT allow access to inactive delegations.
* MID-4172
*/
@Test
public void test122AutzJackDelagatorValidity() throws Exception {
final String TEST_NAME = "test122AutzJackDelagatorValidity";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_DELEGATOR_OID);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
assertAssignedRole(userJack, ROLE_DELEGATOR_OID);
PrismObject<UserType> userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
ActivationType activationType = new ActivationType();
activationType.setValidFrom(XmlTypeConverter.addDuration(startTs, "PT2H"));
activationType.setValidTo(XmlTypeConverter.addDuration(startTs, "P1D"));
// Good direction
assertAllow("delegate to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID,
assignment -> assignment.setActivation(activationType), task, result);
});
userJack = getUser(USER_JACK_OID);
display("Jack delegator", userJack);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
// Delegation is not active yet. Therefore jack cannot see it.
assertAssignments(userBarbossa, 0);
assertDeputySearchDelegatorRef(USER_JACK_OID /* nothing */);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID); // WRONG!!!
// assertDeputySearchAssignmentTarget(USER_JACK_OID /* nothing */);
// Non-delegate. We should be able to read just the name. Not the assignments.
PrismObject<UserType> userRum = getUser(userRumRogersOid);
display("User Rum Rogers", userRum);
assertNoAssignments(userRum);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
// Delegation is not active yet. No access.
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
clockForward("PT3H");
login(USER_ADMINISTRATOR_USERNAME);
recomputeUser(USER_BARBOSSA_OID);
// Delegation is active now
login(USER_JACK_USERNAME);
// WHEN
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
assertAssignments(userBarbossa, 1);
assertAssignedDeputy(userBarbossa, USER_JACK_OID);
assertDeputySearchDelegatorRef(USER_JACK_OID, USER_BARBOSSA_OID);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadAllow(NUMBER_OF_ALL_USERS);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
clockForward("P1D");
login(USER_ADMINISTRATOR_USERNAME);
recomputeUser(USER_BARBOSSA_OID);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
// Delegation is not active any more. No access.
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Jack");
assertAllow("undelegate from Barbossa",
(task, result) -> {
unassignDeputy(USER_BARBOSSA_OID, USER_JACK_OID,
assignment -> assignment.setActivation(activationType), task, result);
});
userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
assertGlobalStateUntouched();
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertDeny("delegate to Jack",
(task, result) -> {
assignDeputy(USER_JACK_OID, USER_BARBOSSA_OID, task, result);
});
assertDeny("delegate from Jack to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, task, result);
});
assertGlobalStateUntouched();
}
/**
* Assign a deputy with validity. But this time there is a role that allows
* access to inactive delegations.
* MID-4172
*/
@Test
public void test124AutzJackDelagatorPlusValidity() throws Exception {
final String TEST_NAME = "test124AutzJackDelagatorPlusValidity";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_DELEGATOR_PLUS_OID);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
assertAssignedRole(userJack, ROLE_DELEGATOR_PLUS_OID);
PrismObject<UserType> userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
ActivationType activationType = new ActivationType();
activationType.setValidFrom(XmlTypeConverter.addDuration(startTs, "PT2H"));
activationType.setValidTo(XmlTypeConverter.addDuration(startTs, "P1D"));
// Good direction
assertAllow("delegate to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID,
assignment -> assignment.setActivation(activationType), task, result);
});
userJack = getUser(USER_JACK_OID);
display("Jack delegator", userJack);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
assertAssignments(userBarbossa, 1);
assertAssignedDeputy(userBarbossa, USER_JACK_OID);
// delegatorRef is allowed, but returns nothing. The delegation is not yet active, it is not in the delgatorRef.
assertDeputySearchDelegatorRef(USER_JACK_OID /* nothing */);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID);
// Non-delegate. We should be able to read just the name. Not the assignments.
PrismObject<UserType> userRum = getUser(userRumRogersOid);
display("User Rum Rogers", userRum);
assertNoAssignments(userRum);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
// Delegation is not active yet. No access.
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
clockForward("PT3H");
login(USER_ADMINISTRATOR_USERNAME);
recomputeUser(USER_BARBOSSA_OID);
// Delegation is active now
login(USER_JACK_USERNAME);
// WHEN
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
assertAssignments(userBarbossa, 1);
assertAssignedDeputy(userBarbossa, USER_JACK_OID);
assertDeputySearchDelegatorRef(USER_JACK_OID, USER_BARBOSSA_OID);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadAllow(NUMBER_OF_ALL_USERS);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
clockForward("P1D");
login(USER_ADMINISTRATOR_USERNAME);
recomputeUser(USER_BARBOSSA_OID);
// Delegation no longer active
login(USER_JACK_USERNAME);
// WHEN
userBarbossa = getUser(USER_BARBOSSA_OID);
display("Barbossa delegate", userBarbossa);
assertAssignments(userBarbossa, 1);
assertAssignedDeputy(userBarbossa, USER_JACK_OID);
// delegatorRef is allowed, but returns nothing. The delegation is not yet active, it is not in the delgatorRef.
assertDeputySearchDelegatorRef(USER_JACK_OID /* nothing */);
assertDeputySearchAssignmentTarget(USER_JACK_OID, USER_BARBOSSA_OID);
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
// Delegation is not active any more. No access.
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Jack");
assertAllow("undelegate from Barbossa",
(task, result) -> {
unassignDeputy(USER_BARBOSSA_OID, USER_JACK_OID,
assignment -> assignment.setActivation(activationType), task, result);
});
userJack = getUser(USER_JACK_OID);
assertAssignments(userJack, 1);
userBarbossa = getUser(USER_BARBOSSA_OID);
assertNoAssignments(userBarbossa);
assertGlobalStateUntouched();
login(USER_BARBOSSA_USERNAME);
// WHEN
displayWhen(TEST_NAME);
display("Logged in as Barbossa");
assertReadDeny();
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertDeny("delegate to Jack",
(task, result) -> {
assignDeputy(USER_JACK_OID, USER_BARBOSSA_OID, task, result);
});
assertDeny("delegate from Jack to Barbossa",
(task, result) -> {
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, task, result);
});
assertGlobalStateUntouched();
}
@Test
public void test150AutzJackApproverUnassignRoles() throws Exception {
final String TEST_NAME = "test150AutzJackApproverUnassignRoles";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_APPROVER_UNASSIGN_ROLES_OID);
assignRole(USER_JACK_OID, ROLE_ORDINARY_OID, SchemaConstants.ORG_APPROVER);
PrismObject<UserType> userCobbBefore = getUser(userCobbOid);
IntegrationTestTools.display("User cobb before", userCobbBefore);
assertRoleMembershipRef(userCobbBefore, ROLE_ORDINARY_OID, ROLE_UNINTERESTING_OID, ORG_SCUMM_BAR_OID);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertGetAllow(RoleType.class, ROLE_ORDINARY_OID);
assertGetDeny(RoleType.class, ROLE_PERSONA_ADMIN_OID); // no assignment
assertGetDeny(RoleType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID); // assignment exists, but wrong relation
PrismObject<UserType> userRum = assertGetAllow(UserType.class, userRumRogersOid); // member of ROLE_ORDINARY_OID
display("User Rum Rogers", userRumRogersOid);
assertRoleMembershipRef(userRum, ROLE_ORDINARY_OID, ROLE_UNINTERESTING_OID, ORG_MINISTRY_OF_RUM_OID);
assertGetAllow(UserType.class, userCobbOid); // member of ROLE_ORDINARY_OID
assertGetDeny(UserType.class, USER_JACK_OID); // assignment exists, but wrong relation
assertGetDeny(UserType.class, USER_GUYBRUSH_OID); // no assignment to ROLE_ORDINARY_OID
assertGetDeny(UserType.class, USER_LECHUCK_OID); // no assignment to ROLE_ORDINARY_OID
assertSearch(OrgType.class, null, 0);
// The appr-read-roles authorization is maySkipOnSearch and there is no other authorization that would
// allow read, so no role are returned
assertSearch(RoleType.class, null, 0);
// The appr-read-users authorization is maySkipOnSearch and there is no other authorization that would
// allow read, so no users are returned
assertSearch(UserType.class, null, 0);
assertSearch(UserType.class, createMembersQuery(UserType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID), 0);
assert15xCommon();
}
@Test
public void test151AutzJackApproverUnassignRolesAndRead() throws Exception {
final String TEST_NAME = "test151AutzJackApproverUnassignRolesAndRead";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_APPROVER_UNASSIGN_ROLES_OID);
assignRole(USER_JACK_OID, ROLE_READ_BASIC_ITEMS_OID);
assignRole(USER_JACK_OID, ROLE_ORDINARY_OID, SchemaConstants.ORG_APPROVER);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertGetAllow(RoleType.class, ROLE_ORDINARY_OID);
assertGetAllow(RoleType.class, ROLE_PERSONA_ADMIN_OID); // no assignment
assertGetAllow(RoleType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID); // assignment exists, but wrong relation
PrismObject<UserType> userRum = assertGetAllow(UserType.class, userRumRogersOid); // member of ROLE_ORDINARY_OID
display("User Rum Rogers", userRumRogersOid);
assertRoleMembershipRef(userRum, ROLE_ORDINARY_OID, ROLE_UNINTERESTING_OID, ORG_MINISTRY_OF_RUM_OID);
assertGetAllow(UserType.class, userCobbOid); // member of ROLE_ORDINARY_OID
PrismObject<UserType> userJack = assertGetAllow(UserType.class, USER_JACK_OID); // assignment exists, but wrong relation
assertNoRoleMembershipRef(userJack);
assertGetAllow(UserType.class, USER_GUYBRUSH_OID); // no assignment to ROLE_ORDINARY_OID
assertGetAllow(UserType.class, USER_LECHUCK_OID); // no assignment to ROLE_ORDINARY_OID
assertSearch(OrgType.class, null, NUMBER_OF_ALL_ORGS);
// The appr-read-roles authorization is maySkipOnSearch and the readonly role allows read.
assertSearch(RoleType.class, null, getNumberOfRoles());
// The appr-read-users authorization is maySkipOnSearch and the readonly role allows read.
assertSearch(UserType.class, null, NUMBER_OF_ALL_USERS);
assert15xCommon();
}
/**
* Jack is an approver of a role, but he does not have any authorization
* except very basic object read.
*/
@Test
public void test154AutzJackApproverRead() throws Exception {
final String TEST_NAME = "test154AutzJackApproverRead";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_READ_BASIC_ITEMS_OID);
assignRole(USER_JACK_OID, ROLE_ORDINARY_OID, SchemaConstants.ORG_APPROVER);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
PrismObject<RoleType> roleOrdinary = assertGetAllow(RoleType.class, ROLE_ORDINARY_OID);
assertNoRoleMembershipRef(roleOrdinary);
assertGetAllow(RoleType.class, ROLE_PERSONA_ADMIN_OID);
PrismObject<RoleType> roleAppr = assertGetAllow(RoleType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID);
assertNoRoleMembershipRef(roleAppr);
PrismObject<UserType> userRum = assertGetAllow(UserType.class, userRumRogersOid);
assertNoRoleMembershipRef(userRum);
assertGetAllow(UserType.class, userCobbOid);
assertGetAllow(UserType.class, USER_JACK_OID);
assertGetAllow(UserType.class, USER_GUYBRUSH_OID);
assertGetAllow(UserType.class, USER_LECHUCK_OID);
assertSearch(OrgType.class, null, NUMBER_OF_ALL_ORGS);
assertSearch(RoleType.class, null, getNumberOfRoles());
assertSearch(UserType.class, null, NUMBER_OF_ALL_USERS);
assertSearch(UserType.class, createMembersQuery(UserType.class, ROLE_ORDINARY_OID), 0);
assertSearch(UserType.class, createMembersQuery(UserType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID), 0);
assertCanSearchRoleMemberUsers(ROLE_ORDINARY_OID, false);
assertCanSearchRoleMembers(ROLE_ORDINARY_OID, false);
assertCanSearchRoleMemberUsers(ROLE_UNINTERESTING_OID, false);
assertCanSearchRoleMembers(ROLE_UNINTERESTING_OID, false);
assertCanSearchRoleMemberUsers(ROLE_APPROVER_UNASSIGN_ROLES_OID, false);
assertCanSearchRoleMembers(ROLE_UNINTERESTING_OID, false);
assertDeny("unassign ordinary role from cobb",
(task,result) -> unassignRole(userCobbOid, ROLE_ORDINARY_OID, task, result));
assertSearch(UserType.class, createMembersQuery(UserType.class, ROLE_ORDINARY_OID), 0);
assertDeny("unassign uninteresting role from cobb",
(task,result) -> unassignRole(userCobbOid, ROLE_UNINTERESTING_OID, task, result));
assertDeny("unassign uninteresting role from rum",
(task,result) -> unassignRole(userRumRogersOid, ROLE_UNINTERESTING_OID, task, result));
assertDeny("unassign approver role from jack",
(task,result) -> unassignRole(USER_JACK_OID, ROLE_APPROVER_UNASSIGN_ROLES_OID, task, result));
assertDeny("unassign ordinary role from lechuck",
(task,result) -> unassignRole(USER_LECHUCK_OID, ROLE_ORDINARY_OID, task, result));
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
assertGlobalStateUntouched();
}
/**
* Jack is an approver of a role, but he does not have any authorization
* except reading self.
* Note: tests with role-self and no approver are in TestSecurityBasic.test204AutzJackSelfRole()
*/
@Test
public void test155AutzJackApproverSelf() throws Exception {
final String TEST_NAME = "test155AutzJackApproverSelf";
displayTestTitle(TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_SELF_OID);
assignRole(USER_JACK_OID, ROLE_ORDINARY_OID, SchemaConstants.ORG_APPROVER);
login(USER_JACK_USERNAME);
// WHEN
displayWhen(TEST_NAME);
assertGetDeny(RoleType.class, ROLE_ORDINARY_OID);
assertGetDeny(RoleType.class, ROLE_PERSONA_ADMIN_OID);
assertGetDeny(RoleType.class, ROLE_APPROVER_UNASSIGN_ROLES_OID);