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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations