use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ResourceContentTabPanel method initLayout.
private void initLayout(final IModel<PrismObject<ResourceType>> model, final PageBase parentPage) {
setOutputMarkupId(true);
final Form mainForm = new Form(ID_MAIN_FORM);
mainForm.setOutputMarkupId(true);
mainForm.addOrReplace(initTable(model));
add(mainForm);
AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT, new PropertyModel<String>(resourceContentSearch, "intent"), String.class) {
private static final long serialVersionUID = 1L;
@Override
public Iterator<String> getIterator(String input) {
RefinedResourceSchema refinedSchema = null;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(model.getObject(), parentPage.getPrismContext());
} catch (SchemaException e) {
return new ArrayList<String>().iterator();
}
return RefinedResourceSchemaImpl.getIntentsForKind(refinedSchema, getKind()).iterator();
}
};
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(model));
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 AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
RefinedObjectClassDefinition ocDef;
try {
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(model.getObject(), parentPage.getPrismContext());
if (refinedSchema == null) {
return "NO SCHEMA DEFINED";
}
ocDef = refinedSchema.getRefinedDefinition(getKind(), getIntent());
if (ocDef != null) {
return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
}
} catch (SchemaException e) {
}
return "NOT FOUND";
}
});
realObjectClassLabel.setOutputMarkupId(true);
add(realObjectClassLabel);
AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS, new PropertyModel<QName>(resourceContentSearch, "objectClass")) {
private static final long serialVersionUID = 1L;
@Override
public Collection<QName> loadChoices() {
return createObjectClassChoices(model);
}
@Override
protected void onChange(AjaxRequestTarget target) {
LOGGER.trace("Object class panel update: {}", isUseObjectClass());
updateResourceContentSearch();
mainForm.addOrReplace(initTable(model));
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<Boolean>(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(model));
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<Boolean>(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(model));
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.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class LensUtil method refineProjectionIntent.
public static String refineProjectionIntent(ShadowKindType kind, String intent, ResourceType resource, PrismContext prismContext) throws SchemaException {
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
RefinedObjectClassDefinition rObjClassDef = refinedSchema.getRefinedDefinition(kind, intent);
if (rObjClassDef == null) {
throw new SchemaException("No projection definition for kind=" + kind + " intent=" + intent + " in " + resource);
}
return rObjClassDef.getIntent();
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class LensUtil method needsFullShadowForCredentialProcessing.
public static boolean needsFullShadowForCredentialProcessing(LensProjectionContext projCtx) throws SchemaException {
RefinedObjectClassDefinition refinedProjDef = projCtx.getStructuralObjectClassDefinition();
if (refinedProjDef == null) {
return false;
}
List<MappingType> outboundMappingType = refinedProjDef.getPasswordOutbound();
if (outboundMappingType == null) {
return false;
}
for (MappingType mappingType : outboundMappingType) {
if (mappingType.getStrength() == MappingStrengthType.STRONG || mappingType.getStrength() == MappingStrengthType.WEAK) {
return true;
}
}
return false;
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class Construction method debugDump.
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabel(sb, "Construction", indent);
if (refinedObjectClassDefinition == null) {
sb.append(" (no object class definition)");
if (getConstructionType() != null && getConstructionType().getResourceRef() != null) {
// should
// be
// always
// the
// case
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "resourceRef / kind / intent", indent + 1);
sb.append(" ");
sb.append(ObjectTypeUtil.toShortString(getConstructionType().getResourceRef()));
sb.append(" / ");
sb.append(getConstructionType().getKind());
sb.append(" / ");
sb.append(getConstructionType().getIntent());
}
} else {
sb.append(refinedObjectClassDefinition.getShadowDiscriminator());
}
if (getConstructionType() != null && getConstructionType().getStrength() == ConstructionStrengthType.WEAK) {
sb.append(" weak");
}
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "isValid", isValid(), indent + 1);
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "auxiliary object classes", indent + 1);
if (auxiliaryObjectClassDefinitions == null) {
sb.append(" (null)");
} else if (auxiliaryObjectClassDefinitions.isEmpty()) {
sb.append(" (empty)");
} else {
for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, indent + 2);
sb.append(auxiliaryObjectClassDefinition.getTypeName());
}
}
if (getConstructionType() != null && getConstructionType().getDescription() != null) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "description", indent + 1);
sb.append(" ").append(getConstructionType().getDescription());
}
if (attributeMappings != null && !attributeMappings.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "attribute mappings", indent + 1);
for (Mapping mapping : attributeMappings) {
sb.append("\n");
sb.append(mapping.debugDump(indent + 2));
}
}
if (associationMappings != null && !associationMappings.isEmpty()) {
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "association mappings", indent + 1);
for (Mapping mapping : associationMappings) {
sb.append("\n");
sb.append(mapping.debugDump(indent + 2));
}
}
if (getAssignmentPath() != null) {
sb.append("\n");
sb.append(getAssignmentPath().debugDump(indent + 1));
}
return sb.toString();
}
use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.
the class ProjectionCredentialsProcessor method processProjectionPasswordMapping.
private <F extends FocusType> void processProjectionPasswordMapping(LensContext<F> context, final LensProjectionContext projCtx, final ValuePolicyType passwordPolicy, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
PrismObject<F> userNew = focusContext.getObjectNew();
if (userNew == null) {
// This must be a user delete or something similar. No point in proceeding
LOGGER.trace("userNew is null, skipping credentials processing");
return;
}
PrismObjectDefinition<ShadowType> accountDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
PrismPropertyDefinition<ProtectedStringType> projPasswordPropertyDefinition = accountDefinition.findPropertyDefinition(SchemaConstants.PATH_PASSWORD_VALUE);
ResourceShadowDiscriminator rsd = projCtx.getResourceShadowDiscriminator();
RefinedObjectClassDefinition refinedProjDef = projCtx.getStructuralObjectClassDefinition();
if (refinedProjDef == null) {
LOGGER.trace("No RefinedObjectClassDefinition, therefore also no password outbound definition, skipping credentials processing for projection {}", rsd);
return;
}
List<MappingType> outboundMappingTypes = refinedProjDef.getPasswordOutbound();
if (outboundMappingTypes == null || outboundMappingTypes.isEmpty()) {
LOGGER.trace("No outbound password mapping for {}, skipping credentials processing", rsd);
return;
}
// HACK
if (!projCtx.isDoReconciliation() && !projCtx.isAdd() && !isActivated(outboundMappingTypes, focusContext.getDelta())) {
LOGGER.trace("Outbound password mappings not activated for type {}, skipping credentials processing", rsd);
return;
}
final ObjectDelta<ShadowType> projDelta = projCtx.getDelta();
final PropertyDelta<ProtectedStringType> projPasswordDelta;
if (projDelta != null && projDelta.getChangeType() == MODIFY) {
projPasswordDelta = projDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
} else {
projPasswordDelta = null;
}
checkExistingDeltaSanity(projCtx, projPasswordDelta);
boolean evaluateWeak = getEvaluateWeak(projCtx);
final ItemDeltaItem<PrismPropertyValue<PasswordType>, PrismPropertyDefinition<ProtectedStringType>> userPasswordIdi = focusContext.getObjectDeltaObject().findIdi(SchemaConstants.PATH_PASSWORD_VALUE);
StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {
@Override
public void setOutputPath(ItemPath outputPath) {
}
@Override
public void setOutputDefinition(ItemDefinition outputDefinition) {
}
@Override
public StringPolicyType resolve() {
if (passwordPolicy == null) {
return null;
}
return passwordPolicy.getStringPolicy();
}
};
MappingInitializer<PrismPropertyValue<ProtectedStringType>, PrismPropertyDefinition<ProtectedStringType>> initializer = (builder) -> {
builder.defaultTargetDefinition(projPasswordPropertyDefinition);
builder.defaultSource(new Source<>(userPasswordIdi, ExpressionConstants.VAR_INPUT));
builder.stringPolicyResolver(stringPolicyResolver);
return builder;
};
MappingOutputProcessor<PrismPropertyValue<ProtectedStringType>> processor = (mappingOutputPath, outputStruct) -> {
PrismValueDeltaSetTriple<PrismPropertyValue<ProtectedStringType>> outputTriple = outputStruct.getOutputTriple();
if (outputTriple == null) {
LOGGER.trace("Credentials 'password' expression resulted in null output triple, skipping credentials processing for {}", rsd);
return false;
}
boolean projectionIsNew = projDelta != null && (projDelta.getChangeType() == ChangeType.ADD || projCtx.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.ADD);
Collection<PrismPropertyValue<ProtectedStringType>> newValues = outputTriple.getPlusSet();
if (projectionIsNew) {
newValues = outputTriple.getNonNegativeValues();
} else {
newValues = outputTriple.getPlusSet();
}
if (!canGetCleartext(newValues)) {
ObjectDelta<ShadowType> projectionPrimaryDelta = projCtx.getPrimaryDelta();
if (projectionPrimaryDelta != null) {
PropertyDelta<ProtectedStringType> passwordPrimaryDelta = projectionPrimaryDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
if (passwordPrimaryDelta != null) {
// We have only hashed value coming from the mapping. There are not very useful
// for provisioning. But we have primary projection delta - and that is very likely
// to be better.
// Skip all password mappings in this case. Primary delta trumps everything.
// No weak, normal or even strong mapping can change that.
// We need to disregard even strong mapping in this case. If we would heed the strong
// mapping then account initialization won't be possible.
LOGGER.trace("We have primary password delta in projection, skipping credentials processing");
return false;
}
}
}
return true;
};
mappingEvaluator.evaluateOutboundMapping(context, projCtx, outboundMappingTypes, SchemaConstants.PATH_PASSWORD_VALUE, SchemaConstants.PATH_PASSWORD_VALUE, initializer, processor, now, true, evaluateWeak, "password mapping", task, result);
}
Aggregations