Search in sources :

Example 31 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method loadRefinedAssociationDefinitions.

private Collection<ResourceAssociationDefinition> loadRefinedAssociationDefinitions(PrismObject<ResourceType> resource, ShadowType shadow, OperationResult parentResult) {
    OperationResult result = parentResult.createMinorSubresult(CREATE_ASSOCIATION_WRAPPER);
    ResourceSchema refinedResourceSchema;
    try {
        refinedResourceSchema = ResourceSchemaFactory.getCompleteSchema(resource);
    } catch (SchemaException e) {
        LOGGER.error("Cannot get refined schema for {}, {}", resource, e.getMessage(), e);
        result.recordPartialError("Could not get fined schema for " + resource, e);
        return null;
    }
    ShadowKindType kind = shadow.getKind();
    String shadowIntent = shadow.getIntent();
    ResourceObjectDefinition oc = refinedResourceSchema.findObjectDefinition(kind, shadowIntent);
    if (oc == null) {
        LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
        return null;
    }
    Collection<ResourceAssociationDefinition> resourceAssociationDefinitions = oc.getAssociationDefinitions();
    if (CollectionUtils.isEmpty(resourceAssociationDefinitions)) {
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
        LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
        return null;
    }
    result.computeStatusIfUnknown();
    return resourceAssociationDefinitions;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 32 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ResourceContentTabPanel method initLayout.

protected void initLayout() {
    setOutputMarkupId(true);
    final Form mainForm = new MidpointForm(ID_MAIN_FORM);
    mainForm.setOutputMarkupId(true);
    mainForm.addOrReplace(initTable(getObjectWrapperModel()));
    add(mainForm);
    AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT, new PropertyModel<>(resourceContentSearch, "intent"), String.class, false, null) {

        private static final long serialVersionUID = 1L;

        @Override
        public Iterator<String> getIterator(String input) {
            ResourceSchema refinedSchema;
            try {
                refinedSchema = ResourceSchemaFactory.getCompleteSchema(getObjectWrapper().getObject());
                if (refinedSchema != null) {
                    return refinedSchema.getIntentsForKind(getKind()).iterator();
                } else {
                    return Collections.emptyIterator();
                }
            } catch (SchemaException e) {
                return Collections.emptyIterator();
            }
        }
    };
    intent.getBaseFormComponent().add(WebComponentUtil.preventSubmitOnEnterKeyDownBehavior());
    intent.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_REAL_OBJECT_CLASS));
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(getObjectWrapperModel()));
            target.add(mainForm);
        }
    });
    intent.setOutputMarkupId(true);
    intent.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isUseObjectClass();
        }
    });
    add(intent);
    Label realObjectClassLabel = new Label(ID_REAL_OBJECT_CLASS, new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            ResourceObjectDefinition ocDef;
            try {
                ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(getObjectWrapper().getObject());
                if (refinedSchema == null) {
                    return "NO SCHEMA DEFINED";
                }
                ocDef = refinedSchema.findObjectDefinition(getKind(), getIntent());
                if (ocDef != null) {
                    return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
                }
            } catch (SchemaException e) {
            // TODO?
            }
            return "NOT FOUND";
        }
    });
    realObjectClassLabel.setOutputMarkupId(true);
    add(realObjectClassLabel);
    AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS, new PropertyModel<>(resourceContentSearch, "objectClass")) {

        private static final long serialVersionUID = 1L;

        @Override
        public Collection<QName> loadChoices() {
            return createObjectClassChoices(getObjectWrapperModel());
        }

        @Override
        protected void onChange(AjaxRequestTarget target) {
            LOGGER.trace("Object class panel update: {}", isUseObjectClass());
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(getObjectWrapperModel()));
            target.add(mainForm);
        }
    };
    objectClassPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isUseObjectClass();
        }
    });
    add(objectClassPanel);
    AjaxLink<Boolean> repoSearch = new AjaxLink<Boolean>(ID_REPO_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = true;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.FALSE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.FALSE);
            resourceContentSearch.getObject().setResourceSearch(Boolean.FALSE);
            updateResourceContentSearch();
            mainForm.addOrReplace(initRepoContent(ResourceContentTabPanel.this.getObjectWrapperModel()));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this);
            target.add(getParent().get(ID_RESOURCE_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            if (!getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(repoSearch);
    AjaxLink<Boolean> resourceSearch = new AjaxLink<Boolean>(ID_RESOURCE_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = false;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.TRUE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.TRUE);
            updateResourceContentSearch();
            resourceContentSearch.getObject().setResourceSearch(Boolean.TRUE);
            mainForm.addOrReplace(initResourceContent(ResourceContentTabPanel.this.getObjectWrapperModel()));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this.add(AttributeModifier.append("class", " active")));
            target.add(getParent().get(ID_REPO_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            getModelObject().booleanValue();
            if (getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(resourceSearch);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) QName(javax.xml.namespace.QName) Label(org.apache.wicket.markup.html.basic.Label) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 33 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class SynchronizationUtils method isPolicyApplicable.

/**
 * Checks if the synchronization policy matches given "parameters" (object class, kind, intent).
 */
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, @NotNull ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource, boolean strictIntent) throws SchemaException {
    if (objectClassDefinedAndNotMatching(objectClass, synchronizationPolicy.getObjectClass())) {
        return false;
    }
    ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
    Objects.requireNonNull(schema, "No schema defined in resource. Possible configuration problem?");
    ShadowKindType policyKind = requireNonNullElse(synchronizationPolicy.getKind(), ACCOUNT);
    String policyIntent = synchronizationPolicy.getIntent();
    ResourceObjectDefinition policyObjectClass;
    if (StringUtils.isEmpty(policyIntent)) {
        // TODO check this
        policyObjectClass = schema.findObjectDefinition(policyKind, null);
        if (policyObjectClass instanceof ResourceObjectTypeDefinition) {
            policyIntent = ((ResourceObjectTypeDefinition) policyObjectClass).getIntent();
        }
    } else {
        policyObjectClass = schema.findObjectDefinition(policyKind, policyIntent);
    }
    if (policyObjectClass == null) {
        return false;
    }
    // re-check objectClass if wasn't defined
    if (objectClassDefinedAndNotMatching(objectClass, List.of(policyObjectClass.getTypeName()))) {
        return false;
    }
    // kind
    LOGGER.trace("Comparing kinds, policy kind: {}, current kind: {}", policyKind, kind);
    if (kind != null && kind != UNKNOWN && !policyKind.equals(kind)) {
        LOGGER.trace("Kinds don't match, skipping policy {}", synchronizationPolicy);
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    LOGGER.trace("Comparing intents, policy intent: {}, current intent: {}", policyIntent, intent);
    if (!strictIntent) {
        if (intent != null && !SchemaConstants.INTENT_UNKNOWN.equals(intent) && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
            LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
            return false;
        }
    } else {
        if (!MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
            LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
            return false;
        }
    }
    return true;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 34 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ChangePasswordPanel method createPasswordAccountDto.

private PasswordAccountDto createPasswordAccountDto(MyPasswordsDto passwordDto, PrismObject<ShadowType> account, Task task, OperationResult result) {
    PrismReference resourceRef = account.findReference(ShadowType.F_RESOURCE_REF);
    String resourceName;
    if (resourceRef == null || resourceRef.getValue() == null || resourceRef.getValue().getObject() == null) {
        resourceName = getString("PageSelfCredentials.couldntResolve");
    } else {
        resourceName = WebComponentUtil.getName(resourceRef.getValue().getObject());
    }
    PasswordAccountDto passwordAccountDto = new PasswordAccountDto(account, resourceName, resourceRef.getOid());
    ShadowType shadowType = account.asObjectable();
    ResourceType resource = (ResourceType) shadowType.getResourceRef().asReferenceValue().getObject().asObjectable();
    if (resource != null) {
        ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource.asPrismObject(), shadowType.getKind(), shadowType.getIntent());
        passwordAccountDto.setPasswordCapabilityEnabled(ResourceTypeUtil.isPasswordCapabilityEnabled(resource, resourceObjectTypeDefinitionType));
        passwordAccountDto.setMaintenanceState(ResourceTypeUtil.isInMaintenance(resource));
        try {
            ResourceObjectDefinition rOCDef = getPageBase().getModelInteractionService().getEditObjectClassDefinition(account, resource.asPrismObject(), AuthorizationPhaseType.REQUEST, task, result);
            if (rOCDef != null) {
                passwordAccountDto.setPasswordOutbound(getPasswordOutbound(account, resource, rOCDef));
                CredentialsPolicyType credentialsPolicy = getPasswordCredentialsPolicy(rOCDef);
                if (credentialsPolicy != null && credentialsPolicy.getPassword() != null && credentialsPolicy.getPassword().getValuePolicyRef() != null) {
                    PrismObject<ValuePolicyType> valuePolicy = WebModelServiceUtils.resolveReferenceNoFetch(credentialsPolicy.getPassword().getValuePolicyRef(), getPageBase(), task, task.getResult());
                    if (valuePolicy != null) {
                        passwordAccountDto.setPasswordValuePolicyOid(valuePolicy.getOid());
                        passwordDto.addPasswordPolicy(valuePolicy.asObjectable());
                    }
                }
            } else {
                passwordAccountDto.setPasswordOutbound(false);
            }
        } catch (Exception e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Fail to get ResourceObjectTypeDefinition for {} ", e, account);
            result.recordFatalError("Fail to get ResourceObjectTypeDefinition for " + account, e);
            getPageBase().showResult(result);
            passwordAccountDto.setPasswordOutbound(false);
        }
    } else {
        passwordAccountDto.setPasswordCapabilityEnabled(false);
        passwordAccountDto.setPasswordOutbound(false);
    }
    return passwordAccountDto;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) PrismReference(com.evolveum.midpoint.prism.PrismReference) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)

Example 35 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ResourceAttributeRefPanelFactory method getChoicesList.

private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
    PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
    // attribute/ref
    if (wrapper == null) {
        return Collections.emptyList();
    }
    // attribute value
    if (wrapper.getParent() == null) {
        return Collections.emptyList();
    }
    // attribute
    ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
    if (attributeWrapper == null) {
        return Collections.emptyList();
    }
    PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
    if (itemWrapper == null) {
        return Collections.emptyList();
    }
    if (!(itemWrapper instanceof ConstructionValueWrapper)) {
        return Collections.emptyList();
    }
    ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
    try {
        ResourceSchema schema = constructionWrapper.getRefinedSchema();
        if (schema == null) {
            return new ArrayList<>();
        }
        ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
        if (rOcd == null) {
            return Collections.emptyList();
        }
        if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
            Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
            return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
        }
        Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
        return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
    } catch (SchemaException e) {
        LOGGER.warn("Cannot get resource attribute definitions");
    }
    return Collections.emptyList();
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ArrayList(java.util.ArrayList) PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) IModel(org.apache.wicket.model.IModel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Serializable(java.io.Serializable) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) List(java.util.List) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) PostConstruct(javax.annotation.PostConstruct) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2