Search in sources :

Example 96 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ConnectorFactoryConnIdImpl method listConnectors.

/**
	 * Returns a list XML representation of the ICF connectors.
	 * 
	 * @throws CommunicationException
	 */
@Override
public Set<ConnectorType> listConnectors(ConnectorHostType host, OperationResult parentRestul) throws CommunicationException {
    OperationResult result = parentRestul.createSubresult(ConnectorFactory.OPERATION_LIST_CONNECTOR);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ConnectorFactoryConnIdImpl.class);
    result.addParam("host", host);
    try {
        if (host == null) {
            Set<ConnectorType> connectors = listLocalConnectors();
            result.recordSuccess();
            return connectors;
        } else {
            // This is necessary as list of the remote connectors is cached locally.
            // So if any remote connector is added then it will not be discovered unless we
            // clear the cache. This may look like inefficiency but in fact the listConnectors() method is
            // used only when discovering new connectors. Normal connector operation is using connector objects
            // stored in repository.
            connectorInfoManagerFactory.clearRemoteCache();
            Set<ConnectorType> connectors = listRemoteConnectors(host);
            result.recordSuccess();
            return connectors;
        }
    } catch (Throwable icfException) {
        Throwable ex = processIcfException(icfException, "list connectors", result);
        result.recordFatalError(ex.getMessage(), ex);
        if (ex instanceof CommunicationException) {
            throw (CommunicationException) ex;
        } else if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        } else if (ex instanceof Error) {
            throw (Error) ex;
        } else {
            throw new SystemException("Unexpected ICF exception: " + ex.getMessage(), ex);
        }
    }
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 97 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ConnectorFactoryConnIdImpl method scanDirectory.

/**
	 * Scan directory for bundles only on first lval we do the scan
	 * 
	 * @param path
	 * @return
	 */
private Set<URL> scanDirectory(String path) {
    // Prepare return object
    Set<URL> bundle = new HashSet<URL>();
    // COnvert path to object File
    File dir = new File(path);
    // Test if this path is single jar or need to do deep examination
    if (isThisJarFileBundle(dir)) {
        try {
            if (isThisBundleCompatible(dir.toURI().toURL())) {
                bundle.add(dir.toURI().toURL());
            } else {
                LOGGER.warn("Skip loading budle {} due error occured", dir.toURI().toURL());
            }
        } catch (MalformedURLException e) {
            LOGGER.error("This never happend we hope.", e);
            throw new SystemException(e);
        }
        return bundle;
    }
    // Test if it is a directory
    if (!dir.isDirectory()) {
        LOGGER.error("Provided Icf connector path {} is not a directory.", dir.getAbsolutePath());
    }
    // List directory items
    File[] dirEntries = dir.listFiles();
    if (null == dirEntries) {
        LOGGER.warn("No bundles found in directory {}", dir.getAbsolutePath());
        return bundle;
    }
    // test all entires for bundle
    for (int i = 0; i < dirEntries.length; i++) {
        if (isThisJarFileBundle(dirEntries[i])) {
            try {
                if (isThisBundleCompatible(dirEntries[i].toURI().toURL())) {
                    bundle.add(dirEntries[i].toURI().toURL());
                } else {
                    LOGGER.warn("Skip loading budle {} due error occured", dirEntries[i].toURI().toURL());
                }
            } catch (MalformedURLException e) {
                LOGGER.error("This never happend we hope.", e);
                throw new SystemException(e);
            }
        }
    }
    return bundle;
}
Also used : MalformedURLException(java.net.MalformedURLException) SystemException(com.evolveum.midpoint.util.exception.SystemException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet)

Example 98 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ConnectorFactoryConnIdImpl method getRemoteConnectorInfoManager.

/**
	 * Returns ICF connector info manager that manages local connectors. The
	 * manager will be created if it does not exist yet.
	 * 
	 * @return ICF connector info manager that manages local connectors
	 */
private ConnectorInfoManager getRemoteConnectorInfoManager(ConnectorHostType hostType) {
    String hostname = hostType.getHostname();
    int port = Integer.parseInt(hostType.getPort());
    GuardedString key;
    try {
        key = new GuardedString(protector.decryptString(hostType.getSharedSecret()).toCharArray());
    } catch (EncryptionException e) {
        throw new SystemException("Shared secret decryption error: " + e.getMessage(), e);
    }
    Integer timeout = hostType.getTimeout();
    if (timeout == null) {
        timeout = 0;
    }
    boolean useSSL = false;
    if (hostType.isProtectConnection() != null) {
        useSSL = hostType.isProtectConnection();
    }
    List<TrustManager> trustManagers = protector.getTrustManagers();
    LOGGER.trace("Creating RemoteFrameworkConnectionInfo: hostname={}, port={}, key={}, useSSL={}, trustManagers={}, timeout={}", new Object[] { hostname, port, key, useSSL, trustManagers, timeout });
    RemoteFrameworkConnectionInfo remoteFramewrorkInfo = new RemoteFrameworkConnectionInfo(hostname, port, key, useSSL, trustManagers, timeout);
    return connectorInfoManagerFactory.getRemoteManager(remoteFramewrorkInfo);
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) GuardedString(org.identityconnectors.common.security.GuardedString) GuardedString(org.identityconnectors.common.security.GuardedString) RemoteFrameworkConnectionInfo(org.identityconnectors.framework.api.RemoteFrameworkConnectionInfo) TrustManager(javax.net.ssl.TrustManager)

Example 99 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TestOpenDj method test701ConfiguredCapabilityNoRead.

@Test
public void test701ConfiguredCapabilityNoRead() throws Exception {
    final String TEST_NAME = "test701ConfiguredCapabilityNoRead";
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    addResourceFromFile(new File(TEST_DIR, "resource-opendj-no-read.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result);
    try {
        provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
        AssertJUnit.fail("Expected unsupported operation exception, but haven't got one.");
    } catch (SystemException ex) {
    // this is expected..				
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 100 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method fetchConnectorObject.

/**
	 * Returns null if nothing is found.
	 */
private ConnectorObject fetchConnectorObject(StateReporter reporter, ObjectClassComplexTypeDefinition objectClassDefinition, ObjectClass icfObjectClass, Uid uid, OperationOptions options, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SecurityViolationException, SchemaException, ConfigurationException {
    // Connector operation cannot create result for itself, so we need to
    // create result for it
    OperationResult icfResult = parentResult.createMinorSubresult(ConnectorFacade.class.getName() + ".getObject");
    icfResult.addParam("objectClass", icfObjectClass.toString());
    icfResult.addParam("uid", uid.getUidValue());
    icfResult.addArbitraryObjectAsParam("options", options);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Fetching connector object ObjectClass={}, UID={}, options={}", new Object[] { icfObjectClass, uid, ConnIdUtil.dumpOptions(options) });
    }
    ConnectorObject co = null;
    try {
        // Invoke the ICF connector
        InternalMonitor.recordConnectorOperation("getObject");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, uid);
        co = connIdConnectorFacade.getObject(icfObjectClass, uid, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, uid);
        icfResult.recordSuccess();
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, ex, uid);
        String desc = this.getHumanReadableName() + " while getting object identified by ICF UID '" + uid.getUidValue() + "'";
        Throwable midpointEx = processIcfException(ex, desc, icfResult);
        icfResult.computeStatus("Add object failed");
        // exception
        if (midpointEx instanceof CommunicationException) {
            icfResult.muteError();
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof SecurityViolationException) {
            throw (SecurityViolationException) midpointEx;
        } else if (midpointEx instanceof ObjectNotFoundException) {
            LOGGER.trace("Got ObjectNotFoundException while looking for resource object ConnId UID: {}", uid);
            return null;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            // This should not happen. But some connectors are very strange.
            throw new SystemException("ERROR: " + midpointEx.getClass().getName() + ": " + midpointEx.getMessage(), midpointEx);
        } else {
            throw new SystemException(midpointEx.getClass().getName() + ": " + midpointEx.getMessage(), midpointEx);
        }
    }
    return co;
}
Also used : CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12