use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class TestUtil method setAttribute.
public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException {
PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES);
ResourceAttributeDefinition attrDef = new ResourceAttributeDefinitionImpl(attrName, typeName, prismContext);
ResourceAttribute attribute = attrDef.instantiate();
attribute.setRealValue(value);
attributesContainer.add(attribute);
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class DefaultGuiProgressListener method updateStatusItemState.
private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
si.setActivityType(progressInformation.getActivityType());
si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
if (progressInformation.getResourceShadowDiscriminator() != null) {
String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
si.setResourceName(resourceName);
}
if (progressInformation.getStateType() == null) {
si.setStatus(null);
} else if (progressInformation.getStateType() == ENTERING) {
si.setStatus(OperationResultStatusType.IN_PROGRESS);
} else {
OperationResult result = progressInformation.getOperationResult();
if (result != null) {
OperationResultStatus status = result.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = result.getComputeStatus();
}
si.setStatus(status.createStatusType());
} else {
si.setStatus(OperationResultStatusType.UNKNOWN);
}
}
// information about modifications on a resource
if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
if (mpc != null) {
// it shouldn't be null!
// operations performed (TODO aggregate them somehow?)
List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
for (ObjectDeltaOperation executedDelta : executedDeltas) {
ObjectDelta delta = executedDelta.getObjectDelta();
if (delta != null) {
OperationResult r = executedDelta.getExecutionResult();
OperationResultStatus status = r.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = r.getComputeStatus();
}
resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
}
}
si.setResourceOperationResultList(resourceOperationResultList);
// object name
PrismObject<ShadowType> object = mpc.getObjectNew();
if (object == null) {
object = mpc.getObjectOld();
}
String name = null;
if (object != null) {
if (object.asObjectable().getName() != null) {
name = PolyString.getOrig(object.asObjectable().getName());
} else {
// determine from attributes
ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
if (nameAttribute != null) {
name = String.valueOf(nameAttribute.getAnyRealValue());
}
}
}
if (name != null) {
si.setResourceObjectName(name);
}
}
}
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method test200AssignAccountBarbossa.
// /**
// * Blocksize is 5, so this gets more than two blocks.
// */
// @Test
// public void test154SeachFirst11Accounts() throws Exception {
// final String TEST_NAME = "test154SeachFirst11Accounts";
// TestUtil.displayTestTile(this, TEST_NAME);
//
// // GIVEN
// Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
// OperationResult result = task.getResult();
//
// ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//
// ObjectPaging paging = ObjectPaging.createEmptyPaging();
// paging.setMaxSize(11);
// query.setPaging(paging);
//
// SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 11, task, result);
//
// assertConnectorOperationIncrement(1);
// assertConnectorSimulatedPagingSearchIncrement(0);
//
// SearchResultMetadata metadata = searchResultList.getMetadata();
// if (metadata != null) {
// assertFalse(metadata.isPartialResults());
// }
//
// assertLdapConnectorInstances(2);
// }
//
// @Test
// public void test162SeachFirst2AccountsOffset0() throws Exception {
// final String TEST_NAME = "test162SeachFirst2AccountsOffset0";
// TestUtil.displayTestTile(this, TEST_NAME);
//
// // GIVEN
// Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
// OperationResult result = task.getResult();
//
// ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//
// ObjectPaging paging = ObjectPaging.createEmptyPaging();
// paging.setOffset(0);
// paging.setMaxSize(2);
// query.setPaging(paging);
//
// SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 2, task, result);
//
// assertConnectorOperationIncrement(1);
// assertConnectorSimulatedPagingSearchIncrement(0);
//
// SearchResultMetadata metadata = searchResultList.getMetadata();
// if (metadata != null) {
// assertFalse(metadata.isPartialResults());
// }
//
// assertLdapConnectorInstances(2);
// }
//
// /**
// * Blocksize is 5, so this is in one block.
// * There is offset, so VLV should be used.
// * No explicit sorting.
// */
// @Test
// public void test172Search2AccountsOffset1() throws Exception {
// final String TEST_NAME = "test172Search2AccountsOffset1";
// TestUtil.displayTestTile(this, TEST_NAME);
//
// // GIVEN
// Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
// OperationResult result = task.getResult();
//
// ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//
// ObjectPaging paging = ObjectPaging.createPaging(1, 2);
// query.setPaging(paging);
//
// SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 2, task, result);
//
// assertConnectorOperationIncrement(1);
// assertConnectorSimulatedPagingSearchIncrement(0);
//
// SearchResultMetadata metadata = searchResultList.getMetadata();
// if (metadata != null) {
// assertFalse(metadata.isPartialResults());
// }
//
// assertLdapConnectorInstances(2);
// }
//
// /**
// * Blocksize is 5, so this gets more than two blocks.
// * There is offset, so VLV should be used.
// * No explicit sorting.
// */
// @Test
// public void test174SeachFirst11AccountsOffset2() throws Exception {
// final String TEST_NAME = "test174SeachFirst11AccountsOffset2";
// TestUtil.displayTestTile(this, TEST_NAME);
//
// // GIVEN
// Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
// OperationResult result = task.getResult();
//
// ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//
// ObjectPaging paging = ObjectPaging.createPaging(2, 11);
// query.setPaging(paging);
//
// allowDuplicateSearchResults = true;
//
// // WHEN
// SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 11, task, result);
//
// // THEN
// allowDuplicateSearchResults = false;
//
// assertConnectorOperationIncrement(1);
// assertConnectorSimulatedPagingSearchIncrement(0);
//
// SearchResultMetadata metadata = searchResultList.getMetadata();
// if (metadata != null) {
// assertFalse(metadata.isPartialResults());
// }
//
// assertLdapConnectorInstances(2);
// }
//
// /**
// * Blocksize is 5, so this is in one block.
// * There is offset, so VLV should be used.
// * Explicit sorting.
// */
// @Test
// public void test182Search2AccountsOffset1SortCn() throws Exception {
// final String TEST_NAME = "test182Search2AccountsOffset1SortCn";
// TestUtil.displayTestTile(this, TEST_NAME);
//
// // GIVEN
// Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
// OperationResult result = task.getResult();
//
// ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//
// ObjectPaging paging = ObjectPaging.createPaging(1, 2);
// paging.setOrdering(getAttributePath(resource, "cn"), OrderDirection.ASCENDING);
// query.setPaging(paging);
//
// SearchResultList<PrismObject<ShadowType>> shadows = doSearch(TEST_NAME, query, 2, task, result);
//
// assertAccountShadow(shadows.get(0), "CN=Adalbert Meduza,OU=evolveum,DC=win,DC=evolveum,DC=com");
// assertAccountShadow(shadows.get(1), "CN=Adalbert Meduza1,OU=evolveum,DC=win,DC=evolveum,DC=com");
//
// assertConnectorOperationIncrement(1);
// assertConnectorSimulatedPagingSearchIncrement(0);
//
// SearchResultMetadata metadata = shadows.getMetadata();
// if (metadata != null) {
// assertFalse(metadata.isPartialResults());
// }
//
// assertLdapConnectorInstances(2);
// }
@Test
public void test200AssignAccountBarbossa() throws Exception {
final String TEST_NAME = "test200AssignAccountBarbossa";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
long tsStart = System.currentTimeMillis();
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignAccount(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
long tsEnd = System.currentTimeMillis();
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "title", null);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
PrismObject<ShadowType> shadow = getShadowModel(shadowOid);
display("Shadow (model)", shadow);
accountBarbossaOid = shadow.getOid();
Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);
assertEquals("Wrong ICFS UID", AdUtils.formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())), accountBarbossaIcfUid);
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimeStamp"));
assertNotNull("No createTimestamp in " + shadow, createTimestampAttribute);
Long createTimestamp = createTimestampAttribute.getRealValue();
// LDAP server may be on a different host. Allow for some clock offset.
TestUtil.assertBetween("Wrong createTimestamp in " + shadow, roundTsDown(tsStart) - 120000, roundTsUp(tsEnd) + 120000, createTimestamp);
// assertLdapConnectorInstances(2);
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.
/**
* Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
*/
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (identifiers == null) {
return null;
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, ctx.getObjectClassDefinition());
PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
if (repoShadow == null) {
return null;
}
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
return null;
}
RefinedObjectClassDefinition ocDef = ctx.getObjectClassDefinition();
Collection primaryIdentifiers = new ArrayList<>();
for (PrismProperty<?> property : attributesContainer.getValue().getProperties()) {
if (ocDef.isPrimaryIdentifier(property.getElementName())) {
RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName());
ResourceAttribute<?> primaryIdentifier = new ResourceAttribute<>(property.getElementName(), attrDef, prismContext);
primaryIdentifier.setRealValue(property.getRealValue());
primaryIdentifiers.add(primaryIdentifier);
}
}
LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, ocDef);
return primaryIdentifiers;
}
use of com.evolveum.midpoint.schema.processor.ResourceAttribute in project midpoint by Evolveum.
the class ProvisioningUtil method normalizeShadow.
public static <T extends ShadowType> void normalizeShadow(T shadow, OperationResult result) throws SchemaException {
if (shadow.getAttemptNumber() != null) {
shadow.setAttemptNumber(null);
}
if (shadow.getFailedOperationType() != null) {
shadow.setFailedOperationType(null);
}
if (shadow.getObjectChange() != null) {
shadow.setObjectChange(null);
}
if (shadow.getResult() != null) {
shadow.setResult(null);
}
if (shadow.getCredentials() != null) {
shadow.setCredentials(null);
}
ResourceAttributeContainer normalizedContainer = ShadowUtil.getAttributesContainer(shadow);
ResourceAttributeContainer oldContainer = normalizedContainer.clone();
normalizedContainer.clear();
Collection<ResourceAttribute<?>> identifiers = oldContainer.getPrimaryIdentifiers();
for (PrismProperty<?> p : identifiers) {
normalizedContainer.getValue().add(p.clone());
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = oldContainer.getSecondaryIdentifiers();
for (PrismProperty<?> p : secondaryIdentifiers) {
normalizedContainer.getValue().add(p.clone());
}
cleanupShadowActivation(shadow);
}
Aggregations