use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class TestMultiResource method test121JackTryDeleteAccount.
/**
* Try to delete Jack's default dummy account. As other provisioned accounts depends on it the
* operation should fail.
*/
@Test
public void test121JackTryDeleteAccount() throws Exception {
final String TEST_NAME = "test121JackTryDeleteAccount";
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
getDummyResource().resetBreakMode();
// Clean up user
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
String accountJackDummyOid = getLinkRefOid(userJack, RESOURCE_DUMMY_OID);
ObjectDelta<ShadowType> accountDelta = ObjectDelta.createDeleteDelta(ShadowType.class, accountJackDummyOid, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
display("Expected exception", e);
}
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class TestMultiResource method test300AddAndAssignRelative.
@Test
public void test300AddAndAssignRelative() throws Exception {
final String TEST_NAME = "test300AddAndAssignRelative";
TestUtil.displayTestTile(TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// Add default dummy account to jack without assigning it.
// In relative mode this account should shay untouched while we play with assignments and
// unsassignements of other accounts
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
modelService.executeChanges(deltas, null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after default dummy account add", userJack);
assertUserJack(userJack);
assertAccount(userJack, RESOURCE_DUMMY_OID);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_BLUE_OID, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
userJack = getUser(USER_JACK_OID);
display("User after red dummy assignment", userJack);
assertUserJack(userJack);
assertAccount(userJack, RESOURCE_DUMMY_OID);
assertAccount(userJack, RESOURCE_DUMMY_BLUE_OID);
assertLinks(userJack, 2);
String accountOid = getLinkRefOid(userJack, RESOURCE_DUMMY_BLUE_OID);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyBlueType);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyBlueType);
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyAccount(RESOURCE_DUMMY_BLUE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class ReportCreateTaskHandler method saveReportOutputType.
private void saveReportOutputType(String filePath, ReportType reportType, Task task, OperationResult parentResult) throws Exception {
String fileName = FilenameUtils.getBaseName(filePath);
String reportOutputName = fileName + " - " + reportType.getExport().value();
ReportOutputType reportOutputType = new ReportOutputType();
prismContext.adopt(reportOutputType);
reportOutputType.setFilePath(filePath);
reportOutputType.setReportRef(MiscSchemaUtil.createObjectReference(reportType.getOid(), ReportType.COMPLEX_TYPE));
reportOutputType.setName(new PolyStringType(reportOutputName));
reportOutputType.setDescription(reportType.getDescription() + " - " + reportType.getExport().value());
reportOutputType.setExportType(reportType.getExport());
ObjectDelta<ReportOutputType> objectDelta = null;
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
OperationResult subResult = null;
objectDelta = ObjectDelta.createAddDelta((PrismObject<ReportOutputType>) reportOutputType.asPrismObject());
deltas.add(objectDelta);
subResult = parentResult.createSubresult(ReportCreateTaskHandler.class.getName() + "createRepourtOutput");
modelService.executeChanges(deltas, null, task, subResult);
String outputOid = objectDelta.getOid();
LOGGER.debug("Created report output with OID {}", outputOid);
PrismProperty<String> outputOidProperty = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(ReportConstants.REPORT_OUTPUT_OID_PROPERTY_NAME).instantiate();
outputOidProperty.setRealValue(outputOid);
task.setExtensionPropertyImmediate(outputOidProperty, subResult);
subResult.computeStatus();
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class ReportWebService method createObjectListType.
private ObjectListType createObjectListType(Collection resultList) {
if (resultList == null) {
return new ObjectListType();
}
ObjectListType results = new ObjectListType();
int skipped = 0;
for (Object object : resultList) {
if (object instanceof PrismObject) {
results.getObject().add(((PrismObject<ObjectType>) object).asObjectable());
} else if (object instanceof ObjectType) {
results.getObject().add((ObjectType) object);
} else {
skipped++;
}
}
if (skipped > 0) {
LOGGER.warn("{} non-PrismObject data objects not returned, as these are not supported by ReportWebService yet", skipped);
}
return results;
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method searchRoleByName.
protected RoleType searchRoleByName(String roleName) throws SAXException, IOException, FaultMessage, JAXBException {
// WARNING: in a real case make sure that the role name is properly escaped before putting it in XML
SearchFilterType filter = ModelClientUtil.parseSearchFilterType("<equal xmlns='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3' >" + "<path>c:name</path>" + "<value>" + roleName + "</value>" + "</equal>");
QueryType query = new QueryType();
query.setFilter(filter);
SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
modelPort.searchObjects(ModelClientUtil.getTypeQName(RoleType.class), query, options, objectListHolder, resultHolder);
ObjectListType objectList = objectListHolder.value;
List<ObjectType> objects = objectList.getObject();
if (objects.isEmpty()) {
return null;
}
if (objects.size() == 1) {
return (RoleType) objects.get(0);
}
throw new IllegalStateException("Expected to find a single role with name '" + roleName + "' but found " + objects.size() + " users instead");
}
Aggregations