use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class TestDummy method test260AddAccountLeChuck.
/**
* LeChuck has both group and priv entitlement. Let's add him together with these entitlements.
*/
@Test
public void test260AddAccountLeChuck() throws Exception {
final String TEST_NAME = "test260AddAccountLeChuck";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
PrismObject<ShadowType> accountBefore = prismContext.parseObject(ACCOUNT_LECHUCK_FILE);
accountBefore.checkConsistence();
display("Adding shadow", accountBefore);
// WHEN
String addedObjectOid = provisioningService.addObject(accountBefore, null, null, task, result);
// THEN
result.computeStatus();
display("add object result", result);
TestUtil.assertSuccess("addObject has failed (result)", result);
assertEquals(ACCOUNT_LECHUCK_OID, addedObjectOid);
accountBefore.checkConsistence();
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, addedObjectOid, null, task, result);
leChuckIcfUid = getIcfUid(shadow);
// Check if the account was created in the dummy resource and that it has the entitlements
DummyAccount dummyAccount = getDummyAccountAssert(ACCOUNT_LECHUCK_NAME, leChuckIcfUid);
assertNotNull("No dummy account", dummyAccount);
assertEquals("Fullname is wrong", "LeChuck", dummyAccount.getAttributeValue(DummyAccount.ATTR_FULLNAME_NAME));
assertTrue("The account is not enabled", dummyAccount.isEnabled());
assertEquals("Wrong password", "und3ad", dummyAccount.getPassword());
Set<String> accountProvileges = dummyAccount.getAttributeValues(DummyAccount.ATTR_PRIVILEGES_NAME, String.class);
PrismAsserts.assertSets("account privileges", accountProvileges, PRIVILEGE_PILLAGE_NAME);
// Make sure that privilege object is still there
DummyPrivilege priv = getDummyPrivilegeAssert(PRIVILEGE_PILLAGE_NAME, pillageIcfUid);
assertNotNull("Privilege object is gone!", priv);
DummyGroup group = getDummyGroupAssert(GROUP_PIRATES_NAME, piratesIcfUid);
assertMember(group, transformNameFromResource(ACCOUNT_LECHUCK_NAME));
PrismObject<ShadowType> repoAccount = repositoryService.getObject(ShadowType.class, ACCOUNT_LECHUCK_OID, null, result);
assertShadowName(repoAccount, ACCOUNT_LECHUCK_NAME);
assertEquals("Wrong kind (repo)", ShadowKindType.ACCOUNT, repoAccount.asObjectable().getKind());
assertAttribute(repoAccount, SchemaConstants.ICFS_NAME, ACCOUNT_LECHUCK_NAME);
if (isIcfNameUidSame()) {
assertAttribute(repoAccount, SchemaConstants.ICFS_UID, ACCOUNT_LECHUCK_NAME);
} else {
assertAttribute(repoAccount, SchemaConstants.ICFS_UID, dummyAccount.getId());
}
syncServiceMock.assertNotifySuccessOnly();
PrismObject<ShadowType> provisioningAccount = provisioningService.getObject(ShadowType.class, ACCOUNT_LECHUCK_OID, null, task, result);
display("account from provisioning", provisioningAccount);
assertShadowName(provisioningAccount, ACCOUNT_LECHUCK_NAME);
assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, provisioningAccount.asObjectable().getKind());
assertAttribute(provisioningAccount, SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_LECHUCK_NAME));
if (isIcfNameUidSame()) {
assertAttribute(provisioningAccount, SchemaConstants.ICFS_UID, transformNameFromResource(ACCOUNT_LECHUCK_NAME));
} else {
assertAttribute(provisioningAccount, SchemaConstants.ICFS_UID, dummyAccount.getId());
}
assertEntitlementGroup(provisioningAccount, GROUP_PIRATES_OID);
assertEntitlementPriv(provisioningAccount, PRIVILEGE_PILLAGE_OID);
assertNull("The _PASSSWORD_ attribute sneaked into shadow", ShadowUtil.getAttributeValues(provisioningAccount, new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
checkConsistency(provisioningAccount);
assertSteadyResource();
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class TestDummy method test220EntitleAccountWillPirates.
@Test
public void test220EntitleAccountWillPirates() throws Exception {
final String TEST_NAME = "test220EntitleAccountWillPirates";
TestUtil.displayTestTile(TEST_NAME);
Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
rememberDummyResourceGroupMembersReadCount(null);
syncServiceMock.reset();
ObjectDelta<ShadowType> delta = IntegrationTestTools.createEntitleDelta(ACCOUNT_WILL_OID, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ENTITLEMENT_GROUP_NAME), GROUP_PIRATES_OID, prismContext);
display("ObjectDelta", delta);
delta.checkConsistence();
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.modifyObject(ShadowType.class, delta.getOid(), delta.getModifications(), new OperationProvisioningScriptsType(), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("modifyObject result", result);
TestUtil.assertSuccess(result);
delta.checkConsistence();
if (isAvoidDuplicateValues()) {
assertDummyResourceGroupMembersReadCountIncrement(null, 1);
} else {
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
}
DummyGroup group = getDummyGroupAssert(GROUP_PIRATES_NAME, piratesIcfUid);
assertMember(group, transformNameToResource(ACCOUNT_WILL_USERNAME));
syncServiceMock.assertNotifySuccessOnly();
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
assertSteadyResource();
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class TestDummy method test230DetitleAccountWillPirates.
@Test
public void test230DetitleAccountWillPirates() throws Exception {
final String TEST_NAME = "test230DetitleAccountWillPirates";
TestUtil.displayTestTile(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
rememberDummyResourceGroupMembersReadCount(null);
syncServiceMock.reset();
ObjectDelta<ShadowType> delta = IntegrationTestTools.createDetitleDelta(ACCOUNT_WILL_OID, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ENTITLEMENT_GROUP_NAME), GROUP_PIRATES_OID, prismContext);
display("ObjectDelta", delta);
delta.checkConsistence();
// WHEN
provisioningService.modifyObject(ShadowType.class, delta.getOid(), delta.getModifications(), new OperationProvisioningScriptsType(), null, task, result);
// THEN
result.computeStatus();
display("modifyObject result", result);
TestUtil.assertSuccess(result);
delta.checkConsistence();
if (isAvoidDuplicateValues()) {
assertDummyResourceGroupMembersReadCountIncrement(null, 1);
} else {
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
}
DummyGroup group = getDummyGroupAssert(GROUP_PIRATES_NAME, piratesIcfUid);
assertNoMember(group, getWillRepoIcfName());
// Make sure that account is still there and it has the privilege
DummyAccount dummyAccount = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
assertNotNull("Account will is gone!", dummyAccount);
Set<String> accountProvileges = dummyAccount.getAttributeValues(DummyAccount.ATTR_PRIVILEGES_NAME, String.class);
PrismAsserts.assertSets("Wrong account privileges", accountProvileges, PRIVILEGE_PILLAGE_NAME, PRIVILEGE_BARGAIN_NAME, PRIVILEGE_NONSENSE_NAME);
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
// Make sure that privilege object is still there
DummyPrivilege priv = getDummyPrivilegeAssert(PRIVILEGE_PILLAGE_NAME, pillageIcfUid);
assertNotNull("Privilege object is gone!", priv);
DummyPrivilege priv2 = getDummyPrivilegeAssert(PRIVILEGE_BARGAIN_NAME, bargainIcfUid);
assertNotNull("Privilege object (bargain) is gone!", priv2);
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
syncServiceMock.assertNotifySuccessOnly();
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
display("Shadow after", shadow);
assertEntitlementPriv(shadow, PRIVILEGE_PILLAGE_OID);
assertEntitlementPriv(shadow, PRIVILEGE_BARGAIN_OID);
assertSteadyResource();
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class TestDummy method test224GetPillagingPirateWill.
/**
* Reads the will accounts, checks that both entitlements are there.
*/
@Test
public void test224GetPillagingPirateWill() throws Exception {
final String TEST_NAME = "test224GetPillagingPirateWill";
TestUtil.displayTestTile(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
rememberDummyResourceGroupMembersReadCount(null);
syncServiceMock.reset();
// WHEN
PrismObject<ShadowType> account = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
// THEN
result.computeStatus();
display("Account", account);
display(result);
TestUtil.assertSuccess(result);
assertEntitlementGroup(account, GROUP_PIRATES_OID);
assertEntitlementPriv(account, PRIVILEGE_PILLAGE_OID);
assertEntitlementPriv(account, PRIVILEGE_BARGAIN_OID);
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
// Just make sure nothing has changed
DummyAccount dummyAccount = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
assertNotNull("Account will is gone!", dummyAccount);
Set<String> accountProvileges = dummyAccount.getAttributeValues(DummyAccount.ATTR_PRIVILEGES_NAME, String.class);
PrismAsserts.assertSets("Wrong account privileges", accountProvileges, PRIVILEGE_PILLAGE_NAME, PRIVILEGE_BARGAIN_NAME);
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
// Make sure that privilege object is still there
DummyPrivilege priv = getDummyPrivilegeAssert(PRIVILEGE_PILLAGE_NAME, pillageIcfUid);
assertNotNull("Privilege object is gone!", priv);
DummyPrivilege priv2 = getDummyPrivilegeAssert(PRIVILEGE_BARGAIN_NAME, bargainIcfUid);
assertNotNull("Privilege object (bargain) is gone!", priv2);
DummyGroup group = getDummyGroupAssert(GROUP_PIRATES_NAME, piratesIcfUid);
assertMember(group, transformNameToResource(ACCOUNT_WILL_USERNAME));
assertDummyResourceGroupMembersReadCountIncrement(null, 0);
assertSteadyResource();
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class DummyConnector method addAttributeValues.
/**
* {@inheritDoc}
*/
public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToAdd, OperationOptions options) {
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
DummyAccount account;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
account = resource.getAccountByUsername(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
account = resource.getAccountById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (account == null) {
throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
if (account.getPassword() != null) {
throw new IllegalArgumentException("Attempt to add value for password while password is already set");
}
changePassword(account, attr);
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to add value for enable attribute");
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.addAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.addAttributeValues(name, attr.getValue());
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), account, account.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
DummyGroup group;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
group = resource.getGroupByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
group = resource.getGroupById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (group == null) {
throw new UnknownUidException("Group with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to add value for enable attribute");
} else {
String name = attr.getName();
List<Object> values = attr.getValue();
if (attr.is(DummyGroup.ATTR_MEMBERS_NAME) && values != null && configuration.getUpCaseName()) {
List<Object> newValues = new ArrayList<Object>(values.size());
for (Object val : values) {
newValues.add(StringUtils.upperCase((String) val));
}
values = newValues;
}
try {
group.addAttributeValues(name, values);
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), group, group.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
DummyPrivilege priv;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
priv = resource.getPrivilegeByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
priv = resource.getPrivilegeById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (priv == null) {
throw new UnknownUidException("Privilege with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to add value for enable attribute");
} else {
String name = attr.getName();
try {
priv.addAttributeValues(name, attr.getValue());
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), priv, priv.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
DummyOrg org;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
org = resource.getOrgByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
org = resource.getOrgById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (org == null) {
throw new UnknownUidException("Org with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to add value for enable org");
} else {
String name = attr.getName();
try {
org.addAttributeValues(name, attr.getValue());
log.ok("Added attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), org, org.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
log.info("addAttributeValues::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("addAttributeValues::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("addAttributeValues::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("addAttributeValues::exception " + e);
throw new AlreadyExistsException(e);
}
return uid;
}
Aggregations