Search in sources :

Example 1 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg in project midpoint by Evolveum.

the class DummyConnector method convertToOrg.

private DummyOrg convertToOrg(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, ConflictException {
    String icfName = Utils.getMandatoryStringAttribute(createAttributes, Name.NAME);
    if (configuration.getUpCaseName()) {
        icfName = StringUtils.upperCase(icfName);
    }
    final DummyOrg newOrg = new DummyOrg(icfName);
    for (Attribute attr : createAttributes) {
        if (attr.is(Uid.NAME)) {
            throw new IllegalArgumentException("UID explicitly specified in the org attributes");
        } else if (attr.is(Name.NAME)) {
        // Skip, already processed
        } else if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
            throw new IllegalArgumentException("Password specified for a org");
        } else if (attr.is(OperationalAttributeInfos.ENABLE.getName())) {
            throw new IllegalArgumentException("Unsupported ENABLE attribute in org");
        } else {
            String name = attr.getName();
            try {
                newOrg.replaceAttributeValues(name, attr.getValue());
            } catch (SchemaViolationException e) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
        }
    }
    return newOrg;
}
Also used : GuardedString(org.identityconnectors.common.security.GuardedString) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg)

Example 2 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg in project midpoint by Evolveum.

the class DummyConnector method removeAttributeValues.

/**
     * {@inheritDoc}
     */
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.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 : 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 IllegalArgumentException("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 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 : valuesToRemove) {
                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 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<Object>(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 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 : valuesToRemove) {
                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 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 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 : valuesToRemove) {
                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 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 IllegalArgumentException(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);
    }
    return uid;
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) DummyObject(com.evolveum.icf.dummy.resource.DummyObject) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException)

Example 3 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg in project midpoint by Evolveum.

the class DummyResourceContoller method addOrgTop.

public DummyOrg addOrgTop() throws ConnectException, FileNotFoundException, ObjectAlreadyExistsException, SchemaViolationException, ConflictException {
    DummyOrg org = new DummyOrg(ORG_TOP_NAME);
    dummyResource.addOrg(org);
    return org;
}
Also used : DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg)

Example 4 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg 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;
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) DummyObject(com.evolveum.icf.dummy.resource.DummyObject) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException)

Example 5 with DummyOrg

use of com.evolveum.icf.dummy.resource.DummyOrg 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;
}
Also used : ConflictException(com.evolveum.icf.dummy.resource.ConflictException) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectDoesNotExistException(com.evolveum.icf.dummy.resource.ObjectDoesNotExistException) List(java.util.List) ArrayList(java.util.ArrayList) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) DummyObject(com.evolveum.icf.dummy.resource.DummyObject) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException)

Aggregations

DummyOrg (com.evolveum.icf.dummy.resource.DummyOrg)7 SchemaViolationException (com.evolveum.icf.dummy.resource.SchemaViolationException)6 GuardedString (org.identityconnectors.common.security.GuardedString)6 ConflictException (com.evolveum.icf.dummy.resource.ConflictException)5 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)5 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)5 DummyPrivilege (com.evolveum.icf.dummy.resource.DummyPrivilege)5 ObjectAlreadyExistsException (com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException)5 FileNotFoundException (java.io.FileNotFoundException)5 ConnectException (java.net.ConnectException)5 AlreadyExistsException (org.identityconnectors.framework.common.exceptions.AlreadyExistsException)5 ConnectionFailedException (org.identityconnectors.framework.common.exceptions.ConnectionFailedException)5 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)5 ConnectorIOException (org.identityconnectors.framework.common.exceptions.ConnectorIOException)5 InvalidAttributeValueException (org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException)5 DummyObject (com.evolveum.icf.dummy.resource.DummyObject)4 ArrayList (java.util.ArrayList)3 UnknownUidException (org.identityconnectors.framework.common.exceptions.UnknownUidException)3 ObjectDoesNotExistException (com.evolveum.icf.dummy.resource.ObjectDoesNotExistException)1 Collection (java.util.Collection)1