use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.
the class DummyConnectorLegacyUpdate method addAttributeValues.
/**
* {@inheritDoc}
*/
@Override
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.isUidBoundToName()) {
account = resource.getAccountByUsername(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(account, options);
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
if (account.getPassword() != null) {
throw new InvalidAttributeValueException("Attempt to add value for password while password is already set");
}
changePassword(account, attr);
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
DummyGroup group;
if (configuration.isUidBoundToName()) {
group = resource.getGroupByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(group, options);
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("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<>(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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
DummyPrivilege priv;
if (configuration.isUidBoundToName()) {
priv = resource.getPrivilegeByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(priv, options);
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
DummyOrg org;
if (configuration.isUidBoundToName()) {
org = resource.getOrgByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(org, options);
for (Attribute attr : valuesToAdd) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("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 InvalidAttributeValueException(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);
} catch (InterruptedException e) {
LOG.info("addAttributeValues::exception " + e);
throw new OperationTimeoutException(e);
}
return uid;
}
use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.
the class DummyConnectorLegacyUpdate method removeAttributeValues.
/**
* {@inheritDoc}
*/
@Override
public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToRemove, OperationOptions options) {
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
DummyAccount account;
if (configuration.isUidBoundToName()) {
account = resource.getAccountByUsername(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(account, options);
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new UnsupportedOperationException("Removing password value is not supported");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to remove value from enable attribute");
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.deleteAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.removeAttributeValues(name, attr.getValue());
LOG.ok("Removed 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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
DummyGroup group;
if (configuration.isUidBoundToName()) {
group = resource.getGroupByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(group, options);
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to remove value from 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<>(values.size());
for (Object val : values) {
newValues.add(StringUtils.upperCase((String) val));
}
values = newValues;
}
try {
group.removeAttributeValues(name, values);
LOG.ok("Removed 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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
DummyPrivilege priv;
if (configuration.isUidBoundToName()) {
priv = resource.getPrivilegeByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(priv, options);
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to remove value from enable attribute");
} else {
String name = attr.getName();
try {
priv.removeAttributeValues(name, attr.getValue());
LOG.ok("Removed 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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
DummyOrg org;
if (configuration.isUidBoundToName()) {
org = resource.getOrgByName(uid.getUidValue());
} else if (configuration.isUidSeparateFromName()) {
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");
}
applyModifyMetadata(org, options);
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new InvalidAttributeValueException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new InvalidAttributeValueException("Attempt to remove value from enable org");
} else {
String name = attr.getName();
try {
org.removeAttributeValues(name, attr.getValue());
LOG.ok("Removed 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 InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
LOG.info("removeAttributeValues::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
LOG.info("removeAttributeValues::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
LOG.info("removeAttributeValues::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
LOG.info("removeAttributeValues::exception " + e);
throw new AlreadyExistsException(e);
} catch (InterruptedException e) {
LOG.info("removeAttributeValues::exception " + e);
throw new OperationTimeoutException(e);
}
return uid;
}
use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test106GetModifiedAccountWill.
/**
* Make a native modification to an account and read it again. Make sure that
* fresh data are returned - even though caching may be in effect.
* MID-3481
*/
@Test
public void test106GetModifiedAccountWill() throws Exception {
given();
Task task = getTestTask();
OperationResult result = createOperationResult();
rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
accountWill.setEnabled(false);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
when();
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
then();
assertSuccess(result);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword", "LOVE");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
assertEquals("Unexpected number of attributes", 7, attributes.size());
PrismObject<ShadowType> shadowRepo = getShadowRepo(ACCOUNT_WILL_OID);
checkRepoAccountShadowWillBasic(shadowRepo, startTs, endTs, null);
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
assertRepoShadowCredentials(shadowRepo, ACCOUNT_WILL_PASSWORD);
checkUniqueness(shadow);
assertCachingMetadata(shadow, false, startTs, endTs);
assertSteadyResource();
}
use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.
the class TestDummyCaching method test107CSkipCachingForIncompleteAttributes.
/**
* Incomplete attributes should not be cached.
*/
@Test
public void test107CSkipCachingForIncompleteAttributes() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, null);
accountWill.getAttributeDefinition(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME).setReturnedAsIncomplete(true);
accountWill.setEnabled(true);
try {
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
when();
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
// THEN
then();
assertSuccess(result);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);
Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
assertEquals("Unexpected number of attributes", 7, attributes.size());
PrismObject<ShadowType> shadowRepo = getShadowRepo(ACCOUNT_WILL_OID);
checkRepoAccountShadowWillBasic(shadowRepo, null, startTs, null);
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
assertRepoShadowCachedAttributeValue(shadowRepo, DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.ENABLED);
checkUniqueness(shadow);
assertCachingMetadata(shadow, false, null, startTs);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
assertSteadyResource();
} finally {
// cleanup the state to allow other tests to pass
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Interceptor");
accountWill.getAttributeDefinition(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME).setReturnedAsIncomplete(false);
}
}
use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.
the class TestDummyCaching method test910CacheMultivaluedAttribute.
/**
* Checks whether multivalued attributes are correctly cached, especially when deleting values.
* See MID-7162.
*/
@Test
public void test910CacheMultivaluedAttribute() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
DummyAccount will = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
updateAndCheckMultivaluedAttribute(will, false, "initial values", Arrays.asList("sword", "love"), task, result);
updateAndCheckMultivaluedAttribute(will, false, "replacing by w1-w3", Arrays.asList("w1", "w2", "w3"), task, result);
updateAndCheckMultivaluedAttribute(will, false, "adding w4", Arrays.asList("w1", "w2", "w3", "w4"), task, result);
updateAndCheckMultivaluedAttribute(will, false, "removing w1", Arrays.asList("w2", "w3", "w4"), task, result);
updateAndCheckMultivaluedAttribute(will, false, "removing all", Collections.emptyList(), task, result);
updateAndCheckMultivaluedAttribute(will, true, "adding w1-w3", Arrays.asList("w1", "w2", "w3"), task, result);
updateAndCheckMultivaluedAttribute(will, true, "adding w4", Arrays.asList("w1", "w2", "w3", "w4"), task, result);
updateAndCheckMultivaluedAttribute(will, true, "removing w1", Arrays.asList("w2", "w3", "w4"), task, result);
updateAndCheckMultivaluedAttribute(will, true, "removing all", Collections.emptyList(), task, result);
}
Aggregations