Search in sources :

Example 1 with RoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType in project midpoint by Evolveum.

the class SampleFormFocusTabPanel method initLayout.

private void initLayout(final LoadableModel<ObjectWrapper<F>> focusModel, LoadableModel<List<AssignmentEditorDto>> assignmentsModel, PageBase pageBase) {
    add(new Label(ID_HEADER, "Object details"));
    WebMarkupContainer body = new WebMarkupContainer("body");
    add(body);
    addPrismPropertyPanel(body, ID_PROP_NAME, FocusType.F_NAME);
    addPrismPropertyPanel(body, ID_PROP_FULL_NAME, UserType.F_FULL_NAME);
    // TODO: create proxy for these operations
    Task task = pageBase.createSimpleTask(OPERATION_SEARCH_ROLES);
    List<PrismObject<RoleType>> availableRoles;
    try {
        availableRoles = pageBase.getModelService().searchObjects(RoleType.class, null, null, task, task.getResult());
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        task.getResult().recordFatalError(e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load roles", e);
        availableRoles = new ArrayList<>();
    // TODO: better errror reporting
    }
    add(new SimpleRoleSelector<F, RoleType>(ID_ROLES, assignmentsModel, availableRoles));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 2 with RoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType in project midpoint by Evolveum.

the class RolePolicyPanel method initLayout.

@Override
protected void initLayout() {
    minAssignmentModel = new LoadableModel<List<MultiplicityPolicyConstraintType>>(false) {

        @Override
        protected List<MultiplicityPolicyConstraintType> load() {
            RoleType roleType = role.asObjectable();
            if (roleType.getPolicyConstraints() == null) {
                roleType.setPolicyConstraints(new PolicyConstraintsType());
            }
            return roleType.getPolicyConstraints().getMinAssignees();
        }
    };
    maxAssignmentsModel = new LoadableModel<List<MultiplicityPolicyConstraintType>>(false) {

        @Override
        protected List<MultiplicityPolicyConstraintType> load() {
            RoleType roleType = role.asObjectable();
            if (roleType.getPolicyConstraints() == null) {
                roleType.setPolicyConstraints(new PolicyConstraintsType());
            }
            return roleType.getPolicyConstraints().getMaxAssignees();
        }
    };
    GenericMultiValueLabelEditPanel minAssignments = new GenericMultiValueLabelEditPanel<MultiplicityPolicyConstraintType>(ID_MIN_ASSIGNMENTS, minAssignmentModel, createStringResource("PageRoleEditor.label.minAssignments"), ID_LABEL_SIZE, ID_INPUT_SIZE, true) {

        @Override
        protected IModel<String> createTextModel(IModel<MultiplicityPolicyConstraintType> model) {
            return createMultiplicityPolicyLabel(model);
        }

        @Override
        protected void editValuePerformed(AjaxRequestTarget target, IModel<MultiplicityPolicyConstraintType> rowModel) {
            MultiplicityPolicyPanel window = new MultiplicityPolicyPanel(getPageBase().getMainPopupBodyId(), rowModel.getObject()) {

                @Override
                protected void savePerformed(AjaxRequestTarget target) {
                    closeModalWindow(target);
                    target.add(getMinAssignmentsContainer());
                }
            };
            showDialog(window, target);
        }

        @Override
        protected MultiplicityPolicyConstraintType createNewEmptyItem() {
            return new MultiplicityPolicyConstraintType();
        }
    };
    minAssignments.setOutputMarkupId(true);
    add(minAssignments);
    GenericMultiValueLabelEditPanel maxAssignments = new GenericMultiValueLabelEditPanel<MultiplicityPolicyConstraintType>(ID_MAX_ASSIGNMENTS, maxAssignmentsModel, createStringResource("PageRoleEditor.label.maxAssignments"), ID_LABEL_SIZE, ID_INPUT_SIZE, true) {

        @Override
        protected IModel<String> createTextModel(IModel<MultiplicityPolicyConstraintType> model) {
            return createMultiplicityPolicyLabel(model);
        }

        @Override
        protected void editValuePerformed(AjaxRequestTarget target, IModel<MultiplicityPolicyConstraintType> rowModel) {
            MultiplicityPolicyPanel window = new MultiplicityPolicyPanel(getPageBase().getMainPopupBodyId(), rowModel.getObject()) {

                @Override
                protected void savePerformed(AjaxRequestTarget target) {
                    closeModalWindow(target);
                    target.add(getMaxAssignmentsContainer());
                }
            };
            showDialog(window, target);
        }

        @Override
        protected MultiplicityPolicyConstraintType createNewEmptyItem() {
            return new MultiplicityPolicyConstraintType();
        }
    };
    maxAssignments.setOutputMarkupId(true);
    add(maxAssignments);
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) MultiplicityPolicyPanel(com.evolveum.midpoint.web.page.admin.roles.component.MultiplicityPolicyPanel) IModel(org.apache.wicket.model.IModel) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) GenericMultiValueLabelEditPanel(com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel) MultiplicityPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.MultiplicityPolicyConstraintType) List(java.util.List)

Example 3 with RoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType in project midpoint by Evolveum.

the class TestDeltaConverter method testModifyInducement.

@Test
public void testModifyInducement() throws Exception {
    System.out.println("===[ testModifyInducement ]====");
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "role-modify-inducement.xml"), ObjectModificationType.COMPLEX_TYPE);
    // WHEN
    ObjectDelta<RoleType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, RoleType.class, getPrismContext());
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    // THEN
    assertNotNull("No object delta", objectDelta);
    objectDelta.checkConsistence();
    assertEquals("Wrong OID", "00000000-8888-6666-0000-100000000005", objectDelta.getOid());
    ReferenceDelta targetRefDelta = objectDelta.findReferenceModification(new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(5L), new NameItemPathSegment(AssignmentType.F_TARGET_REF)));
    assertNotNull("No targetRef delta", targetRefDelta);
    Collection<PrismReferenceValue> valuesToAdd = targetRefDelta.getValuesToAdd();
    assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
    PrismReferenceValue targetRefVal = valuesToAdd.iterator().next();
    assertNotNull("Null value in targetRef delta", targetRefVal);
    assertEquals("wrong OID in targetRef", "12345678-d34d-b33f-f00d-987987987987", targetRefVal.getOid());
    assertEquals("wrong target type in targetRef", RoleType.COMPLEX_TYPE, targetRefVal.getTargetType());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 4 with RoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType in project midpoint by Evolveum.

the class TestAssignmentProcessor2 method test020AssignMR1ToR1.

@Test(enabled = FIRST_PART)
public void test020AssignMR1ToR1() throws Exception {
    final String TEST_NAME = "test020AssignMR1ToR1";
    displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentProcessor.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    LensContext<RoleType> context = createContextForAssignment(RoleType.class, ROLE_R1_OID, RoleType.class, ROLE_MR1_OID, null, null, result);
    // WHEN
    displayWhen(TEST_NAME);
    assignmentProcessor.processAssignmentsProjections(context, clock.currentTimeXMLGregorianCalendar(), task, result);
    // THEN
    displayThen(TEST_NAME);
    display("Output context", context);
    display("Evaluated assignment triple", context.getEvaluatedAssignmentTriple());
    assertSuccess(result);
    // assignment of construction R1-0
    // assignment of focus mappings R1-0
    // assignment of focus policy rules R1-0
    // assignment of metarole MR1 (this will be checked)
    Collection<EvaluatedAssignmentImpl<RoleType>> evaluatedAssignments = assertAssignmentTripleSetSize(context, 4, 0, 0);
    List<EvaluatedAssignmentImpl<RoleType>> targetedAssignments = evaluatedAssignments.stream().filter(ea -> ea.getTarget() != null).collect(Collectors.toList());
    assertEquals("Wrong # of targeted assignments", 1, targetedAssignments.size());
    EvaluatedAssignmentImpl<RoleType> evaluatedAssignment = targetedAssignments.get(0);
    assertEquals("Wrong evaluatedAssignment.isValid", true, evaluatedAssignment.isValid());
    // R4, R5, R6 could be optimized out
    assertTargets(evaluatedAssignment, true, "MR1 MR3 MR4", null, null, null, null, null);
    assertTargets(evaluatedAssignment, false, "MMR1 R5 R4 R6", null, null, null, null, null);
    assertMembershipRef(evaluatedAssignment, "MR1 MR3 MR4");
    assertOrgRef(evaluatedAssignment, "");
    assertDelegation(evaluatedAssignment, null);
    assertConstructions(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1", null, null, null, null, null);
    assertFocusMappings(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1");
    assertFocusPolicyRules(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1");
    assertTargetPolicyRules(evaluatedAssignment, "MR1-0 MMR1-1", "MR3-0 MR4-0");
    assertAuthorizations(evaluatedAssignment, "MR1 MR3 MR4");
    assertGuiConfig(evaluatedAssignment, "MR1 MR3 MR4");
}
Also used : ActivationUtil(com.evolveum.midpoint.schema.util.ActivationUtil) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) IntegrationTestTools.displayObjectTypeCollection(com.evolveum.midpoint.test.IntegrationTestTools.displayObjectTypeCollection) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) EvaluationOrder(com.evolveum.midpoint.model.api.context.EvaluationOrder) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) TestUtil.assertSuccess(com.evolveum.midpoint.test.util.TestUtil.assertSuccess) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) AssertJUnit.assertNull(org.testng.AssertJUnit.assertNull) TestUtil(com.evolveum.midpoint.test.util.TestUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ScriptExpressionEvaluationContext(com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluationContext) DeltaBuilder(com.evolveum.midpoint.prism.delta.builder.DeltaBuilder) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) AssertJUnit.fail(org.testng.AssertJUnit.fail) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) File(java.io.File) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) IntegrationTestTools.display(com.evolveum.midpoint.test.IntegrationTestTools.display) Stream(java.util.stream.Stream) TreeBag(org.apache.commons.collections4.bag.TreeBag) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) AssignmentProcessor(com.evolveum.midpoint.model.impl.lens.projector.AssignmentProcessor) Bag(org.apache.commons.collections4.Bag) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Clock(com.evolveum.midpoint.common.Clock) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 5 with RoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType in project midpoint by Evolveum.

the class PageRole method removeEmptyPolicyConstraints.

/**
	 * Removes empty policy constraints from role. It was created when loading
	 * model (not very good model implementation). MID-2366
	 *
	 * TODO improve
	 *
	 * @param prism
	 */
private void removeEmptyPolicyConstraints(PrismObject<RoleType> prism) {
    RoleType role = prism.asObjectable();
    PolicyConstraintsType pc = role.getPolicyConstraints();
    if (pc == null) {
        return;
    }
    if (pc.getExclusion().isEmpty() && pc.getMinAssignees().isEmpty() && pc.getMaxAssignees().isEmpty()) {
        role.setPolicyConstraints(null);
    }
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)

Aggregations

RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)67 Test (org.testng.annotations.Test)44 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)39 Task (com.evolveum.midpoint.task.api.Task)34 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)18 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)9 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)8 AbstractRoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 QName (javax.xml.namespace.QName)7 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)5 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)5 File (java.io.File)5 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4