Search in sources :

Example 11 with ConnectorFacade

use of org.identityconnectors.framework.api.ConnectorFacade in project CzechIdMng by bcvsolutions.

the class ConnIdIcConnectorService method authenticateObject.

@Override
public IcUidAttribute authenticateObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, String username, GuardedString password) {
    Assert.notNull(connectorInstance, "Connector instance is required.");
    Assert.notNull(connectorInstance.getConnectorKey(), "Connector key is required.");
    Assert.notNull(connectorConfiguration, "Configuration is required.");
    Assert.notNull(username, "Username is required.");
    LOG.debug("Authenticate object - ConnId (username= {} {})", username, connectorInstance.getConnectorKey().toString());
    ConnectorFacade conn = facadeFactory.getConnectorFacade(connectorInstance, connectorConfiguration);
    ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
    if (objectClassConnId == null) {
        objectClassConnId = ObjectClass.ACCOUNT;
    }
    try {
        IcUidAttribute uid = ConnIdIcConvertUtil.convertConnIdUid(conn.authenticate(objectClassConnId, username, new org.identityconnectors.common.security.GuardedString(password.asString().toCharArray()), new OperationOptions(connectorConfiguration.getSystemOperationOptions())));
        LOG.debug("Authenticated object - ConnId (Uid= {})", uid);
        return uid;
    } catch (InvalidCredentialException ex) {
        throw new ResultCodeException(IcResultCode.AUTH_FAILED, ex);
    }
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) InvalidCredentialException(org.identityconnectors.framework.common.exceptions.InvalidCredentialException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 12 with ConnectorFacade

use of org.identityconnectors.framework.api.ConnectorFacade in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method configure.

@Override
public synchronized void configure(@NotNull PrismContainerValue<?> configurationOriginal, List<QName> generateObjectClasses, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(ConnectorInstance.OPERATION_CONFIGURE);
    LOGGER.trace("Configuring connector {}, provided configuration:\n{}", connectorType, configurationOriginal.debugDumpLazily(1));
    try {
        this.generateObjectClasses = generateObjectClasses;
        // Get default configuration for the connector. This is important,
        // as it contains types of connector configuration properties.
        // Make sure that the proper configuration schema is applied. This
        // will cause that all the "raw" elements are parsed
        PrismContainerValue<?> configurationCloned = configurationOriginal.clone();
        configurationCloned.applyDefinition(getConfigurationContainerDefinition());
        ConnIdConfigurationTransformer configTransformer = new ConnIdConfigurationTransformer(connectorType, connectorInfo, protector);
        // Transform XML configuration from the resource to the ConnId connector configuration
        try {
            apiConfig = configTransformer.transformConnectorConfiguration(configurationCloned);
        } catch (SchemaException e) {
            result.recordFatalError(e.getMessage(), e);
            throw e;
        }
        logTransformedConfiguration();
        apiConfig.setInstanceName(getInstanceName());
        ConnectorFacade oldConnIdConnectorFacade = connIdConnectorFacade;
        // Create new connector instance using the transformed configuration
        connIdConnectorFacade = ConnectorFacadeFactory.getInstance().newInstance(apiConfig);
        if (oldConnIdConnectorFacade != null) {
            // Make sure old connector instance is disposed. We do not want to waste resources.
            // In case that old and new facade are the same, this will cause all existing
            // ConnId connector instances to dispose (i.e. connector pool is emptied).
            // But this is exactly what we want on reconfigure. We want the connections to
            // be closed and re-opened.
            LOGGER.debug("Disposing old ConnId ConnectorFacade for instance: {} (connector reconfiguration)", instanceName);
            oldConnIdConnectorFacade.dispose();
        }
        result.recordSuccess();
        PrismProperty<Boolean> legacySchemaConfigProperty = configurationCloned.findProperty(new ItemName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_XML_ELEMENT_NAME));
        if (legacySchemaConfigProperty != null) {
            legacySchema = legacySchemaConfigProperty.getRealValue();
        }
        LOGGER.trace("Legacy schema (config): {}", legacySchema);
    } catch (Throwable ex) {
        Throwable midpointEx = processConnIdException(ex, this, result);
        result.computeStatus("Removing attribute values failed");
        // exception
        if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) ItemName(com.evolveum.midpoint.prism.path.ItemName) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

ConnectorFacade (org.identityconnectors.framework.api.ConnectorFacade)12 IcConnectorFacade (eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade)8 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)7 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)7 OperationOptions (org.identityconnectors.framework.common.objects.OperationOptions)7 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)3 APIConfiguration (org.identityconnectors.framework.api.APIConfiguration)3 ConnectorInfo (org.identityconnectors.framework.api.ConnectorInfo)3 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)2 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)2 HashSet (java.util.HashSet)2 Attribute (org.identityconnectors.framework.common.objects.Attribute)2 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)2 Uid (org.identityconnectors.framework.common.objects.Uid)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)1