Search in sources :

Example 31 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultIdmProcessedTaskItemDtoServiceTest method testItemTypeReference.

@Test
public void testItemTypeReference() {
    IdmScheduledTaskDto d = helper.createSchedulableTask();
    IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
    IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
    // 
    try {
        item.setScheduledTaskQueueOwner(d.getId());
        service.get(service.saveInternal(item).getId());
        fail("Both log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
    // 
    try {
        item.setScheduledTaskQueueOwner(null);
        item.setLongRunningTask(null);
        service.get(service.saveInternal(item).getId());
        fail("Empty log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 32 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class ConnIdIcConfigurationService method toStandardJavaUrl.

/**
 * Transformation the Url to standard Java Url (for the JBoss VFS problem)
 *
 * We have to create new instance of URL, because we don't want use the URL with
 * 'vfs' protocol. This happens on the WildFly server (where are connectors
 * copied to temp folder -> problem with non exists MANIFEST in the ConnId).
 *
 * @param url
 * @return
 */
private URL toStandardJavaUrl(URL url) {
    if (url == null) {
        return null;
    }
    if (URL_PROTOCOL_VFS.equals(url.getProtocol())) {
        try {
            VirtualFile vf = VFS.getChild(url.toURI());
            URL physicalUrl = VFSUtils.getPhysicalURL(vf);
            // Workaround ... replace contents folder with name of file
            URL resultUrl = new URL(URL_PROTOCOL_FILE, physicalUrl.getHost(), physicalUrl.getFile().replace("/contents/", "/" + vf.getName()));
            return resultUrl;
        } catch (Exception e) {
            throw new CoreException("JBoss VFS URL transformation failed", e);
        }
    }
    return url;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) URL(java.net.URL) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) InvalidCredentialException(org.identityconnectors.framework.common.exceptions.InvalidCredentialException) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException)

Example 33 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class IcInitDataProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    LOG.info("Initialization [{}] module...", IcModuleDescriptor.MODULE_ID);
    // ConnId using logger implementation, what cannot be configured (printing
    // always). We need change the implementation to JDKLogger.
    // Second way how configuring that property, is create property file
    // 'connectors.properties' in the java home (jre/lib), witch will contains same
    // property.
    System.setProperty(PROPERTY_CONNID_LOGGER_IMPLEMENTATION, JDKLogger.class.getName());
    // VŠ: I had to use this hard code. Because logger in Connid is cached and calls before this initialisation.
    try {
        Method spiClassMethod = Arrays.asList(Log.class.getDeclaredMethods()).stream().filter(propertyDescriptor -> {
            return PROPERTY_SET_LOGGER.equals(propertyDescriptor.getName());
        }).findFirst().orElse(null);
        spiClassMethod.setAccessible(true);
        spiClassMethod.invoke(Log.class, new Object[] { null });
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new CoreException(e);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Log(org.identityconnectors.common.logging.Log) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) JDKLogger(org.identityconnectors.common.logging.impl.JDKLogger) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 34 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractReadWriteDtoControllerRestTest method getBaseUrl.

/**
 * Entry point url
 *
 * @return
 */
protected String getBaseUrl() {
    Class<?> clazz = AopUtils.getTargetClass(getController());
    RequestMapping mapping = clazz.getAnnotation(RequestMapping.class);
    if (mapping.value().length > 0) {
        return mapping.value()[0];
    }
    if (mapping.path().length > 0) {
        return mapping.path()[0];
    }
    throw new CoreException("Controller [" + clazz + "] doeasn't have default mapping, cannot be tested by this abstraction.");
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AdUserConnectorType method getServerCertificate.

/**
 * Get server certificates.
 */
private Pair<X509Certificate, Boolean> getServerCertificate(String port, String host) {
    try {
        SSLSocket socket = null;
        try {
            socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, Integer.parseInt(port));
            socket.startHandshake();
            LOG.info("Certificate is already trusted for connection to the AD.");
            SSLSession session = socket.getSession();
            Certificate[] peerCertificates = session.getPeerCertificates();
            if (peerCertificates.length > 0) {
                return new Pair<>((X509Certificate) peerCertificates[0], Boolean.TRUE);
            }
        } catch (SSLException e) {
            LOG.info("Certificate is not trusted for connection to the AD.");
            SSLContext context = SSLContext.getInstance("TLS");
            // Workaround how get server certificates from the AD server if the IdM server doesn't have trusted certificate yet.
            SavingTrustManager tm = new SavingTrustManager();
            context.init(null, new TrustManager[] { tm }, null);
            SSLSocketFactory factory = context.getSocketFactory();
            if (socket != null && !socket.isClosed()) {
                socket.close();
            }
            socket = (SSLSocket) factory.createSocket(host, Integer.parseInt(port));
            socket.setSoTimeout(10000);
            // Start handshake. In the case without check a trusted certificate.
            socket.startHandshake();
            X509Certificate[] chain = tm.chain;
            if (chain.length > 0) {
                return new Pair<>(chain[0], Boolean.FALSE);
            }
        } finally {
            if (socket != null && !socket.isClosed()) {
                socket.close();
            }
        }
    } catch (IOException | NoSuchAlgorithmException | KeyManagementException ex) {
        throw new CoreException(ex.getLocalizedMessage(), ex);
    }
    return null;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLException(javax.net.ssl.SSLException) KeyManagementException(java.security.KeyManagementException) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManager(javax.net.ssl.TrustManager) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) Pair(eu.bcvsolutions.idm.core.api.domain.Pair)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6