use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType in project midpoint by Evolveum.
the class ProvisioningUtil method createAttributesToReturn.
public static AttributesToReturn createAttributesToReturn(ProvisioningContext ctx) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
ResourceType resource = ctx.getResource();
boolean apply = false;
AttributesToReturn attributesToReturn = new AttributesToReturn();
// Attributes
boolean hasMinimal = false;
for (RefinedAttributeDefinition attributeDefinition : objectClassDefinition.getAttributeDefinitions()) {
if (attributeDefinition.getFetchStrategy() == AttributeFetchStrategyType.MINIMAL) {
hasMinimal = true;
break;
}
}
attributesToReturn.setReturnDefaultAttributes(!hasMinimal);
Collection<ResourceAttributeDefinition> explicit = new ArrayList<ResourceAttributeDefinition>();
for (RefinedAttributeDefinition attributeDefinition : objectClassDefinition.getAttributeDefinitions()) {
AttributeFetchStrategyType fetchStrategy = attributeDefinition.getFetchStrategy();
if (fetchStrategy != null && fetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
explicit.add(attributeDefinition);
} else if (hasMinimal && fetchStrategy != AttributeFetchStrategyType.MINIMAL) {
explicit.add(attributeDefinition);
}
}
if (!explicit.isEmpty()) {
attributesToReturn.setAttributesToReturn(explicit);
apply = true;
}
// Password
CredentialsCapabilityType credentialsCapabilityType = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
if (credentialsCapabilityType != null) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_PASSWORD_VALUE, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnPasswordExplicit(true);
apply = true;
} else {
if (!CapabilityUtil.isPasswordReturnedByDefault(credentialsCapabilityType)) {
// There resource is capable of returning password but it does not
// do it by default
AttributeFetchStrategyType passwordFetchStrategy = objectClassDefinition.getPasswordFetchStrategy();
if (passwordFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnPasswordExplicit(true);
apply = true;
}
}
}
}
// Activation
ActivationCapabilityType activationCapabilityType = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
if (activationCapabilityType != null) {
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getStatus())) {
if (!CapabilityUtil.isActivationStatusReturnedByDefault(activationCapabilityType)) {
// not do it by default
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_ADMINISTRATIVE_STATUS);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getValidFrom())) {
if (!CapabilityUtil.isActivationValidFromReturnedByDefault(activationCapabilityType)) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_VALID_FROM, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnValidFromExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_VALID_FROM);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnValidFromExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getValidTo())) {
if (!CapabilityUtil.isActivationValidToReturnedByDefault(activationCapabilityType)) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_VALID_TO, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnValidToExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_VALID_TO);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnValidToExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getLockoutStatus())) {
if (!CapabilityUtil.isActivationLockoutStatusReturnedByDefault(activationCapabilityType)) {
// not do it by default
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType statusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_LOCKOUT_STATUS);
if (statusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnLockoutStatusExplicit(true);
apply = true;
}
}
}
}
}
if (apply) {
return attributesToReturn;
} else {
return null;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test024Capabilities.
@Test
public void test024Capabilities() throws Exception {
final String TEST_NAME = "test024Capabilities";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
// WHEN
PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
ResourceType resourceType = resource.asObjectable();
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
// Check native capabilities
CapabilityCollectionType nativeCapabilities = resourceType.getCapabilities().getNative();
display("Native capabilities", PrismTestUtil.serializeAnyDataWrapped(nativeCapabilities));
display("Resource", resourceType);
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNativeCredentialsCapability(capCred);
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
if (supportsActivation()) {
assertNotNull("native activation capability not present", capAct);
assertNotNull("native activation status capability not present", capAct.getStatus());
} else {
assertNull("native activation capability sneaked in", capAct);
}
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());
// TODO: better look inside
capabilitiesCachingMetadataType = resourceType.getCapabilities().getCachingMetadata();
assertNotNull("No capabilities caching metadata", capabilitiesCachingMetadataType);
assertNotNull("No capabilities caching metadata timestamp", capabilitiesCachingMetadataType.getRetrievalTimestamp());
assertNotNull("No capabilities caching metadata serial number", capabilitiesCachingMetadataType.getSerialNumber());
// 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) {
System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
}
assertSteadyResource();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test030ResourceAndConnectorCaching.
@Test
public void test030ResourceAndConnectorCaching() throws Exception {
TestUtil.displayTestTile("test030ResourceAndConnectorCaching");
// GIVEN
OperationResult result = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching");
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
assertNotNull("No resource schema", resourceSchema);
// WHEN
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
// Check resource schema caching
ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
// Check capabilities caching
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
assertNotNull("No capabilities fetched from provisioning", capabilitiesType);
CachingMetadataType capCachingMetadataType = capabilitiesType.getCachingMetadata();
assertNotNull("No capabilities caching metadata fetched from provisioning", capCachingMetadataType);
CachingMetadataType capCachingMetadataTypeAgain = resourceTypeAgain.getCapabilities().getCachingMetadata();
assertEquals("Capabilities caching metadata serial number has changed", capCachingMetadataType.getSerialNumber(), capCachingMetadataTypeAgain.getSerialNumber());
assertEquals("Capabilities caching metadata timestamp has changed", capCachingMetadataType.getRetrievalTimestamp(), capCachingMetadataTypeAgain.getRetrievalTimestamp());
// Rough test if everything is fine
resource.asObjectable().setFetchResult(null);
resourceAgain.asObjectable().setFetchResult(null);
ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resource, resourceAgain);
display("Dummy resource diff", dummyResourceDiff);
assertTrue("The resource read again is not the same as the original. diff:" + dummyResourceDiff, dummyResourceDiff.isEmpty());
// Now we stick our nose deep inside the provisioning impl. But we need
// to make sure that the
// configured connector is properly cached
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
// Check if the connector still works.
OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching.test");
configuredConnectorInstanceAgain.test(testResult);
testResult.computeStatus();
TestUtil.assertSuccess("Connector test failed", testResult);
// Test connection should also refresh the connector by itself. So check if it has been refreshed
ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest);
assertTrue("Connector instance was not cached", configuredConnectorInstanceAgain == configuredConnectorInstanceAfterTest);
assertSteadyResource();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test031ResourceAndConnectorCachingForceFresh.
@Test
public void test031ResourceAndConnectorCachingForceFresh() throws Exception {
TestUtil.displayTestTile("test031ResourceAndConnectorCachingForceFresh");
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + ".test011ResourceAndConnectorCachingForceFresh");
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
assertNotNull("No resource schema", resourceSchema);
// WHEN
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
// Now we stick our nose deep inside the provisioning impl. But we need
// to make sure that the configured connector is properly refreshed
// forceFresh = true
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, true, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
assertFalse("Connector instance was not refreshed", configuredConnectorInstance == configuredConnectorInstanceAgain);
// Check if the connector still works
OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test011ResourceAndConnectorCachingForceFresh.test");
configuredConnectorInstanceAgain.test(testResult);
testResult.computeStatus();
TestUtil.assertSuccess("Connector test failed", testResult);
assertConnectorInitializationCountIncrement(1);
rememberConnectorInstance(configuredConnectorInstanceAgain);
assertSteadyResource();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test015ListResourcesNoFetch.
/**
* List resources with noFetch option. This is what GUI does. This operation
* should be harmless and should not change resource state.
*/
@Test
public void test015ListResourcesNoFetch() throws Exception {
final String TEST_NAME = "test015ListResourcesNoFetch";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
// WHEN
SearchResultList<PrismObject<ResourceType>> resources = provisioningService.searchObjects(ResourceType.class, null, options, task, result);
// THEN
result.computeStatus();
display("searchObjects result", result);
TestUtil.assertSuccess(result);
assertFalse("No resources found", resources.isEmpty());
for (PrismObject<ResourceType> resource : resources) {
ResourceType resourceType = resource.asObjectable();
display("Found resource " + resourceType, resourceType);
display("XML " + resourceType, PrismTestUtil.serializeObjectToString(resource, PrismContext.LANG_XML));
XmlSchemaType xmlSchemaType = resourceType.getSchema();
if (xmlSchemaType != null) {
Element xsdSchemaElement = ResourceTypeUtil.getResourceXsdSchema(resourceType);
assertNull("Found schema in " + resource, xsdSchemaElement);
}
}
assertConnectorSchemaParseIncrement(1);
assertConnectorCapabilitiesFetchIncrement(0);
assertConnectorInitializationCountIncrement(0);
assertResourceSchemaFetchIncrement(0);
assertResourceSchemaParseCountIncrement(0);
}
Aggregations