/
TestRbac.java
4420 lines (3452 loc) · 182 KB
/
TestRbac.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.rbac;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.util.QNameUtil;
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.DummyAccount;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignment;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
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.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.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.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
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.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
/**
* @author semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestRbac extends AbstractInitializedModelIntegrationTest {
protected static final File TEST_DIR = new File("src/test/resources", "rbac");
protected static final File ROLE_ADRIATIC_PIRATE_FILE = new File(TEST_DIR, "role-adriatic-pirate.xml");
protected static final String ROLE_ADRIATIC_PIRATE_OID = "12345678-d34d-b33f-f00d-5555555566aa";
protected static final File ROLE_BLACK_SEA_PIRATE_FILE = new File(TEST_DIR, "role-black-sea-pirate.xml");
protected static final String ROLE_BLACK_SEA_PIRATE_OID = "12345678-d34d-b33f-f00d-5555555566bb";
protected static final File ROLE_INDIAN_OCEAN_PIRATE_FILE = new File(TEST_DIR, "role-indian-ocean-pirate.xml");
protected static final String ROLE_INDIAN_OCEAN_PIRATE_OID = "12345678-d34d-b33f-f00d-555555556610";
protected static final File ROLE_HONORABILITY_FILE = new File(TEST_DIR, "role-honorability.xml");
protected static final String ROLE_HONORABILITY_OID = "12345678-d34d-b33f-f00d-555555557701";
protected static final File ROLE_CLERIC_FILE = new File(TEST_DIR, "role-cleric.xml");
protected static final String ROLE_CLERIC_OID = "12345678-d34d-b33f-f00d-555555557702";
protected static final File ROLE_WANNABE_FILE = new File(TEST_DIR, "role-wannabe.xml");
protected static final String ROLE_WANNABE_OID = "12345678-d34d-b33f-f00d-555555557703";
protected static final File ROLE_HONORABLE_WANNABE_FILE = new File(TEST_DIR, "role-honorable-wannabe.xml");
protected static final String ROLE_HONORABLE_WANNABE_OID = "12345678-d34d-b33f-f00d-555555557704";
protected static final File ROLE_GOVERNOR_FILE = new File(TEST_DIR, "role-governor.xml");
protected static final String ROLE_GOVERNOR_OID = "12345678-d34d-b33f-f00d-555555557705";
protected static final File ROLE_CANNIBAL_FILE = new File(TEST_DIR, "role-cannibal.xml");
protected static final String ROLE_CANNIBAL_OID = "12345678-d34d-b33f-f00d-555555557706";
protected static final File ROLE_PROJECT_OMNINAMAGER_FILE = new File(TEST_DIR, "role-project-omnimanager.xml");
protected static final String ROLE_PROJECT_OMNINAMAGER_OID = "f23ab26c-69df-11e6-8330-979c643ea51c";
protected static final File ROLE_WEAK_GOSSIPER_FILE = new File(TEST_DIR, "role-weak-gossiper.xml");
protected static final String ROLE_WEAK_GOSSIPER_OID = "e8fb2226-7f48-11e6-8cf1-630ce5c3f80b";
protected static final File ROLE_WEAK_SINGER_FILE = new File(TEST_DIR, "role-weak-singer.xml");
protected static final String ROLE_WEAK_SINGER_OID = "caa7daf2-dd68-11e6-a780-ef610c7c3a06";
protected static final File ROLE_IMMUTABLE_FILE = new File(TEST_DIR, "role-immutable.xml");
protected static final String ROLE_IMMUTABLE_OID = "e53baf94-aa99-11e6-962a-5362ec2dd7df";
private static final String ROLE_IMMUTABLE_DESCRIPTION = "Role that cannot be modified because there is a modification rule with enforcement action.";
protected static final File ROLE_IMMUTABLE_GLOBAL_FILE = new File(TEST_DIR, "role-immutable-global.xml");
protected static final String ROLE_IMMUTABLE_GLOBAL_OID = "e7ba8884-b2f6-11e6-a0b9-d3540dd687d6";
private static final String ROLE_IMMUTABLE_GLOBAL_DESCRIPTION = "Thou shalt not modify this role!";
private static final String ROLE_IMMUTABLE_GLOBAL_IDENTIFIER = "GIG001";
protected static final File ROLE_IMMUTABLE_DESCRIPTION_GLOBAL_FILE = new File(TEST_DIR, "role-immutable-description-global.xml");
protected static final String ROLE_IMMUTABLE_DESCRIPTION_GLOBAL_OID = "b7ea1c0c-31d6-445e-8949-9f8f4a665b3b";
private static final String ROLE_IMMUTABLE_DESCRIPTION_GLOBAL_DESCRIPTION = "Thou shalt not modify description of this role!";
private static final String ROLE_IMMUTABLE_DESCRIPTION_GLOBAL_IDENTIFIER = "GIG001D";
protected static final File ROLE_NON_ASSIGNABLE_FILE = new File(TEST_DIR, "role-non-assignable.xml");
protected static final String ROLE_NON_ASSIGNABLE_OID = "db67d2f0-abd8-11e6-9c30-b35abe3e4e3a";
protected static final File ROLE_SCREAMING_FILE = new File(TEST_DIR, "role-screaming.xml");
protected static final String ROLE_SCREAMING_OID = "024e204d-ce40-4fe9-ae5a-0da3cbce989a";
protected static final File ROLE_NON_CREATEABLE_FILE = new File(TEST_DIR, "role-non-createable.xml");
protected static final String ROLE_NON_CREATEABLE_OID = "c45a25ce-b2e8-11e6-923e-938d2c54d334";
protected static final File ROLE_IMMUTABLE_ASSIGN_FILE = new File(TEST_DIR, "role-immutable-assign.xml");
protected static final String ROLE_IMMUTABLE_ASSIGN_OID = "a6b10a7c-b57e-11e6-bcb3-1ba47cb07e2e";
protected static final File ROLE_META_UNTOUCHABLE_FILE = new File(TEST_DIR, "role-meta-untouchable.xml");
protected static final String ROLE_META_UNTOUCHABLE_OID = "a80c9572-b57d-11e6-80a9-6fdae1dc39bc";
protected static final File ROLE_META_FOOL_FILE = new File(TEST_DIR, "role-meta-fool.xml");
protected static final String ROLE_META_FOOL_OID = "2edc5fe4-af3c-11e6-a81e-eb332578ec4f";
protected static final File ROLE_BLOODY_FOOL_FILE = new File(TEST_DIR, "role-bloody-fool.xml");
protected static final String ROLE_BLOODY_FOOL_OID = "0a0ac150-af3d-11e6-9901-67fbcbd5bb25";
protected static final File ORG_PROJECT_RECLAIM_BLACK_PEARL_FILE = new File(TEST_DIR, "org-project-reclaim-black-pearl.xml");
protected static final String ORG_PROJECT_RECLAIM_BLACK_PEARL_OID = "00000000-8888-6666-0000-200000005000";
private static final String USER_LEMONHEAD_NAME = "lemonhead";
private static final String USER_LEMONHEAD_FULLNAME = "Cannibal Lemonhead";
private static final String USER_SHARPTOOTH_NAME = "sharptooth";
private static final String USER_SHARPTOOTH_FULLNAME = "Cannibal Sharptooth";
private static final String USER_REDSKULL_NAME = "redskull";
private static final String USER_REDSKULL_FULLNAME = "Cannibal Redskull";
private static final String USER_BIGNOSE_NAME = "bignose";
private static final String USER_BIGNOSE_FULLNAME = "Bignose the Noncannibal";
private static final String GROUP_FOOLS_NAME = "fools";
private static final String GROUP_SIMPLETONS_NAME = "simpletons";
/**
* Undefined relation. It is not standard relation not a relation that is in any way configured.
*/
private static final QName RELATION_COMPLICATED_QNAME = new QName("http://exmple.com/relation", "complicated");
private String userLemonheadOid;
private String userSharptoothOid;
private String userRedskullOid;
private String userBignoseOid;
private final String EXISTING_GOSSIP = "Black spot!";
protected File getRoleGovernorFile() {
return ROLE_GOVERNOR_FILE;
}
protected File getRoleCannibalFile() {
return ROLE_CANNIBAL_FILE;
}
@Override
public void initSystem(Task initTask, OperationResult initResult)
throws Exception {
super.initSystem(initTask, initResult);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
repoAddObjectFromFile(ROLE_ADRIATIC_PIRATE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_BLACK_SEA_PIRATE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_INDIAN_OCEAN_PIRATE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_HONORABILITY_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_CLERIC_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_WANNABE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_HONORABLE_WANNABE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(getRoleGovernorFile(), RoleType.class, initResult);
repoAddObjectFromFile(getRoleCannibalFile(), RoleType.class, initResult);
repoAddObjectFromFile(ROLE_PROJECT_OMNINAMAGER_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_WEAK_GOSSIPER_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_WEAK_SINGER_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_IMMUTABLE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_NON_ASSIGNABLE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_SCREAMING_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_META_UNTOUCHABLE_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_META_FOOL_FILE, RoleType.class, initResult);
repoAddObjectFromFile(ROLE_BLOODY_FOOL_FILE, RoleType.class, initResult);
repoAddObjectFromFile(USER_RAPP_FILE, initResult);
dummyResourceCtl.addGroup(GROUP_FOOLS_NAME);
dummyResourceCtl.addGroup(GROUP_SIMPLETONS_NAME);
}
@Test
public void test000SanityRolePirate() throws Exception {
final String TEST_NAME = "test000SanityRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
PrismObject<RoleType> rolePirate = modelService.getObject(RoleType.class, ROLE_PIRATE_OID, null, task, result);
// THEN
display("Role pirate", rolePirate);
IntegrationTestTools.displayXml("Role pirate", rolePirate);
assertNotNull("No pirate", rolePirate);
PrismAsserts.assertEquivalent(ROLE_PIRATE_FILE, rolePirate);
}
@Test
public void test001SanityRoleProjectOmnimanager() throws Exception {
final String TEST_NAME = "test001SanityRoleProjectOmnimanager";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
PrismObject<RoleType> roleOmnimanager = modelService.getObject(RoleType.class, ROLE_PROJECT_OMNINAMAGER_OID, null, task, result);
// THEN
display("Role omnimanager", roleOmnimanager);
IntegrationTestTools.displayXml("Role omnimanager", roleOmnimanager);
assertNotNull("No omnimanager", roleOmnimanager);
ObjectReferenceType targetRef = roleOmnimanager.asObjectable().getInducement().get(0).getTargetRef();
assertEquals("Wrong targetRef resolutionTime", EvaluationTimeType.RUN, targetRef.getResolutionTime());
assertNull("targetRef is resolved", targetRef.getOid());
}
@Test
public void test010SearchReuqestableRoles() throws Exception {
final String TEST_NAME = "test010SearchReuqestableRoles";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
ObjectQuery query = QueryBuilder.queryFor(RoleType.class, prismContext)
.item(RoleType.F_REQUESTABLE).eq(true)
.build();
// WHEN
List<PrismObject<RoleType>> requestableRoles = modelService.searchObjects(RoleType.class, query, null, task, result);
// THEN
display("Requestable roles", requestableRoles);
assertEquals("Unexpected number of requestable roles", 3, requestableRoles.size());
}
@Test
public void test101JackAssignRolePirate() throws Exception {
final String TEST_NAME = "test101JackAssignRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertModifyMetadata(userAfter, startTs, endTs);
AssignmentType assignmentType = assertAssignedRole(userAfter, ROLE_PIRATE_OID, task, result);
assertCreateMetadata(assignmentType, startTs, endTs);
assertEffectiveActivation(assignmentType, ActivationStatusType.ENABLED);
assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Caribbean");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Caribbean has ever seen");
}
/**
* We modify Jack's "locality". As this is assigned by expression in the role to the dummy account, the account should
* be updated as well.
*/
@Test
public void test102JackModifyUserLocality() throws Exception {
final String TEST_NAME = "test102JackModifyUserLocality";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// gossip is a tolerant attribute. Make sure there there is something to tolerate
DummyAccount jackDummyAccount = getDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME);
jackDummyAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
EXISTING_GOSSIP);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
modifyUserReplace(USER_JACK_OID, UserType.F_LOCALITY, task, result, PrismTestUtil.createPolyString("Tortuga"));
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
AssignmentType assignmentType = assertAssignedRole(userAfter, ROLE_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test110UnAssignRolePirate() throws Exception {
final String TEST_NAME = "test110UnAssignRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedNoRole(userAfter, task, result);
assertRoleMembershipRef(userAfter);
assertDelegatedRef(userAfter);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
@Test
public void test120JackAssignRolePirateWhileAlreadyHasAccount() throws Exception {
final String TEST_NAME = "test120JackAssignRolePirateWhileAlreadyHasAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
// Make sure that the account has explicit intent
account.asObjectable().setIntent(SchemaConstants.INTENT_DEFAULT);
// Make sure that the existing account has the same value as is set by the role
// This causes problems if the resource does not tolerate duplicate values in deltas. But provisioning
// should work around that.
TestUtil.setAttribute(account,
getDummyResourceController().getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME),
DOMUtil.XSD_STRING, prismContext, "Bloody Pirate");
ObjectDelta<UserType> delta = ObjectDelta.createModificationAddReference(UserType.class, USER_JACK_OID,
UserType.F_LINK_REF, prismContext, account);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
// We need to switch off the encorcement for this opertation. Otherwise we won't be able to create the account
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
modelService.executeChanges(deltas, null, task, result);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// Precondition (simplified)
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "rum");
// gossip is a tolerant attribute. Make sure there there is something to tolerate
DummyAccount jackDummyAccount = getDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME);
jackDummyAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
EXISTING_GOSSIP);
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 1);
assertLinks(userJack, 1);
assertAssignedRole(userJack, ROLE_PIRATE_OID);
assertRoleMembershipRef(userJack, ROLE_PIRATE_OID);
assertDelegatedRef(userJack);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// The account already has a value for 'weapon', it should be unchanged.
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "rum");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test121JackAssignAccountImplicitIntent() throws Exception {
final String TEST_NAME = "test121JackAssignAccountImplicitIntent";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// Precondition (simplified)
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
// 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", userJack);
assertAssignments(userJack, 2);
assertLinks(userJack, 1);
assertAssignedRole(userJack, ROLE_PIRATE_OID);
assertRoleMembershipRef(userJack, ROLE_PIRATE_OID);
assertDelegatedRef(userJack);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test122JackAssignAccountExplicitIntent() throws Exception {
final String TEST_NAME = "test122JackAssignAccountExplicitIntent";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// Precondition (simplified)
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
// WHEN
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, SchemaConstants.INTENT_DEFAULT, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 3);
assertLinks(userJack, 1);
assertAssignedRole(userJack, ROLE_PIRATE_OID);
assertRoleMembershipRef(userJack, ROLE_PIRATE_OID);
assertDelegatedRef(userJack);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test127UnAssignAccountImplicitIntent() throws Exception {
final String TEST_NAME = "test127UnAssignAccountImplicitIntent";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignAccount(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", userJack);
assertAssignments(userJack, 2);
assertLinks(userJack, 1);
assertAssignedRole(userJack, ROLE_PIRATE_OID);
assertRoleMembershipRef(userJack, ROLE_PIRATE_OID);
assertDelegatedRef(userJack);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test128UnAssignAccountExplicitIntent() throws Exception {
final String TEST_NAME = "test128UnAssignAccountExplicitIntent";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, SchemaConstants.INTENT_DEFAULT, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 1);
assertLinks(userJack, 1);
assertAssignedRole(userJack, ROLE_PIRATE_OID);
assertRoleMembershipRef(userJack, ROLE_PIRATE_OID);
assertDelegatedRef(userJack);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen", EXISTING_GOSSIP);
}
@Test
public void test129UnAssignRolePirate() throws Exception {
final String TEST_NAME = "test129UnAssignRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignRole(USER_JACK_OID, ROLE_PIRATE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
@Test
public void test130JackAssignRolePirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test130JackAssignRolePirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
assignRole(USER_JACK_OID, ROLE_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME,
"jack sailed Caribbean, immediately Caribbean, role , with this The Seven Seas while focused on Caribbean (in Pirate)");
}
@Test
public void test132JackUnAssignRolePirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test132JackUnAssignRolePirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
unassignRole(USER_JACK_OID, ROLE_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
/**
* The value for sea is set in Adriatic Pirate role extension.
*/
@Test
public void test134JackAssignRoleAdriaticPirate() throws Exception {
final String TEST_NAME = "test134JackAssignRoleAdriaticPirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
assignRole(USER_JACK_OID, ROLE_ADRIATIC_PIRATE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_ADRIATIC_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_ADRIATIC_PIRATE_OID, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME,
"jack sailed Adriatic, immediately Adriatic, role , with this The Seven Seas while focused on (in Pirate)");
}
/**
* Check if all the roles are visible in preview changes
*/
@Test
public void test135PreviewChangesEmptyDelta() throws Exception {
final String TEST_NAME = "test135PreviewChangesEmptyDelta";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> user = getUser(USER_JACK_OID);
ObjectDelta<UserType> delta = user.createModifyDelta();
// WHEN
ModelContext<ObjectType> modelContext = modelInteractionService.previewChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
DeltaSetTriple<? extends EvaluatedAssignment> evaluatedAssignmentTriple = modelContext.getEvaluatedAssignmentTriple();
PrismAsserts.assertTripleNoPlus(evaluatedAssignmentTriple);
PrismAsserts.assertTripleNoMinus(evaluatedAssignmentTriple);
Collection<? extends EvaluatedAssignment> evaluatedAssignments = evaluatedAssignmentTriple.getZeroSet();
assertEquals("Wrong number of evaluated assignments", 1, evaluatedAssignments.size());
EvaluatedAssignment<UserType> evaluatedAssignment = evaluatedAssignments.iterator().next();
DeltaSetTriple<? extends EvaluatedAssignmentTarget> rolesTriple = evaluatedAssignment.getRoles();
PrismAsserts.assertTripleNoPlus(rolesTriple);
PrismAsserts.assertTripleNoMinus(rolesTriple);
Collection<? extends EvaluatedAssignmentTarget> evaluatedRoles = rolesTriple.getZeroSet();
assertEquals("Wrong number of evaluated role", 2, evaluatedRoles.size());
assertEvaluatedRole(evaluatedRoles, ROLE_ADRIATIC_PIRATE_OID);
assertEvaluatedRole(evaluatedRoles, ROLE_PIRATE_OID);
}
@Test
public void test136JackUnAssignRoleAdriaticPirate() throws Exception {
final String TEST_NAME = "test136JackUnAssignRoleAdriaticPirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignRole(USER_JACK_OID, ROLE_ADRIATIC_PIRATE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
/**
* Even though we assign Adriatic Pirate role which has a sea set in its extension the
* sea set in user's extension should override it.
*/
@Test
public void test137JackAssignRoleAdriaticPirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test137JackAssignRoleAdriaticPirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
assignRole(USER_JACK_OID, ROLE_ADRIATIC_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_ADRIATIC_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_ADRIATIC_PIRATE_OID, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME,
"jack sailed Caribbean, immediately Adriatic, role , with this The Seven Seas while focused on Caribbean (in Pirate)");
}
@Test
public void test139JackUnAssignRoleAdriaticPirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test139JackUnAssignRoleAdriaticPirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
unassignRole(USER_JACK_OID, ROLE_ADRIATIC_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
@Test
public void test144JackAssignRoleBlackSeaPirate() throws Exception {
final String TEST_NAME = "test144JackAssignRoleBlackSeaPirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
assignRole(USER_JACK_OID, ROLE_BLACK_SEA_PIRATE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_BLACK_SEA_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_BLACK_SEA_PIRATE_OID, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME,
"jack sailed Marmara Sea, immediately Marmara Sea, role Black Sea, with this The Seven Seas while focused on (in Pirate)");
}
@Test
public void test146JackUnAssignRoleBlackSeaPirate() throws Exception {
final String TEST_NAME = "test146JackUnAssignRoleBlackSeaPirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
unassignRole(USER_JACK_OID, ROLE_BLACK_SEA_PIRATE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
@Test
public void test147JackAssignRoleBlackSeaPirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test147JackAssignRoleBlackSeaPirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
assignRole(USER_JACK_OID, ROLE_BLACK_SEA_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_BLACK_SEA_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_BLACK_SEA_PIRATE_OID, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "title", "Bloody Pirate");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "location", "Tortuga");
// Outbound mapping for weapon is weak, therefore the mapping in role should override it
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, "weapon", "cutlass");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME,
"Jack Sparrow is the best pirate Tortuga has ever seen");
assertDefaultDummyAccountAttribute(ACCOUNT_JACK_DUMMY_USERNAME, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME,
"jack sailed Caribbean, immediately Marmara Sea, role Black Sea, with this The Seven Seas while focused on Caribbean (in Pirate)");
}
@Test
public void test149JackUnAssignRoleBlackSeaPirateWithSeaInAssignment() throws Exception {
final String TEST_NAME = "test149JackUnAssignRoleBlackSeaPirateWithSeaInAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismContainer<?> extension = getAssignmentExtensionInstance();
PrismSchema piracySchema = getPiracySchema();
PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME);
PrismProperty<String> seaProp = seaPropDef.instantiate();
seaProp.setRealValue("Caribbean");
extension.add(seaProp);
// WHEN
unassignRole(USER_JACK_OID, ROLE_BLACK_SEA_PIRATE_OID, extension, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after", userJack);
assertAssignments(userJack, 0);
assertRoleMembershipRef(userJack);
assertDelegatedRef(userJack);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}
@Test
public void test154JackAssignRoleIndianOceanPirate() throws Exception {
final String TEST_NAME = "test154JackAssignRoleIndianOceanPirate";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignRole(USER_JACK_OID, ROLE_INDIAN_OCEAN_PIRATE_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("Result", result);
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
assertAssignedRole(userAfter, ROLE_INDIAN_OCEAN_PIRATE_OID, task, result);
assertRoleMembershipRef(userAfter, ROLE_INDIAN_OCEAN_PIRATE_OID, ROLE_PIRATE_OID);
assertDelegatedRef(userAfter);