use of com.evolveum.icf.dummy.resource.DummyPrivilege in project midpoint by Evolveum.
the class TestUniversity method test100AddComeniusUniversity.
@Test
public void test100AddComeniusUniversity() throws Exception {
final String TEST_NAME = "test100AddComeniusUniversity";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestUniversity.class.getName() + "." + TEST_NAME);
DummyPrivilege comenius = new DummyPrivilege("UK");
// WHEN
dummyResourceHr.addPrivilege(comenius);
waitForTaskNextRunAssertSuccess(TASK_LIVE_SYNC_DUMMY_HR_OID, true);
// THEN
PrismObject<OrgType> org = getAndAssertFunctionalOrg("UK");
assertNotNull("Comenius University was not found", org);
display("Org", org);
dumpOrgTree();
assertHasOrg(org, ORG_TOP_OID);
assertAssignedOrg(org, ORG_TOP_OID);
assertSubOrgs(org, 0);
assertSubOrgs(ORG_TOP_OID, 1);
}
use of com.evolveum.icf.dummy.resource.DummyPrivilege in project midpoint by Evolveum.
the class TestUniversity method test120MoveComputingCentre.
@Test
public void test120MoveComputingCentre() throws Exception {
final String TEST_NAME = "test120MoveComputingCentre";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestUniversity.class.getName() + "." + TEST_NAME);
DummyPrivilege srcVc = dummyResourceHr.getPrivilegeByName("VC");
// WHEN
srcVc.replaceAttributeValue(DUMMY_PRIVILEGE_ATTRIBUTE_HR_ORGPATH, "UK:PRIF");
waitForTaskNextRunAssertSuccess(TASK_LIVE_SYNC_DUMMY_HR_OID, true, 999999999);
// THEN
dumpOrgTree();
PrismObject<OrgType> uk = getAndAssertFunctionalOrg("UK");
assertNotNull("UK was not found", uk);
display("Org UK", uk);
assertHasOrg(uk, ORG_TOP_OID);
assertAssignedOrg(uk, ORG_TOP_OID);
assertSubOrgs(uk, 2);
assertSubOrgs(ORG_TOP_OID, 1);
assertGroupMembers(uk, "cn=DL-FMFI,ou=FMFI,ou=UK,dc=example,dc=com", "cn=DL-PRIF,ou=PRIF,ou=UK,dc=example,dc=com");
PrismObject<OrgType> fmfi = getAndAssertFunctionalOrg("FMFI");
assertNotNull("FMFI was not found", fmfi);
display("Org FMFI", fmfi);
assertHasOrg(fmfi, uk.getOid());
assertAssignedOrg(fmfi, uk.getOid());
assertSubOrgs(fmfi, 0);
assertNoGroupMembers(fmfi);
PrismObject<OrgType> prif = getAndAssertFunctionalOrg("PRIF");
assertNotNull("PRIF was not found", prif);
display("Org PRIF", prif);
assertHasOrg(prif, uk.getOid());
assertAssignedOrg(prif, uk.getOid());
assertSubOrgs(prif, 1);
assertGroupMembers(prif, "cn=DL-VC,ou=VC,ou=PRIF,ou=UK,dc=example,dc=com");
PrismObject<OrgType> vc = getAndAssertFunctionalOrg("VC");
assertNotNull("VC was not found", vc);
display("Org VC", vc);
assertHasOrg(vc, prif.getOid());
assertAssignedOrg(vc, prif.getOid());
assertSubOrgs(vc, 0);
assertNoGroupMembers(vc);
}
use of com.evolveum.icf.dummy.resource.DummyPrivilege 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;
}
use of com.evolveum.icf.dummy.resource.DummyPrivilege in project midpoint by Evolveum.
the class DummyConnector method update.
/**
* {@inheritDoc}
*/
public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttributes, OperationOptions options) {
log.info("update::begin");
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
final DummyAccount account;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
account = resource.getAccountByUsername(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
account = resource.getAccountById(uid.getUidValue(), false);
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (account == null) {
throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
}
// we do this before setting attribute values, in case when description itself would be changed
resource.changeDescriptionIfNeeded(account);
for (Attribute attr : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameAccount(account.getId(), account.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
} catch (SchemaViolationException e) {
throw new org.identityconnectors.framework.common.exceptions.ConnectorException("Schema exception: " + e.getMessage(), e);
}
// We need to change the returned uid here (only if the mode is not set to UUID)
if (!(configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID))) {
uid = new Uid(newName);
}
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
changePassword(account, attr);
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
account.setEnabled(getBoolean(attr));
} else if (attr.is(OperationalAttributes.ENABLE_DATE_NAME)) {
account.setValidFrom(getDate(attr));
} else if (attr.is(OperationalAttributes.DISABLE_DATE_NAME)) {
account.setValidTo(getDate(attr));
} else if (attr.is(OperationalAttributes.LOCK_OUT_NAME)) {
account.setLockout(getBooleanNotNull(attr));
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.replaceAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new InvalidAttributeValueException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
final DummyGroup group;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
group = resource.getGroupByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
group = resource.getGroupById(uid.getUidValue(), false);
} 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 : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameGroup(group.getId(), group.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
group.setEnabled(getBooleanNotNull(attr));
} 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.replaceAttributeValues(name, values);
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
final DummyPrivilege priv;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
priv = resource.getPrivilegeByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
priv = resource.getPrivilegeById(uid.getUidValue(), false);
} 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 : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renamePrivilege(priv.getId(), priv.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to change enable on privilege");
} else {
String name = attr.getName();
try {
priv.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
final DummyOrg org;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
org = resource.getOrgByName(uid.getUidValue(), false);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
org = resource.getOrgById(uid.getUidValue(), false);
} 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 : replaceAttributes) {
if (attr.is(Name.NAME)) {
String newName = (String) attr.getValue().get(0);
try {
resource.renameOrg(org.getId(), org.getName(), newName);
} catch (ObjectDoesNotExistException e) {
throw new org.identityconnectors.framework.common.exceptions.UnknownUidException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) {
throw new org.identityconnectors.framework.common.exceptions.AlreadyExistsException(e.getMessage(), e);
}
// We need to change the returned uid here
uid = new Uid(newName);
} else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
throw new IllegalArgumentException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to change enable on org");
} else {
String name = attr.getName();
try {
org.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
log.info("update::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("update::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("update::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("update::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("update::end");
return uid;
}
use of com.evolveum.icf.dummy.resource.DummyPrivilege in project midpoint by Evolveum.
the class DummyConnector method executeQuery.
/**
* {@inheritDoc}
*/
public void executeQuery(ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options) {
log.info("executeQuery({0},{1},{2},{3})", objectClass, query, handler, options);
validate(objectClass);
validate(query);
notNull(handler, "Results handled object can't be null.");
Collection<String> attributesToGet = getAttrsToGet(options);
log.ok("attributesToGet={0}", attributesToGet);
if (configuration.getRequiredBaseContextOrgName() != null && shouldRequireBaseContext(objectClass, query, options)) {
if (options == null || options.getContainer() == null) {
throw new ConnectorException("No container option while base context is required");
}
QualifiedUid container = options.getContainer();
if (!configuration.getRequiredBaseContextOrgName().equals(container.getUid().getUidValue())) {
throw new ConnectorException("Base context of '" + configuration.getRequiredBaseContextOrgName() + "' is required, but got '" + container.getUid().getUidValue() + "'");
}
}
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
Collection<DummyAccount> accounts = resource.listAccounts();
for (DummyAccount account : accounts) {
ConnectorObject co = convertToConnectorObject(account, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, account, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
Collection<DummyGroup> groups = resource.listGroups();
for (DummyGroup group : groups) {
ConnectorObject co = convertToConnectorObject(group, attributesToGet);
if (matches(query, co)) {
if (attributesToGetHasAttribute(attributesToGet, DummyGroup.ATTR_MEMBERS_NAME)) {
resource.recordGroupMembersReadCount();
}
co = filterOutAttributesToGet(co, group, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
Collection<DummyPrivilege> privs = resource.listPrivileges();
for (DummyPrivilege priv : privs) {
ConnectorObject co = convertToConnectorObject(priv, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, priv, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
Collection<DummyOrg> orgs = resource.listOrgs();
for (DummyOrg org : orgs) {
ConnectorObject co = convertToConnectorObject(org, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, org, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
log.info("executeQuery::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("executeQuery::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("executeQuery::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("executeQuery::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("executeQuery::end");
}
Aggregations