use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.
the class AbstractLdapConnTest method test200AssignAccountToBarbossa.
// TODO: scoped search
// TODO: count shadows
@Test
public void test200AssignAccountToBarbossa() throws Exception {
final String TEST_NAME = "test200AssignAccountToBarbossa";
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();
assertLdapConnectorInstances(1, 2);
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);
accountBarbossaEntryId = (String) identifiers.iterator().next().getRealValue();
assertNotNull("No identifier in " + shadow, accountBarbossaEntryId);
assertEquals("Wrong ICFS UID", getAttributeAsString(entry, getPrimaryIdentifierAttributeName()), accountBarbossaEntryId);
assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_PASSWORD);
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);
assertLdapConnectorInstances(1, 2);
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.
the class ConnectorManager method discoverConnectors.
/**
* Lists local connectors and makes sure that appropriate ConnectorType
* objects for them exist in repository.
*
* It will never delete any repository object, even if the corresponding
* connector cannot be found. The connector may temporarily removed, may be
* present on a different node, manual upgrade may be needed etc.
*
* @return set of discovered connectors (new connectors found)
* @throws CommunicationException
*/
// @SuppressWarnings("unchecked")
public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult) throws CommunicationException {
OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName() + ".discoverConnectors");
result.addParam("host", hostType);
// it
if (hostType != null && hostType.getOid() == null) {
throw new SystemException("Discovery attempt with non-persistent " + hostType);
}
Set<ConnectorType> discoveredConnectors = new HashSet<ConnectorType>();
for (ConnectorFactory connectorFactory : getConnectorFactories()) {
Set<ConnectorType> foundConnectors;
try {
foundConnectors = connectorFactory.listConnectors(hostType, result);
} catch (CommunicationException ex) {
result.recordFatalError("Discovery failed: " + ex.getMessage(), ex);
throw new CommunicationException("Discovery failed: " + ex.getMessage(), ex);
}
if (foundConnectors == null) {
LOGGER.trace("Connector factory {} discovered null connectors, skipping", connectorFactory);
continue;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got {} connectors from {}: {}", new Object[] { foundConnectors.size(), hostType, foundConnectors });
}
for (ConnectorType foundConnector : foundConnectors) {
LOGGER.trace("Found connector {}", foundConnector);
boolean inRepo = true;
try {
inRepo = isInRepo(foundConnector, result);
} catch (SchemaException e1) {
LOGGER.error("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
result.recordPartialError("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
// But continue otherwise ...
}
if (!inRepo) {
LOGGER.trace("Connector {} not in the repository, \"dicovering\" it", foundConnector);
// itself
if (hostType != null && foundConnector.getConnectorHost() == null) {
foundConnector.setConnectorHost(hostType);
}
if (foundConnector.getSchema() == null) {
LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
}
// Sanitize framework-supplied OID
if (StringUtils.isNotEmpty(foundConnector.getOid())) {
LOGGER.warn("Provisioning framework " + foundConnector.getFramework() + " supplied OID for connector " + ObjectTypeUtil.toShortString(foundConnector));
foundConnector.setOid(null);
}
// Store the connector object
String oid;
try {
prismContext.adopt(foundConnector);
oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
// We don't specify the OID, therefore this should never
// happen
// Convert to runtime exception
LOGGER.error("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
result.recordFatalError("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
} catch (SchemaException e) {
// If there is a schema error it must be a bug. Convert to
// runtime exception
LOGGER.error("Got SchemaException while not expecting it: " + e.getMessage(), e);
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
}
foundConnector.setOid(oid);
discoveredConnectors.add(foundConnector);
LOGGER.info("Discovered new connector " + foundConnector);
}
}
}
result.recordSuccess();
return discoveredConnectors;
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.
the class TestOpenDj method test005Capabilities.
@Test
public void test005Capabilities() throws Exception {
final String TEST_NAME = "test005Capabilities";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
ResourceType resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result).asObjectable();
// THEN
display("Resource from provisioninig", resource);
display("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNotNull("credentials capability not found", capCred);
PasswordCapabilityType capPassword = capCred.getPassword();
assertNotNull("password capability not present", capPassword);
assertPasswordCapability(capPassword);
// Connector cannot do activation, this should be null
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
assertNull("Found activation capability while not expecting it", capAct);
ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
assertNotNull("No script capability", capScript);
List<Host> scriptHosts = capScript.getHost();
assertEquals("Wrong number of script hosts", 1, scriptHosts.size());
Host scriptHost = scriptHosts.get(0);
assertEquals("Wrong script host type", ProvisioningScriptHostType.CONNECTOR, scriptHost.getType());
// assertEquals("Wrong script host language", ....., scriptHost.getLanguage());
CreateCapabilityType capCreate = CapabilityUtil.getCapability(nativeCapabilitiesList, CreateCapabilityType.class);
assertNotNull("No create capability", capCreate);
ReadCapabilityType capRead = CapabilityUtil.getCapability(nativeCapabilitiesList, ReadCapabilityType.class);
assertNotNull("No read capability", capRead);
UpdateCapabilityType capUpdate = CapabilityUtil.getCapability(nativeCapabilitiesList, UpdateCapabilityType.class);
assertNotNull("No update capability", capUpdate);
DeleteCapabilityType capDelete = CapabilityUtil.getCapability(nativeCapabilitiesList, DeleteCapabilityType.class);
assertNotNull("No delete capability", capDelete);
List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
for (Object capability : effectiveCapabilities) {
System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
}
capCred = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
assertNotNull("credentials effective capability not found", capCred);
assertNotNull("password effective capability not found", capCred.getPassword());
// Although connector does not support activation, the resource specifies a way how to simulate it.
// Therefore the following should succeed
capAct = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
assertNotNull("activation capability not found", capAct);
PagedSearchCapabilityType capPage = ResourceTypeUtil.getEffectiveCapability(resource, PagedSearchCapabilityType.class);
assertNotNull("paged search capability not present", capPage);
assertShadows(1);
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.
the class TestDummySchemaless method test107Capabilities.
@Test
public void test107Capabilities() throws Exception {
final String TEST_NAME = "test107Capabilities";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ResourceType resourceType = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, null, result).asObjectable();
// THEN
TestUtil.displayThen(TEST_NAME);
assertSuccess(result);
// Check native capabilities
CapabilityCollectionType nativeCapabilities = resourceType.getCapabilities().getNative();
System.out.println("Native capabilities: " + PrismTestUtil.serializeAnyDataWrapped(nativeCapabilities));
System.out.println("resource: " + resourceType.asPrismObject().debugDump());
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
TestConnectionCapabilityType capTest = CapabilityUtil.getCapability(nativeCapabilitiesList, TestConnectionCapabilityType.class);
assertNotNull("native test capability not present", capTest);
ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
assertNotNull("native script capability not present", capScript);
assertNotNull("No host in native script capability", capScript.getHost());
assertFalse("No host in native script capability", capScript.getHost().isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNull("Unexpected native credentials capability", capCred);
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
assertNull("Unexpected native activation capability", capAct);
// Check effective capabilites
capCred = ResourceTypeUtil.getEffectiveCapability(resourceType, CredentialsCapabilityType.class);
assertNotNull("password capability not found", capCred.getPassword());
// Although connector does not support activation, the resource
// specifies a way how to simulate it.
// Therefore the following should succeed
capAct = ResourceTypeUtil.getEffectiveCapability(resourceType, ActivationCapabilityType.class);
assertNotNull("activation capability not found", capCred.getPassword());
List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resourceType);
for (Object capability : effectiveCapabilities) {
display("Capability " + CapabilityUtil.getCapabilityDisplayName(capability), capability);
}
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method getConnectorInfo.
/**
* Get contect informations
*
* @param connectorType
* @return
* @throws ObjectNotFoundException
*/
private ConnectorInfo getConnectorInfo(ConnectorType connectorType) throws ObjectNotFoundException {
if (!SchemaConstants.ICF_FRAMEWORK_URI.equals(connectorType.getFramework())) {
throw new ObjectNotFoundException("Requested connector for framework " + connectorType.getFramework() + " cannot be found in framework " + SchemaConstants.ICF_FRAMEWORK_URI);
}
ConnectorKey key = getConnectorKey(connectorType);
if (connectorType.getConnectorHost() == null && connectorType.getConnectorHostRef() == null) {
// Local connector
return getLocalConnectorInfoManager().findConnectorInfo(key);
}
ConnectorHostType host = connectorType.getConnectorHost();
if (host == null) {
throw new ObjectNotFoundException("Attempt to use remote connector without ConnectorHostType resolved (there is only ConnectorHostRef");
}
return getRemoteConnectorInfoManager(host).findConnectorInfo(key);
}
Aggregations