use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class EntitlementConverter method determineBaseContextIdentification.
// ctx is type-based
@Nullable
private ResourceObjectIdentification determineBaseContextIdentification(ResourceObjectReferenceType baseContextRef, ProvisioningContext ctx, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (baseContextRef == null) {
return null;
}
ResourceObjectTypeDefinition objectTypeDef = ctx.getObjectTypeDefinitionRequired();
PrismObject<ShadowType> baseContextShadow;
try {
// We request the use of raw object class definition to avoid endless loops during base context determination.
baseContextShadow = resourceObjectReferenceResolver.resolve(ctx, baseContextRef, true, "base context specification in " + objectTypeDef, result);
} catch (RuntimeException e) {
throw new SystemException("Cannot resolve base context for " + objectTypeDef + ", specified as " + baseContextRef, e);
}
if (baseContextShadow == null) {
throw new ObjectNotFoundException("Base context not found for " + objectTypeDef + ", specified as " + baseContextRef);
}
ResourceObjectDefinition baseContextObjectDefinition = java.util.Objects.requireNonNull(ResourceObjectDefinitionResolver.getDefinitionForShadow(ctx.getResourceSchema(), baseContextShadow), () -> "Couldn't determine definition for " + baseContextRef);
return ShadowUtil.getResourceObjectIdentification(baseContextShadow, baseContextObjectDefinition);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class TestOpenDj method test007RefinedSchema.
@Test
public void test007RefinedSchema() throws Exception {
// GIVEN
// WHEN
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceBean);
displayDumpable("Refined schema", refinedSchema);
// Check whether it is reusing the existing schema and not parsing it
// all over again
// Not equals() but == ... we want to really know if exactly the same
// object instance is returned
assertSame("Broken caching", refinedSchema, ResourceSchemaFactory.getCompleteSchema(resourceBean));
ResourceObjectTypeDefinition accountDef = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
assertNotNull("Account definition is missing", accountDef);
assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in account", accountDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in account", accountDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getObjectClassDefinition().getNativeObjectClass()));
ResourceAttributeDefinition<?> idPrimaryDef = accountDef.findAttributeDefinition(getPrimaryIdentifierQName());
assertEquals(1, idPrimaryDef.getMaxOccurs());
assertEquals(0, idPrimaryDef.getMinOccurs());
assertFalse("UID has create", idPrimaryDef.canAdd());
assertFalse("UID has update", idPrimaryDef.canModify());
assertTrue("No UID read", idPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(idPrimaryDef));
assertEquals("Wrong " + OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME + " frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, idPrimaryDef.getFrameworkAttributeName());
ResourceAttributeDefinition<?> idSecondaryDef = accountDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, idSecondaryDef.getMaxOccurs());
assertEquals(1, idSecondaryDef.getMinOccurs());
assertTrue("No NAME create", idSecondaryDef.canAdd());
assertTrue("No NAME update", idSecondaryDef.canModify());
assertTrue("No NAME read", idSecondaryDef.canRead());
assertTrue("NAME definition not in identifiers", accountDef.getSecondaryIdentifiers().contains(idSecondaryDef));
assertEquals("Wrong NAME matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, idSecondaryDef.getMatchingRuleQName());
assertEquals("Wrong " + OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME + " frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, idSecondaryDef.getFrameworkAttributeName());
ResourceAttributeDefinition<?> cnDef = accountDef.findAttributeDefinition("cn");
assertNotNull("No definition for cn", cnDef);
assertEquals(-1, cnDef.getMaxOccurs());
assertEquals(1, cnDef.getMinOccurs());
assertTrue("No cn create", cnDef.canAdd());
assertTrue("No cn update", cnDef.canModify());
assertTrue("No cn read", cnDef.canRead());
ResourceAttributeDefinition<?> memberOfDef = accountDef.findAttributeDefinition("isMemberOf");
assertNotNull("No definition for isMemberOf", memberOfDef);
assertEquals(-1, memberOfDef.getMaxOccurs());
assertEquals(0, memberOfDef.getMinOccurs());
assertFalse("isMemberOf create", memberOfDef.canAdd());
assertFalse("isMemberOf update", memberOfDef.canModify());
assertTrue("No isMemberOf read", memberOfDef.canRead());
assertEquals("Wrong isMemberOf matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, memberOfDef.getMatchingRuleQName());
ResourceAttributeDefinition<?> secretaryDef = accountDef.findAttributeDefinition("secretary");
assertNotNull("No definition for secretary", secretaryDef);
assertEquals(-1, secretaryDef.getMaxOccurs());
assertEquals(0, secretaryDef.getMinOccurs());
assertTrue("No secretary create", secretaryDef.canAdd());
assertTrue("No secretary update", secretaryDef.canModify());
assertTrue("No secretary read", secretaryDef.canRead());
assertEquals("Wrong secretary matching rule", PrismConstants.XML_MATCHING_RULE_NAME, secretaryDef.getMatchingRuleQName());
ResourceAttributeDefinition<?> dsDef = accountDef.findAttributeDefinition("ds-pwp-account-disabled");
assertNotNull("No definition for cn", dsDef);
assertEquals(1, dsDef.getMaxOccurs());
assertEquals(0, dsDef.getMinOccurs());
assertTrue("No ds-pwp-account-disabled create", dsDef.canAdd());
assertTrue("No ds-pwp-account-disabled update", dsDef.canModify());
assertTrue("No ds-pwp-account-disabled read", dsDef.canRead());
// TODO: MID-2358
// assertTrue("ds-pwp-account-disabled is NOT operational", dsDef.isOperational());
assertTrue("ds-pwp-account-disabled is NOT ignored", dsDef.isIgnored());
assertNull("The _PASSSWORD_ attribute sneaked into schema", accountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
ResourceObjectClassDefinition posixAccountObjectClassDef = refinedSchema.findObjectClassDefinition(RESOURCE_OPENDJ_POSIX_ACCOUNT_OBJECTCLASS);
assertNotNull("posixAccount definition is missing", posixAccountObjectClassDef);
assertNotNull("Null identifiers in posixAccount", posixAccountObjectClassDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in posixAccount", posixAccountObjectClassDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in posixAccount", posixAccountObjectClassDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in posixAccount", posixAccountObjectClassDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in posixAccount", posixAccountObjectClassDef.getNamingAttribute());
assertFalse("No nativeObjectClass in posixAccount", StringUtils.isEmpty(posixAccountObjectClassDef.getObjectClassDefinition().getNativeObjectClass()));
assertTrue("posixAccount is not auxiliary", posixAccountObjectClassDef.getObjectClassDefinition().isAuxiliary());
ResourceAttributeDefinition<?> posixIdPrimaryDef = posixAccountObjectClassDef.findAttributeDefinitionRequired(getPrimaryIdentifierQName());
assertEquals(1, posixIdPrimaryDef.getMaxOccurs());
assertEquals(0, posixIdPrimaryDef.getMinOccurs());
assertFalse("UID has create", posixIdPrimaryDef.canAdd());
assertFalse("UID has update", posixIdPrimaryDef.canModify());
assertTrue("No UID read", posixIdPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", removeRefinedParts(accountDef.getPrimaryIdentifiers()).contains(posixIdPrimaryDef));
assertEquals("Wrong " + OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME + " frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, posixIdPrimaryDef.getFrameworkAttributeName());
ResourceAttributeDefinition<?> posixIdSecondaryDef = posixAccountObjectClassDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, posixIdSecondaryDef.getMaxOccurs());
assertEquals(1, posixIdSecondaryDef.getMinOccurs());
assertTrue("No NAME create", posixIdSecondaryDef.canAdd());
assertTrue("No NAME update", posixIdSecondaryDef.canModify());
assertTrue("No NAME read", posixIdSecondaryDef.canRead());
assertTrue("NAME definition not in secondary identifiers", removeRefinedParts(accountDef.getSecondaryIdentifiers()).contains(posixIdSecondaryDef));
assertEquals("Wrong " + OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME + " frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, posixIdSecondaryDef.getFrameworkAttributeName());
assertShadows(1);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class DummyResourceContoller method assertDummyResourceSchemaSanity.
public void assertDummyResourceSchemaSanity(ResourceSchema resourceSchema, ResourceType resourceType, boolean checkDisplayOrder) throws SchemaException {
IntegrationTestTools.assertIcfResourceSchemaSanity(resourceSchema, resourceType);
// ACCOUNT
ResourceObjectDefinition accountDef = resourceSchema.findDefinitionForObjectClass(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_NAME);
assertNotNull("No ACCOUNT kind definition", accountDef);
ResourceAttributeDefinition fullnameDef = accountDef.findAttributeDefinition("fullname");
assertNotNull("No definition for fullname", fullnameDef);
assertEquals(1, fullnameDef.getMaxOccurs());
assertEquals(1, fullnameDef.getMinOccurs());
assertTrue("No fullname create", fullnameDef.canAdd());
assertTrue("No fullname update", fullnameDef.canModify());
assertTrue("No fullname read", fullnameDef.canRead());
if (checkDisplayOrder) {
// TODO: fix, see MID-2642
assertTrue("Wrong displayOrder for attribute fullName: " + fullnameDef.getDisplayOrder(), fullnameDef.getDisplayOrder() == 200 || fullnameDef.getDisplayOrder() == 250 || fullnameDef.getDisplayOrder() == 270);
}
// GROUP
ResourceObjectDefinition groupObjectClass = resourceSchema.findDefinitionForObjectClass(SchemaTestConstants.GROUP_OBJECT_CLASS_NAME);
assertNotNull("No group objectClass", groupObjectClass);
ResourceAttributeDefinition membersDef = groupObjectClass.findAttributeDefinition(DUMMY_GROUP_MEMBERS_ATTRIBUTE_NAME);
assertNotNull("No definition for members", membersDef);
assertEquals("Wrong maxOccurs", -1, membersDef.getMaxOccurs());
assertEquals("Wrong minOccurs", 0, membersDef.getMinOccurs());
assertTrue("No members create", membersDef.canAdd());
assertTrue("No members update", membersDef.canModify());
assertTrue("No members read", membersDef.canRead());
assertEquals("Unexpected number of schema definitions in " + getName() + " dummy resource", dummyResource.getNumberOfObjectclasses(), resourceSchema.getDefinitions().size());
for (Definition def : resourceSchema.getDefinitions()) {
if (def instanceof ResourceObjectTypeDefinition) {
AssertJUnit.fail("Refined definition sneaked into resource schema of " + getName() + " dummy resource: " + def);
}
}
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class ConstructionDetailsPanelChainedModel method initLayout.
private void initLayout() {
CompoundPropertyModel constrModel = new CompoundPropertyModel(getModel()) {
@Override
public Object getObject() {
Object o = super.getObject();
return o;
}
@Override
public void setObject(Object o) {
super.setObject(o);
}
};
Form<ConstructionType> form = new Form<ConstructionType>(ID_FORM, constrModel);
form.setOutputMarkupId(true);
DropDownChoice kindChoice = new DropDownChoice<>("kind", Model.ofList(Arrays.asList(ShadowKindType.values())));
kindChoice.setOutputMarkupId(true);
kindChoice.add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {
@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
// ajaxRequestTarget.add(form);
}
});
// kindChoice.add(new AjaxEventBehavior("blur") {
// @Override
// protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
// ajaxRequestTarget.add(form);
// }
// });
form.add(kindChoice);
DropDownChoice intentDropdown = new DropDownChoice<>("intent", new IModel<List<String>>() {
@Override
public List<String> getObject() {
List<String> availableIntentValues = new ArrayList<>();
try {
if (resourceModel.getObject() == null) {
return availableIntentValues;
}
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
if (refinedSchema != null) {
ConstructionType m = (ConstructionType) constrModel.getObject();
ShadowKindType kind = m.getKind();
List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
for (ResourceObjectTypeDefinition def : definitions) {
if (def.getIntent() != null) {
availableIntentValues.add(def.getIntent());
}
}
}
} catch (SchemaException ex) {
LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage());
}
return availableIntentValues;
}
@Override
public void setObject(List<String> o) {
//
}
@Override
public void detach() {
}
});
intentDropdown.setOutputMarkupId(true);
form.add(intentDropdown);
add(form);
// DropDownChoice kindDropDown = new DropDownChoice<ShadowKindType>(ID_KIND_FIELD, kindModel, Model.ofList(Arrays.asList(ShadowKindType.values()))){
// @Override
// protected void onSelectionChanged(ShadowKindType newSelection) {
// if (newSelection == null){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind(null);
// return;
// }
// if (newSelection instanceof ShadowKindType){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind((ShadowKindType) newSelection);
// }
// }
// };
// kindDropDown.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
//
// kindDropDown.setOutputMarkupId(true);
// add(kindDropDown);
//
// TextField intentDropDown = new TextField(ID_INTENT_FIELD, intentChoicesModel);
// DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD,
// PropertyModel.of(getModel(), ConstructionType.F_INTENT.getLocalPart()), intentChoicesModel);
// intentDropDown.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// intentDropDown.setOutputMarkupId(true);
// add(intentDropDown);
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition in project midpoint by Evolveum.
the class ConstructionDetailsPanelChainedModel method initModels.
private void initModels() {
resourceModel = new LoadableDetachableModel<PrismObject<ResourceType>>() {
@Override
protected PrismObject<ResourceType> load() {
ObjectReferenceType resourceRef = getModelObject().getResourceRef();
Task loadResourceTask = getPageBase().createSimpleTask(OPERATION_LOAD_RESOURCE);
OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(resourceRef, getPageBase(), loadResourceTask, result);
result.computeStatusIfUnknown();
if (!result.isAcceptable()) {
LOGGER.error("Cannot find resource referenced from construction. {}", result.getMessage());
result.recordPartialError("Could not find resource referenced from construction.");
return null;
}
return resource;
}
};
kindModel = new IModel<ShadowKindType>() {
@Override
public ShadowKindType getObject() {
return getModelObject().getKind();
}
@Override
public void setObject(ShadowKindType shadowKindType) {
getModelObject().setKind(shadowKindType);
}
@Override
public void detach() {
}
};
intentChoicesModel = new ChainingModel<String>(kindModel) {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
List<String> availableIntentValues = new ArrayList<>();
try {
if (resourceModel.getObject() == null) {
return availableIntentValues.toString();
}
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
if (refinedSchema != null) {
ShadowKindType kind = ((IModel<ShadowKindType>) super.getChainedModel()).getObject();
List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
for (ResourceObjectTypeDefinition def : definitions) {
if (def.getIntent() != null) {
availableIntentValues.add(def.getIntent());
}
}
}
} catch (SchemaException ex) {
LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage());
}
return availableIntentValues.toString();
}
@Override
public void setObject(String o) {
super.setObject(o);
}
};
}
Aggregations