Search in sources :

Example 11 with Host

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host 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 12 with Host

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.

the class ConnectorFactoryConnIdImpl method convertToConnectorType.

/**
	 * Converts ICF ConnectorInfo into a midPoint XML connector representation.
	 * 
	 * TODO: schema transformation
	 * 
	 * @param hostType
	 *            host that this connector runs on or null for local connectors
	 */
private ConnectorType convertToConnectorType(ConnectorInfo cinfo, ConnectorHostType hostType) throws SchemaException {
    ConnectorType connectorType = new ConnectorType();
    ConnectorKey key = cinfo.getConnectorKey();
    UcfUtil.addConnectorNames(connectorType, "ConnId", key.getBundleName(), key.getConnectorName(), key.getBundleVersion(), hostType);
    String stringID = keyToNamespaceSuffix(key);
    connectorType.setFramework(SchemaConstants.ICF_FRAMEWORK_URI);
    connectorType.setConnectorType(key.getConnectorName());
    connectorType.setNamespace(ICF_CONFIGURATION_NAMESPACE_PREFIX + stringID);
    connectorType.setConnectorVersion(key.getBundleVersion());
    connectorType.setConnectorBundle(key.getBundleName());
    if (hostType != null) {
        if (hostType.getOid() != null) {
            // bind using connectorHostRef and OID
            ObjectReferenceType ref = new ObjectReferenceType();
            ref.setOid(hostType.getOid());
            ref.setType(ObjectTypes.CONNECTOR_HOST.getTypeQName());
            connectorType.setConnectorHostRef(ref);
        } else {
            // Embed the object
            connectorType.setConnectorHost(hostType);
        }
    }
    PrismSchema connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
    LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size());
    UcfUtil.setConnectorSchema(connectorType, connectorSchema);
    return connectorType;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ConnectorKey(org.identityconnectors.framework.api.ConnectorKey) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 13 with Host

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.

the class ConnectorFactoryConnIdImpl method listRemoteConnectors.

private Set<ConnectorType> listRemoteConnectors(ConnectorHostType host) {
    ConnectorInfoManager remoteConnectorInfoManager = getRemoteConnectorInfoManager(host);
    Set<ConnectorType> connectorTypes = new HashSet<ConnectorType>();
    List<ConnectorInfo> connectorInfos = remoteConnectorInfoManager.getConnectorInfos();
    for (ConnectorInfo connectorInfo : connectorInfos) {
        try {
            ConnectorType connectorType = convertToConnectorType(connectorInfo, host);
            connectorTypes.add(connectorType);
        } catch (SchemaException e) {
            LOGGER.error("Schema error while initializing ConnId connector {}: {}", getConnctorDesc(connectorInfo), e.getMessage(), e);
        }
    }
    return connectorTypes;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ConnectorInfo(org.identityconnectors.framework.api.ConnectorInfo) ConnectorInfoManager(org.identityconnectors.framework.api.ConnectorInfoManager) HashSet(java.util.HashSet)

Example 14 with Host

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.

the class AbstractEDirTest method test200AssignAccountBarbossa.

@Test
public void test200AssignAccountBarbossa() throws Exception {
    final String TEST_NAME = "test200AssignAccountBarbossa";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    long tsStart = System.currentTimeMillis();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assignAccount(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    long tsEnd = System.currentTimeMillis();
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", null);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    PrismObject<ShadowType> shadow = getShadowModel(shadowOid);
    display("Shadow (model)", shadow);
    accountBarbossaOid = shadow.getOid();
    Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
    String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
    assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);
    assertEquals("Wrong ICFS UID", MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid);
    assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_PASSWORD);
    assertPasswordAllowChange(shadow, null);
    ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimestamp"));
    assertNotNull("No createTimestamp in " + shadow, createTimestampAttribute);
    Long createTimestamp = createTimestampAttribute.getRealValue();
    // LDAP server may be on a different host. Allow for some clock offset.
    TestUtil.assertBetween("Wrong createTimestamp in " + shadow, roundTsDown(tsStart) - 1000, roundTsUp(tsEnd) + 1000, createTimestamp);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 15 with Host

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.

the class AbstractAdLdapTest method test200AssignAccountBarbossa.

@Test
public void test200AssignAccountBarbossa() throws Exception {
    final String TEST_NAME = "test200AssignAccountBarbossa";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    long tsStart = System.currentTimeMillis();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assignAccount(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    long tsEnd = System.currentTimeMillis();
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", null);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    PrismObject<ShadowType> shadow = getShadowModel(shadowOid);
    display("Shadow (model)", shadow);
    accountBarbossaOid = shadow.getOid();
    Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
    String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
    assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);
    assertEquals("Wrong ICFS UID", AdUtils.formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())), accountBarbossaIcfUid);
    assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
    assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
    ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimeStamp"));
    assertNotNull("No createTimestamp in " + shadow, createTimestampAttribute);
    Long createTimestamp = createTimestampAttribute.getRealValue();
    // LDAP server may be on a different host. Allow for some clock offset.
    TestUtil.assertBetween("Wrong createTimestamp in " + shadow, roundTsDown(tsStart) - 120000, roundTsUp(tsEnd) + 120000, createTimestamp);
    assertLdapConnectorInstances(2);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 Test (org.testng.annotations.Test)11 Task (com.evolveum.midpoint.task.api.Task)8 ScriptCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)7 ConnectorHostType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType)6 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)6 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)5 CapabilityCollectionType (com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)5 QName (javax.xml.namespace.QName)5 Entry (org.apache.directory.api.ldap.model.entry.Entry)5 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)3 CredentialsCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType)3 TestConnectionCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.TestConnectionCapabilityType)3